mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: Added static to set regeneration of default pages (ticket #5633) (from r107426)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112591 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
bd6e51c87f
commit
2f4fe2ff35
@ -176,6 +176,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
*/
|
*/
|
||||||
private static $nested_urls = false;
|
private static $nested_urls = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SiteTree::disable_create_defaultpages()
|
||||||
|
*/
|
||||||
|
private static $create_default_pages = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controls whether of not extendCMSFields() is called by getCMSFields.
|
* This controls whether of not extendCMSFields() is called by getCMSFields.
|
||||||
*/
|
*/
|
||||||
@ -216,6 +221,14 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
self::$nested_urls = false;
|
self::$nested_urls = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables the (re)creation of default pages on /dev/build
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static function set_create_defaultpages($option = true) {
|
||||||
|
self::$create_default_pages = $option;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the {@link SiteTree} object that maps to a link.
|
* Fetches the {@link SiteTree} object that maps to a link.
|
||||||
*
|
*
|
||||||
@ -1294,7 +1307,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
parent::requireDefaultRecords();
|
parent::requireDefaultRecords();
|
||||||
|
|
||||||
// default pages
|
// default pages
|
||||||
if($this->class == 'SiteTree') {
|
if($this->class == 'SiteTree' && self::$create_default_pages) {
|
||||||
if(!SiteTree::get_by_link('home')) {
|
if(!SiteTree::get_by_link('home')) {
|
||||||
$homepage = new Page();
|
$homepage = new Page();
|
||||||
$homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home');
|
$homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home');
|
||||||
|
@ -55,6 +55,27 @@ class SiteTreeTest extends SapphireTest {
|
|||||||
parent::tear_down_once();
|
parent::tear_down_once();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testCreateDefaultpages() {
|
||||||
|
$remove = DataObject::get('SiteTree');
|
||||||
|
if($remove) foreach($remove as $page) $page->delete();
|
||||||
|
// Make sure the table is empty
|
||||||
|
$this->assertEquals(DB::query('SELECT COUNT(ID) FROM "SiteTree"')->value(), 0);
|
||||||
|
|
||||||
|
// Disable the creation
|
||||||
|
SiteTree::set_create_defaultpages(false);
|
||||||
|
singleton('SiteTree')->requireDefaultRecords();
|
||||||
|
|
||||||
|
// The table should still be empty
|
||||||
|
$this->assertEquals(DB::query('SELECT COUNT(ID) FROM "SiteTree"')->value(), 0);
|
||||||
|
|
||||||
|
// Enable the creation
|
||||||
|
SiteTree::set_create_defaultpages(true);
|
||||||
|
singleton('SiteTree')->requireDefaultRecords();
|
||||||
|
|
||||||
|
// The table should now have three rows (home, about-us, contact-us)
|
||||||
|
$this->assertEquals(DB::query('SELECT COUNT(ID) FROM "SiteTree"')->value(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test generation of the URLSegment values.
|
* Test generation of the URLSegment values.
|
||||||
* - Turns things into lowercase-hyphen-format
|
* - Turns things into lowercase-hyphen-format
|
||||||
|
Loading…
Reference in New Issue
Block a user