fix SiteConfigSubsites AugmentSQL: get the right table name to filter

This commit is contained in:
Werner M. Krauß 2017-05-30 17:58:31 +02:00
parent 997459caf3
commit f348f5fa97
2 changed files with 21 additions and 16 deletions

View File

@ -21,11 +21,14 @@ class SiteConfigSubsites extends DataExtension
'Subsite' => Subsite::class, // The subsite that this page belongs to
];
/**
* Update any requests to limit the results to the current site
*/
public function augmentSQL(SQLSelect$query, DataQuery $dataQuery = null) {
if(Subsite::$disable_subsite_filter) {return;}
/**
* Update any requests to limit the results to the current site
*/
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
{
if (Subsite::$disable_subsite_filter) {
return;
}
// If you're querying by ID, ignore the sub-site - this is a bit ugly...
if ($query->filtersOnID()) {
@ -38,14 +41,16 @@ class SiteConfigSubsites extends DataExtension
}
}
$subsiteID = (int)Subsite::currentSubsiteID();
$subsiteID = (int)Subsite::currentSubsiteID();
$froms=$query->getFrom();
$froms=array_keys($froms);
$tableName = array_shift($froms);
if($tableName != SiteConfig::class) { return;}
$query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
}
$froms = $query->getFrom();
$froms = array_keys($froms);
$tableName = array_shift($froms);
if ($tableName !== SiteConfig::getSchema()->tableName(SiteConfig::class)) {
return;
}
$query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
}
public function onBeforeWrite()
{
@ -59,7 +64,7 @@ class SiteConfigSubsites extends DataExtension
*/
public function cacheKeyComponent()
{
return 'subsite-'.Subsite::currentSubsiteID();
return 'subsite-' . Subsite::currentSubsiteID();
}
public function updateCMSFields(FieldList $fields)

View File

@ -33,11 +33,11 @@ class SiteConfigSubsitesTest extends BaseSubsiteTest
$sc->write();
Subsite::changeSubsite(0);
$this->assertEquals(SiteConfig::current_site_config()->Title, 'RootSite');
$this->assertEquals('RootSite', SiteConfig::current_site_config()->Title);
Subsite::changeSubsite($subsite1->ID);
$this->assertEquals(SiteConfig::current_site_config()->Title, 'Subsite1');
$this->assertEquals('Subsite1', SiteConfig::current_site_config()->Title);
Subsite::changeSubsite($subsite2->ID);
$this->assertEquals(SiteConfig::current_site_config()->Title, 'Subsite2');
$this->assertEquals('Subsite2', SiteConfig::current_site_config()->Title);
$keys = SiteConfig::current_site_config()->extend('cacheKeyComponent');
$this->assertContains('subsite-' . $subsite2->ID, $keys);