diff --git a/code/CMSMain.php b/code/CMSMain.php index 984f95da..3c2519e4 100644 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -331,12 +331,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)) { - // First, try getting a record from the stage site - $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) { @@ -743,11 +746,7 @@ JS; 'Root' ); - $actions = new FieldSet( - new FormAction("email", _t('CMSMain.EMAIL',"Email")), - new FormAction("print", _t('CMSMain.PRINT',"Print")), - 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 dfdd610b..1a8ca7bd 100644 --- a/tests/CMSMainTest.php +++ b/tests/CMSMainTest.php @@ -132,7 +132,20 @@ class CMSMainTest extends FunctionalTest { $newPage = $cmsMain->getRecord('new-Page-5'); $this->assertType('Page', $newPage); $this->assertEquals('5', $newPage->ParentID); - } -} \ No newline at end of file + 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']); + } + +}