BUGFIX Moved 'rollback' logic back from CMSPageHistoryController to CMSMain (used in edit mode as well), removed unnecessary performRollback(), and introduced PJAX response handling to ensure the edit view is loaded correctly regardless of context (edit or history mode) (fixes #7108)

This commit is contained in:
Ingo Schommer 2012-04-10 14:09:30 +02:00
parent 39208d15e0
commit 69e819a417
2 changed files with 51 additions and 58 deletions

View File

@ -809,6 +809,57 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
return $this->getResponseNegotiator()->respond($this->request);
}
/**
* @return array
*/
function rollback() {
return $this->doRollback(array(
'ID' => $this->currentPageID(),
'Version' => $this->request->param('VersionID')
), null);
}
/**
* Rolls a site back to a given version ID
*
* @param array
* @param Form
*
* @return html
*/
function doRollback($data, $form) {
$this->extend('onBeforeRollback', $data['ID']);
$id = (isset($data['ID'])) ? (int) $data['ID'] : null;
$version = (isset($data['Version'])) ? (int) $data['Version'] : null;
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
if($record && !$record->canEdit()) return Security::permissionFailure($this);
if($version) {
$record->doRollbackTo($version);
$message = sprintf(
_t('CMSMain.ROLLEDBACKVERSION',"Rolled back to version #%d. New version number is #%d"),
$data['Version'],
$record->Version
);
} else {
$record->doRollbackTo('Live');
$message = sprintf(
_t('CMSMain.ROLLEDBACKPUB',"Rolled back to published version. New version number is #%d"),
$record->Version
);
}
$this->response->addHeader('X-Status', $message);
// Can be used in different contexts: In normal page edit view, in which case the redirect won't have any effect.
// Or in history view, in which case a revert causes the CMS to re-load the edit view.
$url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID);
$this->response->addHeader('X-ControllerURL', $url);
return $this->getResponseNegotiator()->respond($this->request);
}
/**
* Batch Actions Handler
*/

View File

@ -52,16 +52,6 @@ class CMSPageHistoryController extends CMSMain {
return $content;
}
/**
* @return array
*/
function rollback() {
return $this->doRollback(array(
'ID' => $this->currentPageID(),
'Version' => $this->request->param('VersionID')
), null);
}
/**
* Returns the read only version of the edit form. Detaches all {@link FormAction}
* instances attached since only action relates to revert.
@ -309,54 +299,6 @@ class CMSPageHistoryController extends CMSMain {
));
}
/**
* Rolls a site back to a given version ID
*
* @param array
* @param Form
*
* @return html
*/
function doRollback($data, $form) {
$this->extend('onBeforeRollback', $data['ID']);
$id = (isset($data['ID'])) ? (int) $data['ID'] : null;
$version = (isset($data['Version'])) ? (int) $data['Version'] : null;
if(isset($data['Version']) && (bool)$data['Version']) {
$record = $this->performRollback($data['ID'], $data['Version']);
$message = sprintf(
_t('CMSMain.ROLLEDBACKVERSION',"Rolled back to version #%d. New version number is #%d"),
$data['Version'],
$record->Version
);
} else {
$record = $this->performRollback($data['ID'], "Live");
$message = sprintf(
_t('CMSMain.ROLLEDBACKPUB',"Rolled back to published version. New version number is #%d"),
$record->Version
);
}
return $this->redirect(Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID));
}
/**
* Performs a rollback of the a given
*
* @param int $id record ID
* @param int $version version ID to rollback to
*/
function performRollback($id, $version) {
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
if($record && !$record->canEdit()) return Security::permissionFailure($this);
$record->doRollbackTo($version);
return $record;
}
/**
* @return Form
*/