Skip to content

Commit

Permalink
BUGFIX #6291 Remove rollback action from CMSMain allowed_actions and …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Sean Harvey authored and Sam Minnee committed Feb 2, 2011
1 parent 3b6a957 commit 27aad3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
14 changes: 7 additions & 7 deletions code/CMSMain.php
Expand Up @@ -52,7 +52,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'getshowdeletedsubtree', 'getshowdeletedsubtree',
'getfilteredsubtree', 'getfilteredsubtree',
'batchactions', 'batchactions',
'rollback', // see http://open.silverstripe.org/ticket/6291
); );


/** /**
Expand Down Expand Up @@ -390,11 +389,15 @@ function save_siteconfig($data, $form) {
* Get a database record to be managed by the CMS * Get a database record to be managed by the CMS
*/ */
public function getRecord($id) { public function getRecord($id) {

$treeClass = $this->stat('tree_class'); $treeClass = $this->stat('tree_class');


if($id && is_numeric($id)) { 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 // Then, try getting a record from the live site
if(!$record) { if(!$record) {
Expand Down Expand Up @@ -902,10 +905,7 @@ function getversion() {
'Root' 'Root'
); );


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


// encode the message to appear in the body of the email // encode the message to appear in the body of the email
$archiveURL = Director::absoluteBaseURL() . $record->URLSegment . '?archiveDate=' . $record->obj('LastEdited')->URLDatetime(); $archiveURL = Director::absoluteBaseURL() . $record->URLSegment . '?archiveDate=' . $record->obj('LastEdited')->URLDatetime();
Expand Down
15 changes: 14 additions & 1 deletion tests/CMSMainTest.php
Expand Up @@ -186,9 +186,22 @@ function testGetRecord() {
$newPage = $cmsMain->getRecord('new-Page-5'); $newPage = $cmsMain->getRecord('new-Page-5');
$this->assertType('Page', $newPage); $this->assertType('Page', $newPage);
$this->assertEquals('5', $newPage->ParentID); $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() { function testDeletedPagesSiteTreeFilter() {
$id = $this->idFromFixture('Page', 'page3'); $id = $this->idFromFixture('Page', 'page3');
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
Expand Down

0 comments on commit 27aad3d

Please sign in to comment.