Skip to content

Commit

Permalink
BUG Fix incompatibility with framework 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Aug 25, 2014
1 parent ffe6c34 commit a97b0d3
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 63 deletions.
17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

language: php

php:
- 5.3
php:
- 5.4

env:
- DB=MYSQL CORE_RELEASE=3.1
- DB=PGSQL CORE_RELEASE=master
global:
- CORE_RELEASE=master
matrix:
- DB=MYSQL
- DB=PGSQL

matrix:
include:
- php: 5.3
env: DB=MYSQL
- php: 5.4
env: DB=MYSQL CORE_RELEASE=master
- php: 5.4
env: DB=MYSQL CORE_RELEASE=3.1 BEHAT_TEST=1
env: DB=MYSQL BEHAT_TEST=1

before_script:
- composer self-update
Expand Down
32 changes: 15 additions & 17 deletions code/extensions/FileSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,30 @@ function updateCMSFields(FieldList $fields) {
/**
* Update any requests to limit the results to the current site
*/
function augmentSQL(SQLQuery &$query) {
public function augmentSQL(SQLSelect $query) {
if(Subsite::$disable_subsite_filter) return;

// If you're querying by ID, ignore the sub-site - this is a bit ugly... (but it was WAYYYYYYYYY worse)
//@TODO I don't think excluding if SiteTree_ImageTracking is a good idea however because of the SS 3.0 api and ManyManyList::removeAll() changing the from table after this function is called there isn't much of a choice

$from = $query->getFrom();
$where = $query->getWhere();
if(isset($from['SiteTree_ImageTracking']) || $query->filtersOnID()) return;

if(!isset($from['SiteTree_ImageTracking']) && !($where && preg_match('/\.(\'|"|`|)ID(\'|"|`|)/', $where[0]))) {
$subsiteID = (int) Subsite::currentSubsiteID();
$subsiteID = (int) Subsite::currentSubsiteID();

// The foreach is an ugly way of getting the first key :-)
foreach($query->getFrom() as $tableName => $info) {
$where = "\"$tableName\".\"SubsiteID\" IN (0, $subsiteID)";
$query->addWhere($where);
break;
}

$sect=array_values($query->getSelect());
$isCounting = strpos($sect[0], 'COUNT') !== false;
// The foreach is an ugly way of getting the first key :-)
foreach($query->getFrom() as $tableName => $info) {
$where = "\"$tableName\".\"SubsiteID\" IN (0, $subsiteID)";
$query->addWhere($where);
break;
}

// Ordering when deleting or counting doesn't apply
if(!$query->getDelete() && !$isCounting) {
$query->addOrderBy("\"SubsiteID\"");
}
$sect=array_values($query->getSelect());
$isCounting = strpos($sect[0], 'COUNT') !== false;

// Ordering when deleting or counting doesn't apply
if(!$isCounting) {
$query->addOrderBy("\"SubsiteID\"");
}
}

Expand Down
6 changes: 3 additions & 3 deletions code/extensions/GroupSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
*/
function requireDefaultRecords() {
// Migration for Group.SubsiteID data from when Groups only had a single subsite
$groupFields = DB::getConn()->fieldList('Group');
$groupFields = DB::field_list('Group');

// Detection of SubsiteID field is the trigger for old-style-subsiteID migration
if(isset($groupFields['SubsiteID'])) {
Expand All @@ -35,7 +35,7 @@ function requireDefaultRecords() {
DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1 WHERE "SubsiteID" = 0');

// Move the field out of the way so that this migration doesn't get executed again
DB::getConn()->renameField('Group', 'SubsiteID', '_obsolete_SubsiteID');
DB::get_schema()->renameField('Group', 'SubsiteID', '_obsolete_SubsiteID');

// No subsite access on anything means that we've just installed the subsites module.
// Make all previous groups global-access groups
Expand Down Expand Up @@ -107,7 +107,7 @@ function alternateTreeTitle() {
/**
* Update any requests to limit the results to the current site
*/
function augmentSQL(SQLQuery &$query) {
public function augmentSQL(SQLSelect $query) {
if(Subsite::$disable_subsite_filter) return;
if(Cookie::get('noSubsiteFilter') == 'true') return;

Expand Down
26 changes: 15 additions & 11 deletions code/extensions/SiteConfigSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ class SiteConfigSubsites extends DataExtension {
/**
* Update any requests to limit the results to the current site
*/
function augmentSQL(SQLQuery &$query) {
public function augmentSQL(SQLSelect $query) {
if(Subsite::$disable_subsite_filter) return;

// If you're querying by ID, ignore the sub-site - this is a bit ugly...
if (!$query->where || (!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]) && !preg_match('/\.?(\'|"|`|)SubsiteID(\'|"|`|)( ?)=/', $query->where[0]))) {
/*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else */$subsiteID = (int)Subsite::currentSubsiteID();

$froms=$query->getFrom();
$froms=array_keys($froms);
$tableName = array_shift($froms);
if($tableName != 'SiteConfig') return;
$query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
if($query->filtersOnID()) return;
$regexp = '/^(.*\.)?("|`)?SubsiteID("|`)?\s?=/';
foreach($query->getWhereParameterised($parameters) as $predicate) {
if(preg_match($regexp, $predicate)) return;
}

/*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else */$subsiteID = (int)Subsite::currentSubsiteID();

$froms=$query->getFrom();
$froms=array_keys($froms);
$tableName = array_shift($froms);
if($tableName != 'SiteConfig') return;
$query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
}

function onBeforeWrite() {
Expand Down
33 changes: 14 additions & 19 deletions code/extensions/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,26 @@ function isMainSite() {
/**
* Update any requests to limit the results to the current site
*/
function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) {
if(Subsite::$disable_subsite_filter) return;
if($dataQuery->getQueryParam('Subsite.filter') === false) return;

// Don't run on delete queries, since they are always tied to
// a specific ID.
if ($query->getDelete()) return;

// If you're querying by ID, ignore the sub-site - this is a bit ugly...
// if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) {
if (!$query->where || (!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]))) {
if($query->filtersOnID()) return;

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->getFrom() as $tableName => $info) {
// The tableName should be SiteTree or SiteTree_Live...
if(strpos($tableName,'SiteTree') === false) break;
$query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
break;
}
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->getFrom() as $tableName => $info) {
// The tableName should be SiteTree or SiteTree_Live...
if(strpos($tableName,'SiteTree') === false) break;
$query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
break;
}
}

Expand Down
17 changes: 11 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
"type": "silverstripe-module",
"keywords": ["silverstripe", "subsites", "multisite"],
"authors": [
{
"name": "Sam Minnee",
"email": "sam@silverstripe.com"
}
{
"name": "Sam Minnee",
"email": "sam@silverstripe.com"
}
],
"require":
{
"silverstripe/framework": "~3.1",
"silverstripe/cms": "~3.1"
"silverstripe/framework": "~3.2",
"silverstripe/cms": "~3.2"
},
"extra": {
"branch-alias": {
"dev-master": "0.6.x-dev"
}
}
}
1 change: 1 addition & 0 deletions tests/SubsitesVirtualPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function testPublishedSubsiteVirtualPagesUpdateIfTargetPageUpdates()
// create svp in subsite
$svp = new SubsitesVirtualPage();
$svp->CopyContentFromID = $p->ID;
$svp->write();
$svp->writeToStage('Stage');
$svp->publish('Stage', 'Live');
$this->assertEquals($svp->SubsiteID, $subsite->ID);
Expand Down

0 comments on commit a97b0d3

Please sign in to comment.