From 9e423fda4db895e198482cfb8d0e450d54e32c38 Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Mon, 1 Mar 2010 21:56:24 +0000 Subject: [PATCH] MINOR force a specific set of subsite IDs to be queried on (from r95849) --- code/SiteTreeSubsites.php | 8 +++++--- code/Subsite.php | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/code/SiteTreeSubsites.php b/code/SiteTreeSubsites.php index 23f2b64..2bc4e4b 100644 --- a/code/SiteTreeSubsites.php +++ b/code/SiteTreeSubsites.php @@ -69,9 +69,11 @@ class SiteTreeSubsites extends SiteTreeDecorator { // If you're querying by ID, ignore the sub-site - this is a bit ugly... if (!$query->where || (!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]))) { - $context = DataObject::context_obj(); - if($context && is_numeric($context->SubsiteID)) $subsiteID = (int) $context->SubsiteID; - else $subsiteID = (int) Subsite::currentSubsiteID(); + if (Subsite::$force_subsite) $subsiteID = Subsite::$force_subsite; + else { + if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID; + else $subsiteID = (int)Subsite::currentSubsiteID(); + } // The foreach is an ugly way of getting the first key :-) foreach($query->from as $tableName => $info) { diff --git a/code/Subsite.php b/code/Subsite.php index ca14934..db79b48 100644 --- a/code/Subsite.php +++ b/code/Subsite.php @@ -12,6 +12,12 @@ class Subsite extends DataObject implements PermissionProvider { * to limit DataObject::get*() calls to a specific subsite. Useful for debugging. */ static $disable_subsite_filter = false; + + /** + * Allows you to force a specific subsite ID, or comma separated list of IDs. + * Only works for reading. An object cannot be written to more than 1 subsite. + */ + static $force_subsite = null; static $write_hostmap = true; static $default_sort = 'Title';