ENHANCEMENT: Added 'show deleted pages' function to CMS, with a restore page option.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@75737 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-04-30 05:39:12 +00:00
parent b6e0c2358b
commit 820d6b92cd
8 changed files with 121 additions and 28 deletions

View File

@ -44,7 +44,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'getversion',
'publishall',
'publishitems',
'restorepage',
'restore',
'revert',
'rollback',
'sidereport',
@ -54,6 +54,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'EditForm',
'AddPageOptionsForm',
'SiteTreeAsUL',
'getshowdeletedsubtree'
);
/**
@ -169,6 +170,21 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
return $this->getSiteTreeFor("SiteTree");
}
/**
* Get a subtree underneath the request param 'ID', of the tree that includes deleted pages.
* If ID = 0, then get the whole tree.
*/
public function getshowdeletedsubtree() {
// Get the tree
$tree = $this->getSiteTreeFor($this->stat('tree_class'), $_REQUEST['ID'], "AllHistoricalChildren");
// Trim off the outer tag
$tree = ereg_replace('^[ \t\r\n]*<ul[^>]*>','', $tree);
$tree = ereg_replace('</ul[^>]*>[ \t\r\n]*$','', $tree);
return $tree;
}
/**
* Returns the SiteTree columns that can be filtered using the the Site Tree Search button as a DataObjectSet
*/
@ -368,8 +384,10 @@ JS;
$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");
// Then, try getting a record from the live site
if(!$record) {
// $record = Versioned::get_one_by_stage($treeClass, "Live", "`$treeClass`.ID = $id");
Versioned::reading_stage('Live');
@ -377,6 +395,11 @@ JS;
$record = DataObject::get_one( $treeClass, "`$treeClass`.ID = $id");
if($record) Versioned::reading_stage(null);
}
// Then, try getting a deleted record
if(!$record) {
$record = Versioned::get_latest_version($treeClass, $id);
}
// Don't open a page from a different locale
if($record && Translatable::is_enabled() && $record->Locale && $record->Locale != Translatable::current_locale()) {
@ -1196,23 +1219,25 @@ JS;
}
/**
* Restore a previously deleted page.
* Internal action which shouldn't be executed through URL-handlers.
* Restore a completely deleted page from the SiteTree_versions table.
*/
function restorepage() {
if($id = $this->urlParams['ID']) {
function restore() {
if(($id = $_REQUEST['ID']) && is_numeric($id)) {
$restoredPage = Versioned::get_latest_version("SiteTree", $id);
$restoredPage->ID = $restoredPage->RecordID;
// if no record can be found on draft stage (meaning it has been "deleted from draft" before),
// create an empty record
if(!DB::query("SELECT ID FROM SiteTree WHERE ID = $restoredPage->ID")->value()) {
DB::query("INSERT INTO SiteTree SET ID = $restoredPage->ID");
if($restoredPage) {
$restoredPage = $restoredPage->doRestoreToStage();
FormResponse::get_page($id);
$title = Convert::raw2js($restoredPage->TreeTitle());
FormResponse::add("$('sitetree').setNodeTitle($id, '$title');");
FormResponse::status_message(sprintf(_t('CMSMain.RESTORED',"Restored '%s' successfully",PR_MEDIUM,'Param %s is a title'),$title),'good');
return FormResponse::respond();
} else {
return new HTTPResponse("SiteTree #$id not found", 400);
}
$restoredPage->forceChange();
$restoredPage->writeWithoutVersion();
Debug::show($restoredPage);
} else {
echo _t('CMSMain.VISITRESTORE',"visit restorepage/(ID)",PR_LOW,'restorepage/(ID) should not be translated (is an URL)');
} else {
return new HTTPResponse("Please pass an ID in the form content", 400);
}
}

View File

@ -456,9 +456,18 @@ class LeftAndMain extends Controller {
}
}
function getSiteTreeFor($className, $rootID = null) {
/**
* Get a site tree displaying the nodes under the given objects
* @param $className The class of the root object
* @param $rootID The ID of the root object. If this is null then a complete tree will be
* shown
* @param $childrenMethod The method to call to get the children of the tree. For example,
* Children, AllChildrenIncludingDeleted, or AllHistoricalChildren
*/
function getSiteTreeFor($className, $rootID = null,
$childrenMethod = "AllChildrenIncludingDeleted") {
$obj = $rootID ? $this->getRecord($rootID) : singleton($className);
$obj->markPartialTree(30, $this);
$obj->markPartialTree(30, $this, $childrenMethod);
if($p = $this->currentPage()) $obj->markToExpose($p);
// getChildrenAsUL is a flexible and complex way of traversing the tree
@ -468,7 +477,7 @@ class LeftAndMain extends Controller {
($child->TreeTitle()) .
"</a>"
'
,$this, true);
,$this, true, $childrenMethod);
// Wrap the root if needs be.
@ -486,9 +495,19 @@ class LeftAndMain extends Controller {
return $siteTree;
}
/**
* Get a subtree underneath the request param 'ID'.
* If ID = 0, then get the whole tree.
*/
public function getsubtree() {
$results = $this->getSiteTreeFor($this->stat('tree_class'), $_REQUEST['ID']);
return substr(trim($results), 4,-5);
// Get the tree
$tree = $this->getSiteTreeFor($this->stat('tree_class'), $_REQUEST['ID']);
// Trim off the outer tag
$tree = ereg_replace('^[ \t\r\n]*<ul[^>]*>','', $tree);
$tree = ereg_replace('</ul[^>]*>[ \t\r\n]*$','', $tree);
return $tree;
}
/**

View File

@ -180,6 +180,12 @@ ul.tree span.a a del, ul.tree span.a a.notinmenu del,
#publication_key del {
color: red;
}
/* Deleted on stage & live (when show deleted pages is active) */
ul.tree span.a a del, ul.tree span.a a.notinmenu del.deletedOnLive,
#publication_key del.deletedOnLive {
color: #700;
}
ul.tree span.a span.modified,
#publication_key span.modified {
color: green;
@ -400,14 +406,14 @@ ul.tree span.untranslated a:visited {
font-style: italic;
}
#SortItems {
.checkboxAboveTree {
border-top: 1px solid #cccccc;
padding: 5px 0 0 0;
overflow: hidden;
clear: left;
width: 100%;
}
#SortItems input, #ShowChanged input {
.checkboxAboveTree input, #ShowChanged input {
float: left;
margin: 0 3px 0 0;
}

View File

@ -400,13 +400,13 @@ body.stillLoading select {
width: auto;
}
#left #TreeActions,
#left #SortItems {
#left .checkboxAboveTree {
background: #EEE;
padding: 5px;
float: left;
width: 95%;
}
#left #SortItems {
#left .checkboxAboveTree {
border-bottom: 1px solid #CCC;
}
#TreeTools label {

