Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUGFIX Moved 'rollback' logic back from CMSPageHistoryController to C…

…MSMain (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)
commit 69e819a4174b5f33dbfd337b25ff38c15528d45a 1 parent 39208d1
@chillu chillu authored
View
51 code/controllers/CMSMain.php
@@ -810,6 +810,57 @@ function unpublish($data, $form) {
}
/**
+ * @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
*/
function batchactions() {
View
58 code/controllers/CMSPageHistoryController.php
@@ -53,16 +53,6 @@ function compare($request) {
}
/**
- * @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.
*
@@ -308,54 +298,6 @@ function doShowVersion($data, $form) {
$versionID
));
}
-
- /**
- * 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
Please sign in to comment.
Something went wrong with that request. Please try again.