From 27aad3decad52f0e48f816257ef7af8dc0a8e96e Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 11 Jan 2011 23:00:59 +0000 Subject: [PATCH] BUGFIX #6291 Remove rollback action from CMSMain allowed_actions and rely on form action_rollback instead which is safer git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@115440 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CMSMain.php | 14 +++++++------- tests/CMSMainTest.php | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/code/CMSMain.php b/code/CMSMain.php index 192181ae..f636617d 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -52,7 +52,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'getshowdeletedsubtree', 'getfilteredsubtree', 'batchactions', - 'rollback', // see http://open.silverstripe.org/ticket/6291 ); /** @@ -390,11 +389,15 @@ JS; * Get a database record to be managed by the CMS */ public function getRecord($id) { - $treeClass = $this->stat('tree_class'); if($id && is_numeric($id)) { - $record = DataObject::get_one( $treeClass, "\"$treeClass\".\"ID\" = $id"); + $version = isset($_REQUEST['Version']) ? $_REQUEST['Version'] : null; + if(is_numeric($version)) { + $record = Versioned::get_version($treeClass, $id, $version); + } else { + $record = DataObject::get_one($treeClass, "\"$treeClass\".\"ID\" = $id"); + } // Then, try getting a record from the live site if(!$record) { @@ -902,10 +905,7 @@ JS; 'Root' ); - $actions = new FieldSet( - new FormAction("email", _t('CMSMain.EMAIL',"Email")), - new FormAction("rollback", _t('CMSMain.ROLLBACK',"Roll back to this version")) - ); + $actions = $record->getCMSActions(); // encode the message to appear in the body of the email $archiveURL = Director::absoluteBaseURL() . $record->URLSegment . '?archiveDate=' . $record->obj('LastEdited')->URLDatetime(); diff --git a/tests/CMSMainTest.php b/tests/CMSMainTest.php index 6c535a61..6bbb75c0 100644 --- a/tests/CMSMainTest.php +++ b/tests/CMSMainTest.php @@ -186,9 +186,22 @@ class CMSMainTest extends FunctionalTest { $newPage = $cmsMain->getRecord('new-Page-5'); $this->assertType('Page', $newPage); $this->assertEquals('5', $newPage->ParentID); - } - + + function testGetVersionRecord() { + $cmsMain = new CMSMain(); + $page1 = $this->objFromFixture('Page', 'page1'); + $page1->Content = 'this is the old content'; + $page1->write(); + $page1->Content = 'this is new content (new version)'; + $page1->write(); + $versionID = DB::query('SELECT "Version" FROM "SiteTree_versions" WHERE "Content" = \'this is the old content\'')->value(); + $_REQUEST['Version'] = $versionID; + $this->assertEquals($cmsMain->getRecord($page1->ID)->Version, $versionID); + $this->assertEquals($cmsMain->getRecord($page1->ID)->Content, 'this is the old content'); + unset($_REQUEST['Version']); + } + function testDeletedPagesSiteTreeFilter() { $id = $this->idFromFixture('Page', 'page3'); $this->logInWithPermission('ADMIN');