mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
API Rename mysiteconfig to subsiteconfig
API make ErrorPageSubsite 4.x compatible BUG Fix incorrect yml BUG Fix incorrect DataExtension::augmentSQL implementation
This commit is contained in:
parent
d45ff44edb
commit
0d7dc49d6b
@ -1,6 +1,8 @@
|
||||
---
|
||||
Name: mysiteconfig
|
||||
After: 'framework/*','cms/*'
|
||||
Name: subsiteconfig
|
||||
After:
|
||||
- 'framework/*'
|
||||
- 'cms/*'
|
||||
---
|
||||
AssetAdmin:
|
||||
treats_subsite_0_as_global: true
|
||||
|
@ -4,14 +4,15 @@ class ErrorPageSubsite extends DataExtension {
|
||||
/**
|
||||
* Alter file path to generated a static (static) error page file to handle error page template on different sub-sites
|
||||
*
|
||||
* @see Error::get_filepath_for_errorcode()
|
||||
* {@see Error::get_error_filename()}
|
||||
*
|
||||
* FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including main site) between
|
||||
* opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly.
|
||||
*
|
||||
* @param string $name Filename to write to
|
||||
* @param int $statusCode Integer error code
|
||||
*/
|
||||
function alternateFilepathForErrorcode($statusCode, $locale = null) {
|
||||
$static_filepath = Config::inst()->get($this->owner->ClassName, 'static_filepath');
|
||||
$subdomainPart = "";
|
||||
public function updateErrorFilename(&$name, $statusCode) {
|
||||
|
||||
// Try to get current subsite from session
|
||||
$subsite = Subsite::currentSubsite(false);
|
||||
@ -19,22 +20,18 @@ class ErrorPageSubsite extends DataExtension {
|
||||
// since this function is called from Page class before the controller is created, we have to get subsite from domain instead
|
||||
if(!$subsite) {
|
||||
$subsiteID = Subsite::getSubsiteIDForDomain();
|
||||
if($subsiteID != 0) $subsite = DataObject::get_by_id("Subsite", $subsiteID);
|
||||
else $subsite = null;
|
||||
if($subsiteID != 0) {
|
||||
$subsite = DataObject::get_by_id("Subsite", $subsiteID);
|
||||
}
|
||||
}
|
||||
|
||||
// Without subsite, don't rewrite
|
||||
if($subsite) {
|
||||
// Add subdomain to end of filename, just before .html
|
||||
// This should preserve translatable locale in the filename as well
|
||||
$subdomain = $subsite->domain();
|
||||
$subdomainPart = "-{$subdomain}";
|
||||
$name = substr($name, 0, -5) . "-{$subdomain}.html";
|
||||
}
|
||||
|
||||
if(singleton('SiteTree')->hasExtension('Translatable') && $locale && $locale != Translatable::default_locale()) {
|
||||
$filepath = $static_filepath . "/error-{$statusCode}-{$locale}{$subdomainPart}.html";
|
||||
} else {
|
||||
$filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html";
|
||||
}
|
||||
|
||||
return $filepath;
|
||||
}
|
||||
|
||||
}
|
@ -57,7 +57,7 @@ class FileSubsites extends DataExtension {
|
||||
/**
|
||||
* Update any requests to limit the results to the current site
|
||||
*/
|
||||
public function augmentSQL(SQLSelect $query) {
|
||||
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... (but it was WAYYYYYYYYY worse)
|
||||
|
@ -107,7 +107,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
|
||||
/**
|
||||
* Update any requests to limit the results to the current site
|
||||
*/
|
||||
public function augmentSQL(SQLSelect $query) {
|
||||
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) {
|
||||
if(Subsite::$disable_subsite_filter) return;
|
||||
if(Cookie::get('noSubsiteFilter') == 'true') return;
|
||||
|
||||
|
@ -12,7 +12,7 @@ class SiteConfigSubsites extends DataExtension {
|
||||
/**
|
||||
* Update any requests to limit the results to the current site
|
||||
*/
|
||||
public function augmentSQL(SQLSelect $query) {
|
||||
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...
|
||||
|
@ -25,7 +25,7 @@ class SiteTreeSubsites extends DataExtension {
|
||||
/**
|
||||
* Update any requests to limit the results to the current site
|
||||
*/
|
||||
public function augmentSQL(SQLSelect $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;
|
||||
|
||||
|
@ -6,7 +6,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
'SiteTreeSubsitesTest_ClassA',
|
||||
'SiteTreeSubsitesTest_ClassB'
|
||||
'SiteTreeSubsitesTest_ClassB',
|
||||
'SiteTreeSubsitesTest_ErrorPage'
|
||||
);
|
||||
|
||||
protected $illegalExtensions = array(
|
||||
@ -55,10 +56,9 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
|
||||
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
|
||||
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
$path = ErrorPage::get_filepath_for_errorcode(500);
|
||||
$path = SiteTreeSubsitesTest_ErrorPage::get_error_filename_spy(500);
|
||||
|
||||
$static_path = Config::inst()->get('ErrorPage', 'static_filepath');
|
||||
$expected_path = $static_path . '/error-500-'.$subsite1->domain().'.html';
|
||||
$expected_path = 'error-500-'.$subsite1->domain().'.html';
|
||||
$this->assertEquals($expected_path, $path);
|
||||
}
|
||||
|
||||
@ -201,3 +201,16 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
|
||||
class SiteTreeSubsitesTest_ClassA extends SiteTree implements TestOnly {}
|
||||
|
||||
class SiteTreeSubsitesTest_ClassB extends SiteTree implements TestOnly {}
|
||||
|
||||
class SiteTreeSubsitesTest_ErrorPage extends ErrorPage implements TestOnly {
|
||||
|
||||
/**
|
||||
* Helper method to call protected members
|
||||
*
|
||||
* @param int $statusCode
|
||||
* @return string
|
||||
*/
|
||||
public static function get_error_filename_spy($statusCode) {
|
||||
return self::get_error_filename($statusCode);
|
||||
}
|
||||
}
|
@ -1,78 +1,78 @@
|
||||
Subsite:
|
||||
main:
|
||||
Title: Template
|
||||
Title: 'Template'
|
||||
subsite1:
|
||||
Title: Subsite1 Template
|
||||
Title: 'Subsite1 Template'
|
||||
subsite2:
|
||||
Title: Subsite2 Template
|
||||
Title: 'Subsite2 Template'
|
||||
domaintest1:
|
||||
Title: Test 1
|
||||
Title: 'Test 1'
|
||||
domaintest2:
|
||||
Title: Test 2
|
||||
Title: 'Test 2'
|
||||
domaintest3:
|
||||
Title: Test 3
|
||||
Title: 'Test 3'
|
||||
SubsiteDomain:
|
||||
subsite1:
|
||||
SubsiteID: =>Subsite.subsite1
|
||||
Domain: subsite1.*
|
||||
Domain: 'subsite1.*'
|
||||
subsite2:
|
||||
SubsiteID: =>Subsite.subsite2
|
||||
Domain: subsite2.*
|
||||
Domain: 'subsite2.*'
|
||||
dt1a:
|
||||
SubsiteID: =>Subsite.domaintest1
|
||||
Domain: one.example.org
|
||||
Domain: 'one.example.org'
|
||||
IsPrimary: 1
|
||||
dt1b:
|
||||
SubsiteID: =>Subsite.domaintest1
|
||||
Domain: one.*
|
||||
Domain: 'one.*'
|
||||
dt2a:
|
||||
SubsiteID: =>Subsite.domaintest2
|
||||
Domain: two.mysite.com
|
||||
Domain: 'two.mysite.com'
|
||||
IsPrimary: 1
|
||||
dt2b:
|
||||
SubsiteID: =>Subsite.domaintest2
|
||||
Domain: *.mysite.com
|
||||
Domain: '*.mysite.com'
|
||||
dt3:
|
||||
SubsiteID: =>Subsite.domaintest3
|
||||
Domain: three.*
|
||||
Domain: 'three.*'
|
||||
IsPrimary: 1
|
||||
Page:
|
||||
mainSubsitePage:
|
||||
Title: MainSubsitePage
|
||||
Title: 'MainSubsitePage'
|
||||
SubsiteID: 0
|
||||
home:
|
||||
Title: Home
|
||||
Title: 'Home'
|
||||
SubsiteID: =>Subsite.main
|
||||
about:
|
||||
Title: About
|
||||
Title: 'About'
|
||||
SubsiteID: =>Subsite.main
|
||||
linky:
|
||||
Title: Linky
|
||||
Title: 'Linky'
|
||||
SubsiteID: =>Subsite.main
|
||||
staff:
|
||||
Title: Staff
|
||||
Title: 'Staff'
|
||||
ParentID: =>Page.about
|
||||
SubsiteID: =>Subsite.main
|
||||
contact:
|
||||
Title: Contact Us
|
||||
Title: 'Contact Us'
|
||||
SubsiteID: =>Subsite.main
|
||||
importantpage:
|
||||
Title: Important Page
|
||||
Title: 'Important Page'
|
||||
SubsiteID: =>Subsite.main
|
||||
subsite1_home:
|
||||
Title: Home (Subsite 1)
|
||||
Title: 'Home (Subsite 1)'
|
||||
SubsiteID: =>Subsite.subsite1
|
||||
subsite1_contactus:
|
||||
Title: Contact Us (Subsite 1)
|
||||
Title: 'Contact Us (Subsite 1)'
|
||||
SubsiteID: =>Subsite.subsite1
|
||||
subsite1_staff:
|
||||
Title: Staff
|
||||
Title: 'Staff'
|
||||
SubsiteID: =>Subsite.subsite1
|
||||
subsite2_home:
|
||||
Title: Home (Subsite 2)
|
||||
Title: 'Home (Subsite 2)'
|
||||
SubsiteID: =>Subsite.subsite2
|
||||
subsite2_contactus:
|
||||
Title: Contact Us (Subsite 2)
|
||||
Title: 'Contact Us (Subsite 2)'
|
||||
SubsiteID: =>Subsite.subsite2
|
||||
|
||||
PermissionRoleCode:
|
||||
|
@ -6,25 +6,28 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
|
||||
'subsites/tests/SubsitesVirtualPageTest.yml',
|
||||
);
|
||||
|
||||
function setUp() {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
||||
$fh = fopen(Director::baseFolder() . '/assets/testscript-test-file.pdf', "w");
|
||||
fwrite($fh, str_repeat('x',1000000));
|
||||
fclose($fh);
|
||||
// Set backend root to /DataDifferencerTest
|
||||
AssetStoreTest_SpyStore::activate('SubsitesVirtualPageTest');
|
||||
|
||||
// Create a test files for each of the fixture references
|
||||
$file = $this->objFromFixture('File', 'file1');
|
||||
$page = $this->objFromFixture('SiteTree', 'page1');
|
||||
$fromPath = __DIR__ . '/testscript-test-file.pdf';
|
||||
$destPath = AssetStoreTest_SpyStore::getLocalPath($file);
|
||||
Filesystem::makeFolder(dirname($destPath));
|
||||
copy($fromPath, $destPath);
|
||||
|
||||
// Hack in site link tracking after the fact
|
||||
$page->Content = '<p><img src="'. $file->getURL(). '" data-fileid="' . $file->ID . '" /></p>';
|
||||
$page->write();
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
public function tearDown() {
|
||||
AssetStoreTest_SpyStore::reset();
|
||||
parent::tearDown();
|
||||
$testFiles = array(
|
||||
'/assets/testscript-test-file.pdf',
|
||||
'/assets/renamed-test-file.pdf',
|
||||
'/assets/renamed-test-file-second-time.pdf',
|
||||
);
|
||||
foreach($testFiles as $file) {
|
||||
if(file_exists(Director::baseFolder().$file)) unlink(Director::baseFolder().$file);
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to bring main:linky to subsite2:linky
|
||||
@ -52,7 +55,6 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
|
||||
function testFileLinkRewritingOnVirtualPages() {
|
||||
// File setup
|
||||
$this->logInWithPermission('ADMIN');
|
||||
touch(Director::baseFolder() . '/assets/testscript-test-file.pdf');
|
||||
|
||||
// Publish the source page
|
||||
$page = $this->objFromFixture('SiteTree', 'page1');
|
||||
@ -70,19 +72,10 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
|
||||
$file->write();
|
||||
|
||||
// Verify that the draft and publish virtual pages both have the corrected link
|
||||
$this->assertContains('<img src="assets/renamed-test-file.pdf"',
|
||||
$this->assertContains('<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"',
|
||||
DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $svp->ID")->value());
|
||||
$this->assertContains('<img src="assets/renamed-test-file.pdf"',
|
||||
$this->assertContains('<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"',
|
||||
DB::query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = $svp->ID")->value());
|
||||
|
||||
// File teardown
|
||||
$testFiles = array(
|
||||
'/assets/testscript-test-file.pdf',
|
||||
'/assets/renamed-test-file.pdf',
|
||||
);
|
||||
foreach($testFiles as $file) {
|
||||
if(file_exists(Director::baseFolder().$file)) unlink(Director::baseFolder().$file);
|
||||
}
|
||||
}
|
||||
|
||||
function testSubsiteVirtualPagesArentInappropriatelyPublished() {
|
||||
|
@ -1,10 +1,12 @@
|
||||
# These need to come first so that SiteTree has the link meta-data written.
|
||||
File:
|
||||
file1:
|
||||
Filename: assets/testscript-test-file.pdf
|
||||
FileFilename: testscript-test-file.pdf
|
||||
FileHash: 464dedb70af0dc7f8f3360e7f3ae43cbbf1cdf4e
|
||||
Name: testscript-test-file.pdf
|
||||
|
||||
SiteTree:
|
||||
page1:
|
||||
Title: page1
|
||||
URLSegment: page1
|
||||
Content: <p><img src="assets/testscript-test-file.pdf" /></p>
|
||||
Content: '<p><img src="/assets/SubsitesVirtualPageTest/464dedb70a/testscript-test-file.pdf" /></p>'
|
||||
|
BIN
tests/testscript-test-file.pdf
Normal file
BIN
tests/testscript-test-file.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user