Merge branch '1.4' into 1

This commit is contained in:
Robbie Averill 2018-05-04 13:44:30 +12:00
commit 531a38e043
3 changed files with 39 additions and 1 deletions

View File

@ -743,16 +743,35 @@ class Subsite extends DataObject
}
/**
* Whenever a Subsite is written, rewrite the hostmap
* Whenever a Subsite is written, rewrite the hostmap and create some default pages
*
* @return void
*/
public function onAfterWrite()
{
Subsite::writeHostMap();
if ($this->isChanged('ID')) {
$this->createDefaultPages();
}
parent::onAfterWrite();
}
/**
* Automatically create default pages for new subsites
*/
protected function createDefaultPages()
{
$currentSubsite = Subsite::currentSubsiteID();
Subsite::changeSubsite($this->ID);
// Silence DB schema output
DB::quiet();
$siteTree = new SiteTree();
$siteTree->requireDefaultRecords();
Subsite::changeSubsite($currentSubsite);
}
/**
* Return the primary domain of this site. Tries to "normalize" the domain name,
* by replacing potential wildcards.

View File

@ -13,6 +13,14 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
'SiteTree' => array('Translatable')
);
public function setUp()
{
// We have our own home page fixtures, prevent the default one being created in this test suite.
Config::inst()->update('SiteTree', 'create_default_pages', false);
parent::setUp();
}
public function testPagesInDifferentSubsitesCanShareURLSegment()
{
$subsiteMain = $this->objFromFixture('Subsite', 'main');

View File

@ -442,4 +442,15 @@ class SubsiteTest extends BaseSubsiteTest
$subsite2->activate();
$this->assertEquals('MyNewAwesomePage', DataObject::get_by_id('Page', $page2->ID)->Title);
}
public function testDefaultPageCreatedWhenCreatingSubsite()
{
$subsite = new Subsite();
$subsite->Title = 'New Subsite';
$subsite->write();
$subsite->activate();
$pages = SiteTree::get();
$this->assertGreaterThanOrEqual(1, $pages->count());
}
}