View File

@ -118,6 +118,43 @@ searchclass.prototype = {
}
}
/**
* Show deleted pages checkbox
*/
ShowDeletedPagesAction = Class.create();
ShowDeletedPagesAction.applyTo('#showdeletedpages');
ShowDeletedPagesAction.prototype = {
initialize: function () {
},
onclick : function() {
if(this.checked) {
SiteTreeHandlers.loadTree_url = SiteTreeHandlers.controller_url + '/getshowdeletedsubtree';
} else {
SiteTreeHandlers.loadTree_url = SiteTreeHandlers.controller_url + '/getsubtree';
}
// We can't update the tree while it's draggable; it gets b0rked.
var __makeDraggableAfterUpdate = false;
if($('sitetree').isDraggable) {
$('sitetree').stopBeingDraggable();
__makeDraggableAfterUpdate = true;
}
var request = new Ajax.Request(SiteTreeHandlers.loadTree_url + '?ID=0&ajax=1', {
onSuccess: function(response) {
$('sitetree').innerHTML = response.responseText;
SiteTree.applyTo($('sitetree'));
if(__makeDraggableAfterUpdate) $('sitetree').makeDraggable();
},
onFailure: function(response) {
errorMessage('Could not update tree', response);
}
});
}
}
/**
* Add Criteria Drop-down onchange action which allows more criteria to be shown
*/

View File

@ -23,7 +23,7 @@
<form class="actionparams" id="sortitems_options" style="display: none">
<p id="sortitems_message" style="margin: 0"><% _t('TOREORG','To reorganise your folders, drag them around as desired.') %></p>
</form>
<div id="SortItems">
<div class="checkboxAboveTree">
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag &amp; drop reordering', PR_HIGH) %></label>
</div>

View File

@ -89,9 +89,15 @@
</div>
</form>
<% end_control %>
<div id="SortItems">
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag &amp; drop reordering', PR_HIGH) %></label>
<div class="checkboxAboveTree">
<div>
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag &amp; drop reordering', PR_HIGH) %></label>
</div>
<div>
<input type="checkbox" id="showdeletedpages" /> <label for="showdeletedpages"><% _t('SHOW_DELETED_PAGES','Show deleted pages', PR_HIGH) %></label>
</div>
</div>
<% if IsTranslatableEnabled %>
<div id="LangSelector_holder">
Language: $LangSelector

View File

@ -22,7 +22,7 @@
<p id="sortitems_message" style="margin: 0"><% _t('TOREORG','To reorganise your site, drag the pages around as desired.') %></p>
</form>
<div id="SortItems">
<div class="checkboxAboveTree">
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag &amp; drop reordering', PR_HIGH) %></label>
</div>