From d33c2869a7dc0bf1712d396427c81c9dbbcd6892 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 29 Apr 2009 02:45:19 +0000 Subject: [PATCH] BUGFIX: Let CMS users open pages deleted from draft; bug introduced by translatable. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@75611 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CMSMain.php | 6 ++++++ code/LeftAndMain.php | 19 +++--------------- tests/CMSMainTest.php | 46 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/code/CMSMain.php b/code/CMSMain.php index 6678dd0d..a52d8cab 100644 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -377,6 +377,12 @@ JS; $record = DataObject::get_one( $treeClass, "`$treeClass`.ID = $id"); if($record) Versioned::reading_stage(null); } + + // Don't open a page from a different locale + if($record && Translatable::is_enabled() && $record->Locale && $record->Locale != Translatable::current_locale()) { + $record = null; + } + return $record; } else if(substr($id,0,3) == 'new') { diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 38856eb4..633adeb0 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -451,7 +451,7 @@ class LeftAndMain extends Controller { public function getRecord($id, $className = null) { if(!$className) $className = $this->stat('tree_class'); - return DataObject::get_by_id($className, $rootID); + return DataObject::get_by_id($className, $id); } function getSiteTreeFor($className, $rootID = null) { @@ -844,12 +844,7 @@ JS; } public function EditForm() { - if(isset($_REQUEST['ID']) && is_numeric($_REQUEST['ID'])) { - $record = DataObject::get_by_id($this->stat('tree_class'), $_REQUEST['ID']); - } else { - $record = $this->CurrentPage(); - } - + $record = $this->currentPage(); if(!$record) return false; if($record && !$record->canView()) return Security::permissionFailure($this); @@ -899,15 +894,7 @@ JS; } public function currentPage() { - $id = $this->currentPageID(); - if($id && is_numeric($id)) { - $page = DataObject::get_by_id($this->stat('tree_class'), $id); - if($page && Translatable::is_enabled() && $page->Locale && $page->Locale != Translatable::current_locale()) { - return false; - } else { - return $page; - } - } + return $this->getRecord($this->currentPageID()); } public function isCurrentPage(DataObject $page) { diff --git a/tests/CMSMainTest.php b/tests/CMSMainTest.php index 21afae37..4c169fc8 100644 --- a/tests/CMSMainTest.php +++ b/tests/CMSMainTest.php @@ -1,6 +1,6 @@ assertTrue($page->getCMSFields(null) instanceof FieldSet); } } + + /** + * Test that a draft-deleted page can still be opened in the CMS + */ + function testDraftDeletedPageCanBeOpenedInCMS() { + // Set up a page that is delete from live + $page = $this->objFromFixture('Page','page1'); + $pageID = $page->ID; + $page->doPublish(); + $page->delete(); + + $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin')); + $response = $this->get('admin/getitem?ID=' . $pageID . '&ajax=1'); + + // Check that the 'delete from live' button exists as a simple way of checking that the correct page is returned. + $this->assertRegExp('/]+type="submit"[^>]+name="action_deletefromlive"/i', $response->getBody()); + } + + /** + * Test CMSMain::getRecord() + */ + function testGetRecord() { + // Set up a page that is delete from live + $page1 = $this->objFromFixture('Page','page1'); + $page1ID = $page1->ID; + $page1->doPublish(); + $page1->delete(); + + $cmsMain = new CMSMain(); + + // Bad calls + $this->assertNull($cmsMain->getRecord('0')); + $this->assertNull($cmsMain->getRecord('asdf')); + + // Pages that are on draft and aren't on draft should both work + $this->assertType('Page', $cmsMain->getRecord($page1ID)); + $this->assertType('Page', $cmsMain->getRecord($this->idFromFixture('Page','page2'))); + + // This functionality isn't actually used any more. + $newPage = $cmsMain->getRecord('new-Page-5'); + $this->assertType('Page', $newPage); + $this->assertEquals('5', $newPage->ParentID); + + } } \ No newline at end of file