Skip to content

Commit

Permalink
Merge pull request #9 from quantum-dragons/fix-augment-sql
Browse files Browse the repository at this point in the history
Fix issue where extension owner doesn't respect subsite
  • Loading branch information
adrexia authored Mar 6, 2019
2 parents d09d820 + be2fa50 commit 8b12444
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/SubsiteModelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
}
}
}

0 comments on commit 8b12444

Please sign in to comment.