ENHANCEMENT: Removed unnecessary subsite caching for better static publishing operation. (from r81672)

This commit is contained in:
Tom Rix 2010-03-01 02:53:34 +00:00
parent c17784761a
commit cfb0d238e5
2 changed files with 43 additions and 1 deletions

View File

@ -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

View File

@ -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();
}
}