mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
fix SiteConfigSubsites AugmentSQL: get the right table name to filter
This commit is contained in:
parent
997459caf3
commit
f348f5fa97
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user