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
|
* Return the domain of this site
|
||||||
*
|
*
|
||||||
@ -242,7 +251,6 @@ JS;
|
|||||||
Session::set('SubsiteID', $subsiteID);
|
Session::set('SubsiteID', $subsiteID);
|
||||||
|
|
||||||
// And clear caches
|
// And clear caches
|
||||||
self::$cached_subsite = NULL ;
|
|
||||||
Permission::flush_permission_cache() ;
|
Permission::flush_permission_cache() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,6 +456,31 @@ JS;
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
// CMS ADMINISTRATION HELPERS
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -8,4 +8,13 @@ class SubsiteDomain extends DataObject {
|
|||||||
static $has_one = array(
|
static $has_one = array(
|
||||||
"Subsite" => "Subsite",
|
"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