BUG Fixing FileSubsites failing when deleting ImageTracking

This commit is contained in:
Sean Harvey 2012-11-07 14:25:32 +13:00
parent 3d59f10331
commit cac77703ed
1 changed files with 6 additions and 3 deletions

View File

@ -46,9 +46,12 @@ class FileSubsites extends DataExtension {
function augmentSQL(SQLQuery &$query) {
// 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
if(array_search('SiteTree_ImageTracking', $query->getFrom())===false && (!$query->where || !preg_match('/\.(\'|"|`|)ID(\'|"|`|)/', $query->where[0]))) {
/*if($context = DataObject::context_obj()) $subsiteID = (int) $context->SubsiteID;
else */$subsiteID = (int) Subsite::currentSubsiteID();
$from = $query->getFrom();
$where = $query->getWhere();
if(!isset($from['SiteTree_ImageTracking']) && !($where && preg_match('/\.(\'|"|`|)ID(\'|"|`|)/', $where[0]))) {
$subsiteID = (int) Subsite::currentSubsiteID();
// The foreach is an ugly way of getting the first key :-)
foreach($query->getFrom() as $tableName => $info) {