Merge pull request #157 from tractorcow/pulls/0.6/branch

BUG Fix incompatibility with framework 3.2
This commit is contained in:
Sean Harvey 2014-08-26 18:06:40 +12:00
commit ba6cb193b7
7 changed files with 69 additions and 63 deletions

View File

@ -3,18 +3,21 @@
language: php language: php
php: php:
- 5.3 - 5.4
env: env:
- DB=MYSQL CORE_RELEASE=3.1 global:
- DB=PGSQL CORE_RELEASE=master - CORE_RELEASE=master
matrix:
- DB=MYSQL
- DB=PGSQL
matrix: matrix:
include: include:
- php: 5.3
env: DB=MYSQL
- php: 5.4 - php: 5.4
env: DB=MYSQL CORE_RELEASE=master env: DB=MYSQL BEHAT_TEST=1
- php: 5.4
env: DB=MYSQL CORE_RELEASE=3.1 BEHAT_TEST=1
before_script: before_script:
- composer self-update - composer self-update

View File

@ -57,16 +57,15 @@ class FileSubsites extends DataExtension {
/** /**
* Update any requests to limit the results to the current site * 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(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) // 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 //@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(); $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 :-) // The foreach is an ugly way of getting the first key :-)
@ -80,11 +79,10 @@ class FileSubsites extends DataExtension {
$isCounting = strpos($sect[0], 'COUNT') !== false; $isCounting = strpos($sect[0], 'COUNT') !== false;
// Ordering when deleting or counting doesn't apply // Ordering when deleting or counting doesn't apply
if(!$query->getDelete() && !$isCounting) { if(!$isCounting) {
$query->addOrderBy("\"SubsiteID\""); $query->addOrderBy("\"SubsiteID\"");
} }
} }
}
function onBeforeWrite() { function onBeforeWrite() {
if (!$this->owner->ID && !$this->owner->SubsiteID) { if (!$this->owner->ID && !$this->owner->SubsiteID) {

View File

@ -23,7 +23,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
*/ */
function requireDefaultRecords() { function requireDefaultRecords() {
// Migration for Group.SubsiteID data from when Groups only had a single subsite // 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 // Detection of SubsiteID field is the trigger for old-style-subsiteID migration
if(isset($groupFields['SubsiteID'])) { if(isset($groupFields['SubsiteID'])) {
@ -35,7 +35,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1 WHERE "SubsiteID" = 0'); 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 // 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. // No subsite access on anything means that we've just installed the subsites module.
// Make all previous groups global-access groups // Make all previous groups global-access groups
@ -107,7 +107,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
/** /**
* Update any requests to limit the results to the current site * 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(Subsite::$disable_subsite_filter) return;
if(Cookie::get('noSubsiteFilter') == 'true') return; if(Cookie::get('noSubsiteFilter') == 'true') return;

View File

@ -12,11 +12,16 @@ class SiteConfigSubsites extends DataExtension {
/** /**
* Update any requests to limit the results to the current site * 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(Subsite::$disable_subsite_filter) return;
// If you're querying by ID, ignore the sub-site - this is a bit ugly... // 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($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; /*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else */$subsiteID = (int)Subsite::currentSubsiteID(); else */$subsiteID = (int)Subsite::currentSubsiteID();
@ -26,7 +31,6 @@ class SiteConfigSubsites extends DataExtension {
if($tableName != 'SiteConfig') return; if($tableName != 'SiteConfig') return;
$query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)"); $query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
} }
}
function onBeforeWrite() { function onBeforeWrite() {
if((!is_numeric($this->owner->ID) || !$this->owner->ID) && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID(); if((!is_numeric($this->owner->ID) || !$this->owner->ID) && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID();

View File

@ -25,17 +25,13 @@ class SiteTreeSubsites extends DataExtension {
/** /**
* Update any requests to limit the results to the current site * 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(Subsite::$disable_subsite_filter) return;
if($dataQuery->getQueryParam('Subsite.filter') === false) 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 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 || (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; if (Subsite::$force_subsite) $subsiteID = Subsite::$force_subsite;
else { else {
@ -51,7 +47,6 @@ class SiteTreeSubsites extends DataExtension {
break; break;
} }
} }
}
function onBeforeWrite() { function onBeforeWrite() {
if(!$this->owner->ID && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID(); if(!$this->owner->ID && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID();

View File

@ -11,7 +11,12 @@
], ],
"require": "require":
{ {
"silverstripe/framework": "~3.1", "silverstripe/framework": "~3.2",
"silverstripe/cms": "~3.1" "silverstripe/cms": "~3.2"
},
"extra": {
"branch-alias": {
"dev-master": "0.6.x-dev"
}
} }
} }

View File

@ -161,6 +161,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
// create svp in subsite // create svp in subsite
$svp = new SubsitesVirtualPage(); $svp = new SubsitesVirtualPage();
$svp->CopyContentFromID = $p->ID; $svp->CopyContentFromID = $p->ID;
$svp->write();
$svp->writeToStage('Stage'); $svp->writeToStage('Stage');
$svp->publish('Stage', 'Live'); $svp->publish('Stage', 'Live');
$this->assertEquals($svp->SubsiteID, $subsite->ID); $this->assertEquals($svp->SubsiteID, $subsite->ID);