BUGFIX: Updated models to suit minor changes in the new ORM.

This commit is contained in:
Sam Minnee 2009-11-22 18:16:38 +13:00
parent 8fe9283181
commit 488a04c670
4 changed files with 21 additions and 12 deletions

View File

@ -269,8 +269,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
); );
/// Fall back on a unique URLSegment for b/c. /// Fall back on a unique URLSegment for b/c.
if(!$sitetree && self::nested_urls() && $pages = DataObject::get('SiteTree', "\"URLSegment\" = '$URLSegment'")) { if(!$sitetree && self::nested_urls() && $page = DataObject::get('SiteTree', "\"URLSegment\" = '$URLSegment'")->First()) {
return ($pages->Count() == 1) ? $pages->First() : null; return $page;
} }
// Attempt to grab an alternative page from extensions. // Attempt to grab an alternative page from extensions.
@ -1612,9 +1612,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if(is_callable('Subsite::disable_subsite_filter')) Subsite::disable_subsite_filter(true); if(is_callable('Subsite::disable_subsite_filter')) Subsite::disable_subsite_filter(true);
// Content links // Content links
$items = $this->BackLinkTracking(); $items = new DataObjectSet();
if(!$items) $items = new DataObjectSet();
else foreach($items as $item) $item->DependentLinkType = 'Content link'; // We merge all into a regular DataObjectSet, because DataList doesn't support merge
if($contentLinks = $this->BackLinkTracking()) {
foreach($contentLinks as $item) $item->DependentLinkType = 'Content link';
$items->merge($contentLinks);
}
// Virtual pages // Virtual pages
if($includeVirtuals) { if($includeVirtuals) {
@ -1696,7 +1700,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$parentPageLinks = array(); $parentPageLinks = array();
if(isset($linkedPages)) { if($linkedPages->Count() > 0) {
foreach($linkedPages as $linkedPage) { foreach($linkedPages as $linkedPage) {
$parentPage = $linkedPage->Parent; $parentPage = $linkedPage->Parent;
if($parentPage) { if($parentPage) {

View File

@ -410,7 +410,6 @@ class SiteTreePermissionsTest extends FunctionalTest {
$siteconfig->CanViewType = 'OnlyTheseUsers'; $siteconfig->CanViewType = 'OnlyTheseUsers';
$siteconfig->ViewerGroups()->add($editorGroup); $siteconfig->ViewerGroups()->add($editorGroup);
$siteconfig->ViewerGroups()->write();
$siteconfig->write(); $siteconfig->write();
$this->assertTrue($page->canView($editor), 'Editors can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to OnlyTheseUsers'); $this->assertTrue($page->canView($editor), 'Editors can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to OnlyTheseUsers');
$this->assertFalse($page->canView(FALSE), 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to OnlyTheseUsers'); $this->assertFalse($page->canView(FALSE), 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to OnlyTheseUsers');
@ -432,7 +431,6 @@ class SiteTreePermissionsTest extends FunctionalTest {
$siteconfig->CanEditType = 'OnlyTheseUsers'; $siteconfig->CanEditType = 'OnlyTheseUsers';
$siteconfig->EditorGroups()->add($editorGroup); $siteconfig->EditorGroups()->add($editorGroup);
$siteconfig->EditorGroups()->write();
$siteconfig->write(); $siteconfig->write();
$this->assertTrue($page->canEdit($editor), 'Editors can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to OnlyTheseUsers'); $this->assertTrue($page->canEdit($editor), 'Editors can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to OnlyTheseUsers');
$this->session()->inst_set('loggedInAs', null); $this->session()->inst_set('loggedInAs', null);

View File

@ -296,7 +296,7 @@ class SiteTreeTest extends SapphireTest {
Versioned::reading_stage('Live'); Versioned::reading_stage('Live');
$deletedPage = Versioned::get_latest_version('SiteTree', $page2ID); $deletedPage = Versioned::get_latest_version('SiteTree', $page2ID);
$deletedPage->doRestoreToStage(); $deletedPage->doRestoreToStage();
$this->assertTrue(!Versioned::get_one_by_stage("Page", "Live", "\"SiteTree\".\"ID\" = " . $page2ID)); $this->assertFalse((bool)Versioned::get_one_by_stage("Page", "Live", "\"SiteTree\".\"ID\" = " . $page2ID));
Versioned::reading_stage('Stage'); Versioned::reading_stage('Stage');
$requeriedPage = DataObject::get_by_id("Page", $page2ID); $requeriedPage = DataObject::get_by_id("Page", $page2ID);
@ -385,9 +385,16 @@ class SiteTreeTest extends SapphireTest {
$pageStaffDuplicate->doPublish(); $pageStaffDuplicate->doPublish();
$parentPage = $this->objFromFixture('Page', 'about'); $parentPage = $this->objFromFixture('Page', 'about');
$parentPage->doDeleteFromLive(); $parentPage->doDeleteFromLive();
Versioned::reading_stage('Live'); Versioned::reading_stage('Live');
// Confirm that none of the given pages exist
$this->assertEquals(array(), DataObject::get("Page")
->byIDs(array($pageAbout->ID, $pageStaff->ID, $pageStaffDuplicate->ID))
->column('URLSegment'));
$this->assertFalse(DataObject::get_by_id('Page', $pageAbout->ID)); $this->assertFalse(DataObject::get_by_id('Page', $pageAbout->ID));
$this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page);
$this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page);

View File

@ -273,7 +273,7 @@ class VirtualPageTest extends SapphireTest {
// Unpublish the source page, confirm that the virtual page has also been unpublished // Unpublish the source page, confirm that the virtual page has also been unpublished
$p->doUnpublish(); $p->doUnpublish();
$vpLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $vp->ID); $vpLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $vp->ID);
$this->assertFalse($vpLive); $this->assertNull($vpLive);
// Delete from draft, confirm that the virtual page has a broken link on the draft site // Delete from draft, confirm that the virtual page has a broken link on the draft site
$p->delete(); $p->delete();
@ -307,7 +307,7 @@ class VirtualPageTest extends SapphireTest {
$pLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $pID); $pLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $pID);
$this->assertTrue($pLive->doDeleteFromLive()); $this->assertTrue($pLive->doDeleteFromLive());
$vpLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $vp->ID); $vpLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $vp->ID);
$this->assertFalse($vpLive); $this->assertNull($vpLive);
// Delete from draft, confirm that the virtual page has a broken link on the draft site // Delete from draft, confirm that the virtual page has a broken link on the draft site
$pLive->delete(); $pLive->delete();