Skip to content
This repository
Browse code

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)
  • Loading branch information...
commit 69e819a4174b5f33dbfd337b25ff38c15528d45a 1 parent 39208d1
Ingo Schommer authored April 10, 2012
51  code/controllers/CMSMain.php
@@ -810,6 +810,57 @@ function unpublish($data, $form) {
810 810
 	}
811 811
 
812 812
 	/**
  813
+	 * @return array
  814
+	 */
  815
+	function rollback() {
  816
+		return $this->doRollback(array(
  817
+			'ID' => $this->currentPageID(),
  818
+			'Version' => $this->request->param('VersionID')
  819
+		), null);
  820
+	}
  821
+
  822
+	/**
  823
+	 * Rolls a site back to a given version ID
  824
+	 *
  825
+	 * @param array
  826
+	 * @param Form
  827
+	 *
  828
+	 * @return html
  829
+	 */
  830
+	function doRollback($data, $form) {
  831
+		$this->extend('onBeforeRollback', $data['ID']);
  832
+		
  833
+		$id = (isset($data['ID'])) ? (int) $data['ID'] : null;
  834
+		$version = (isset($data['Version'])) ? (int) $data['Version'] : null;
  835
+
  836
+		$record = DataObject::get_by_id($this->stat('tree_class'), $id);
  837
+		if($record && !$record->canEdit()) return Security::permissionFailure($this);
  838
+		
  839
+		if($version) {
  840
+			$record->doRollbackTo($version);
  841
+			$message = sprintf(
  842
+				_t('CMSMain.ROLLEDBACKVERSION',"Rolled back to version #%d.  New version number is #%d"),
  843
+				$data['Version'],
  844
+				$record->Version
  845
+			);
  846
+		} else {
  847
+			$record->doRollbackTo('Live');
  848
+			$message = sprintf(
  849
+				_t('CMSMain.ROLLEDBACKPUB',"Rolled back to published version. New version number is #%d"),
  850
+				$record->Version
  851
+			);
  852
+		}
  853
+
  854
+		$this->response->addHeader('X-Status', $message);
  855
+		
  856
+		// Can be used in different contexts: In normal page edit view, in which case the redirect won't have any effect.
  857
+		// Or in history view, in which case a revert causes the CMS to re-load the edit view.
  858
+		$url = Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID);
  859
+		$this->response->addHeader('X-ControllerURL', $url);
  860
+		return $this->getResponseNegotiator()->respond($this->request);
  861
+	}
  862
+
  863
+	/**
813 864
 	 * Batch Actions Handler
814 865
 	 */
815 866
 	function batchactions() {
58  code/controllers/CMSPageHistoryController.php
@@ -53,16 +53,6 @@ function compare($request) {
53 53
 	}
54 54
 	
55 55
 	/**
56  
-	 * @return array
57  
-	 */
58  
-	function rollback() {
59  
-		return $this->doRollback(array(
60  
-			'ID' => $this->currentPageID(),
61  
-			'Version' => $this->request->param('VersionID')
62  
-		), null);
63  
-	}
64  
-
65  
-	/**
66 56
 	 * Returns the read only version of the edit form. Detaches all {@link FormAction} 
67 57
 	 * instances attached since only action relates to revert.
68 58
 	 *
@@ -308,54 +298,6 @@ function doShowVersion($data, $form) {
308 298
 			$versionID
309 299
 		));
310 300
 	}
311  
-	
312  
-	/**
313  
-	 * Rolls a site back to a given version ID
314  
-	 *
315  
-	 * @param array
316  
-	 * @param Form
317  
-	 *
318  
-	 * @return html
319  
-	 */
320  
-	function doRollback($data, $form) {
321  
-		$this->extend('onBeforeRollback', $data['ID']);
322  
-		
323  
-		$id = (isset($data['ID'])) ? (int) $data['ID'] : null;
324  
-		$version = (isset($data['Version'])) ? (int) $data['Version'] : null;
325  
-		
326  
-		if(isset($data['Version']) && (bool)$data['Version']) {
327  
-			$record = $this->performRollback($data['ID'], $data['Version']);
328  
-			$message = sprintf(
329  
-			_t('CMSMain.ROLLEDBACKVERSION',"Rolled back to version #%d.  New version number is #%d"),
330  
-			$data['Version'],
331  
-			$record->Version
332  
-		);
333  
-		} else {
334  
-			$record = $this->performRollback($data['ID'], "Live");
335  
-			$message = sprintf(
336  
-				_t('CMSMain.ROLLEDBACKPUB',"Rolled back to published version. New version number is #%d"),
337  
-				$record->Version
338  
-			);
339  
-		}
340  
-
341  
-		return $this->redirect(Controller::join_links(singleton('CMSPageEditController')->Link('show'), $record->ID));
342  
-	}
343  
-	
344  
-	/**
345  
-	 * Performs a rollback of the a given 
346  
-	 *
347  
-	 * @param int $id record ID
348  
-	 * @param int $version version ID to rollback to
349  
-	 */
350  
-	function performRollback($id, $version) {
351  
-		$record = DataObject::get_by_id($this->stat('tree_class'), $id);
352  
-		
353  
-		if($record && !$record->canEdit()) return Security::permissionFailure($this);
354  
-		
355  
-		$record->doRollbackTo($version);
356  
-		
357  
-		return $record;
358  
-	}
359 301
 
360 302
 	/**
361 303
 	 * @return Form

0 notes on commit 69e819a

Please sign in to comment.
Something went wrong with that request. Please try again.