From be2fa50ec9059ef3dee2bde9f8367a703e5f1dc2 Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Thu, 15 Nov 2018 17:06:02 +1300 Subject: [PATCH] Fix issue where extension owner doesn't respect subsite --- src/SubsiteModelExtension.php | 45 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/SubsiteModelExtension.php b/src/SubsiteModelExtension.php index 0e7cd83..212d556 100644 --- a/src/SubsiteModelExtension.php +++ b/src/SubsiteModelExtension.php @@ -42,29 +42,28 @@ public function onBeforeWrite() { * @param DataQuery $dataQuery Container DataQuery for this SQLSelect */ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { + if (Subsite::$disable_subsite_filter) { + return; + } + + // If you're querying by ID, ignore the sub-site + if ($query->filtersOnID()) { + return; + } + $regexp = '/^(.*\.)?("|`)?SubsiteID("|`)?\s?=/'; + foreach ($query->getWhereParameterised($parameters) as $predicate) { + if (preg_match($regexp, $predicate)) { + return; + } + } + + $subsiteID = (int)SubsiteState::singleton()->getSubsiteId(); - // if (Subsite::$disable_subsite_filter) { - // return; - // } - // - // // If you're querying by ID, ignore the sub-site - // if ($query->filtersOnID()) { - // return; - // } - // $regexp = '/^(.*\.)?("|`)?SubsiteID("|`)?\s?=/'; - // foreach ($query->getWhereParameterised($parameters) as $predicate) { - // if (preg_match($regexp, $predicate)) { - // return; - // } - // } - // - // $subsiteID = (int)Subsite::currentSubsiteID(); - // - // $froms=$query->getFrom(); - // $froms=array_keys($froms); - // $tableName = array_shift($froms); - // if ($tableName === $this->owner->ClassName) { - // $query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)"); - // } + $froms=$query->getFrom(); + $froms=array_keys($froms); + $tableName = array_shift($froms); + if ($tableName == $this->owner->baseTable()) { + $query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)"); + } } }