mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 09:05:55 +00:00
ENHANCEMENT: Removed unnecessary subsite caching for better static publishing operation. (from r81672)
This commit is contained in:
parent
c17784761a
commit
cfb0d238e5
@ -91,6 +91,15 @@ class Subsite extends DataObject implements PermissionProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whenever a Subsite is written, rewrite the hostmap
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterWrite() {
|
||||
Subsite::writeHostMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the domain of this site
|
||||
*
|
||||
@ -242,7 +251,6 @@ JS;
|
||||
Session::set('SubsiteID', $subsiteID);
|
||||
|
||||
// And clear caches
|
||||
self::$cached_subsite = NULL ;
|
||||
Permission::flush_permission_cache() ;
|
||||
}
|
||||
|
||||
@ -447,6 +455,31 @@ JS;
|
||||
LEFT JOIN {$q}Permission{$q} ON {$q}Group{$q}.{$q}ID{$q} = {$q}Permission{$q}.{$q}GroupID{$q}"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a host->domain map to cache/host-map.php
|
||||
*
|
||||
* This is used primarily when using subsites in conjunction with StaticPublisher
|
||||
*
|
||||
* @return void
|
||||
* @author Tom Rix
|
||||
*/
|
||||
static function writeHostMap($file = null) {
|
||||
if (!$file) $file = Director::baseFolder().'/cache/host-map.php';
|
||||
$hostmap = array();
|
||||
|
||||
$subsites = DataObject::get('Subsite');
|
||||
|
||||
if ($subsites) foreach($subsites as $subsite) {
|
||||
$domains = $subsite->Domains();
|
||||
if ($domains) foreach($domains as $domain) {
|
||||
$hostmap[str_replace('www.', '', $domain->Domain)] = $subsite->domain();
|
||||
}
|
||||
}
|
||||
|
||||
$data = '<?php $subsiteHostmap = '.var_export($hostmap, true).' ?>';
|
||||
file_put_contents($file, $data);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CMS ADMINISTRATION HELPERS
|
||||
|
@ -8,4 +8,13 @@ class SubsiteDomain extends DataObject {
|
||||
static $has_one = array(
|
||||
"Subsite" => "Subsite",
|
||||
);
|
||||
|
||||
/**
|
||||
* Whenever a Subsite Domain is written, rewrite the hostmap
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterWrite() {
|
||||
Subsite::writeHostMap();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user