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:
Ingo Schommer 2010-10-15 03:44:57 +00:00
parent bd6e51c87f
commit 2f4fe2ff35
2 changed files with 35 additions and 1 deletions

View File

@ -176,6 +176,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
*/
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.
*/
@ -216,6 +221,14 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
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.
*
@ -1294,7 +1307,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
parent::requireDefaultRecords();
// default pages
if($this->class == 'SiteTree') {
if($this->class == 'SiteTree' && self::$create_default_pages) {
if(!SiteTree::get_by_link('home')) {
$homepage = new Page();
$homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home');

View File

@ -54,6 +54,27 @@ class SiteTreeTest extends SapphireTest {
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.