Skip to content

Commit 27aad3d

Browse files
Sean HarveySam Minnee
Sean Harvey
authored and
Sam Minnee
committed
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
1 parent 3b6a957 commit 27aad3d

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

code/CMSMain.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
5252
'getshowdeletedsubtree',
5353
'getfilteredsubtree',
5454
'batchactions',
55-
'rollback', // see http://open.silverstripe.org/ticket/6291
5655
);
5756

5857
/**
@@ -390,11 +389,15 @@ function save_siteconfig($data, $form) {
390389
* Get a database record to be managed by the CMS
391390
*/
392391
public function getRecord($id) {
393-
394392
$treeClass = $this->stat('tree_class');
395393

396394
if($id && is_numeric($id)) {
397-
$record = DataObject::get_one( $treeClass, "\"$treeClass\".\"ID\" = $id");
395+
$version = isset($_REQUEST['Version']) ? $_REQUEST['Version'] : null;
396+
if(is_numeric($version)) {
397+
$record = Versioned::get_version($treeClass, $id, $version);
398+
} else {
399+
$record = DataObject::get_one($treeClass, "\"$treeClass\".\"ID\" = $id");
400+
}
398401

399402
// Then, try getting a record from the live site
400403
if(!$record) {
@@ -902,10 +905,7 @@ function getversion() {
902905
'Root'
903906
);
904907

905-
$actions = new FieldSet(
906-
new FormAction("email", _t('CMSMain.EMAIL',"Email")),
907-
new FormAction("rollback", _t('CMSMain.ROLLBACK',"Roll back to this version"))
908-
);
908+
$actions = $record->getCMSActions();
909909

910910
// encode the message to appear in the body of the email
911911
$archiveURL = Director::absoluteBaseURL() . $record->URLSegment . '?archiveDate=' . $record->obj('LastEdited')->URLDatetime();

tests/CMSMainTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,22 @@ function testGetRecord() {
186186
$newPage = $cmsMain->getRecord('new-Page-5');
187187
$this->assertType('Page', $newPage);
188188
$this->assertEquals('5', $newPage->ParentID);
189+
}
189190

191+
function testGetVersionRecord() {
192+
$cmsMain = new CMSMain();
193+
$page1 = $this->objFromFixture('Page', 'page1');
194+
$page1->Content = 'this is the old content';
195+
$page1->write();
196+
$page1->Content = 'this is new content (new version)';
197+
$page1->write();
198+
$versionID = DB::query('SELECT "Version" FROM "SiteTree_versions" WHERE "Content" = \'this is the old content\'')->value();
199+
$_REQUEST['Version'] = $versionID;
200+
$this->assertEquals($cmsMain->getRecord($page1->ID)->Version, $versionID);
201+
$this->assertEquals($cmsMain->getRecord($page1->ID)->Content, 'this is the old content');
202+
unset($_REQUEST['Version']);
190203
}
191-
204+
192205
function testDeletedPagesSiteTreeFilter() {
193206
$id = $this->idFromFixture('Page', 'page3');
194207
$this->logInWithPermission('ADMIN');

0 commit comments

Comments
 (0)