mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
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:
parent
b6e0c2358b
commit
820d6b92cd
@ -44,7 +44,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
'getversion',
|
'getversion',
|
||||||
'publishall',
|
'publishall',
|
||||||
'publishitems',
|
'publishitems',
|
||||||
'restorepage',
|
'restore',
|
||||||
'revert',
|
'revert',
|
||||||
'rollback',
|
'rollback',
|
||||||
'sidereport',
|
'sidereport',
|
||||||
@ -54,6 +54,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
'EditForm',
|
'EditForm',
|
||||||
'AddPageOptionsForm',
|
'AddPageOptionsForm',
|
||||||
'SiteTreeAsUL',
|
'SiteTreeAsUL',
|
||||||
|
'getshowdeletedsubtree'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,6 +170,21 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
return $this->getSiteTreeFor("SiteTree");
|
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
|
* 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');
|
$treeClass = $this->stat('tree_class');
|
||||||
|
|
||||||
if($id && is_numeric($id)) {
|
if($id && is_numeric($id)) {
|
||||||
|
// First, try getting a record from the stage site
|
||||||
$record = DataObject::get_one( $treeClass, "`$treeClass`.ID = $id");
|
$record = DataObject::get_one( $treeClass, "`$treeClass`.ID = $id");
|
||||||
|
|
||||||
|
// Then, try getting a record from the live site
|
||||||
if(!$record) {
|
if(!$record) {
|
||||||
// $record = Versioned::get_one_by_stage($treeClass, "Live", "`$treeClass`.ID = $id");
|
// $record = Versioned::get_one_by_stage($treeClass, "Live", "`$treeClass`.ID = $id");
|
||||||
Versioned::reading_stage('Live');
|
Versioned::reading_stage('Live');
|
||||||
@ -378,6 +396,11 @@ JS;
|
|||||||
if($record) Versioned::reading_stage(null);
|
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
|
// Don't open a page from a different locale
|
||||||
if($record && Translatable::is_enabled() && $record->Locale && $record->Locale != Translatable::current_locale()) {
|
if($record && Translatable::is_enabled() && $record->Locale && $record->Locale != Translatable::current_locale()) {
|
||||||
$record = null;
|
$record = null;
|
||||||
@ -1196,23 +1219,25 @@ JS;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore a previously deleted page.
|
* Restore a completely deleted page from the SiteTree_versions table.
|
||||||
* Internal action which shouldn't be executed through URL-handlers.
|
|
||||||
*/
|
*/
|
||||||
function restorepage() {
|
function restore() {
|
||||||
if($id = $this->urlParams['ID']) {
|
if(($id = $_REQUEST['ID']) && is_numeric($id)) {
|
||||||
$restoredPage = Versioned::get_latest_version("SiteTree", $id);
|
$restoredPage = Versioned::get_latest_version("SiteTree", $id);
|
||||||
$restoredPage->ID = $restoredPage->RecordID;
|
if($restoredPage) {
|
||||||
// if no record can be found on draft stage (meaning it has been "deleted from draft" before),
|
$restoredPage = $restoredPage->doRestoreToStage();
|
||||||
// create an empty record
|
|
||||||
if(!DB::query("SELECT ID FROM SiteTree WHERE ID = $restoredPage->ID")->value()) {
|
FormResponse::get_page($id);
|
||||||
DB::query("INSERT INTO SiteTree SET ID = $restoredPage->ID");
|
$title = Convert::raw2js($restoredPage->TreeTitle());
|
||||||
}
|
FormResponse::add("$('sitetree').setNodeTitle($id, '$title');");
|
||||||
$restoredPage->forceChange();
|
FormResponse::status_message(sprintf(_t('CMSMain.RESTORED',"Restored '%s' successfully",PR_MEDIUM,'Param %s is a title'),$title),'good');
|
||||||
$restoredPage->writeWithoutVersion();
|
return FormResponse::respond();
|
||||||
Debug::show($restoredPage);
|
|
||||||
} else {
|
} else {
|
||||||
echo _t('CMSMain.VISITRESTORE',"visit restorepage/(ID)",PR_LOW,'restorepage/(ID) should not be translated (is an URL)');
|
return new HTTPResponse("SiteTree #$id not found", 400);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return new HTTPResponse("Please pass an ID in the form content", 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 = $rootID ? $this->getRecord($rootID) : singleton($className);
|
||||||
$obj->markPartialTree(30, $this);
|
$obj->markPartialTree(30, $this, $childrenMethod);
|
||||||
if($p = $this->currentPage()) $obj->markToExpose($p);
|
if($p = $this->currentPage()) $obj->markToExpose($p);
|
||||||
|
|
||||||
// getChildrenAsUL is a flexible and complex way of traversing the tree
|
// getChildrenAsUL is a flexible and complex way of traversing the tree
|
||||||
@ -468,7 +477,7 @@ class LeftAndMain extends Controller {
|
|||||||
($child->TreeTitle()) .
|
($child->TreeTitle()) .
|
||||||
"</a>"
|
"</a>"
|
||||||
'
|
'
|
||||||
,$this, true);
|
,$this, true, $childrenMethod);
|
||||||
|
|
||||||
// Wrap the root if needs be.
|
// Wrap the root if needs be.
|
||||||
|
|
||||||
@ -486,9 +495,19 @@ class LeftAndMain extends Controller {
|
|||||||
return $siteTree;
|
return $siteTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a subtree underneath the request param 'ID'.
|
||||||
|
* If ID = 0, then get the whole tree.
|
||||||
|
*/
|
||||||
public function getsubtree() {
|
public function getsubtree() {
|
||||||
$results = $this->getSiteTreeFor($this->stat('tree_class'), $_REQUEST['ID']);
|
// Get the tree
|
||||||
return substr(trim($results), 4,-5);
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,6 +180,12 @@ ul.tree span.a a del, ul.tree span.a a.notinmenu del,
|
|||||||
#publication_key del {
|
#publication_key del {
|
||||||
color: red;
|
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,
|
ul.tree span.a span.modified,
|
||||||
#publication_key span.modified {
|
#publication_key span.modified {
|
||||||
color: green;
|
color: green;
|
||||||
@ -400,14 +406,14 @@ ul.tree span.untranslated a:visited {
|
|||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
#SortItems {
|
.checkboxAboveTree {
|
||||||
border-top: 1px solid #cccccc;
|
border-top: 1px solid #cccccc;
|
||||||
padding: 5px 0 0 0;
|
padding: 5px 0 0 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
clear: left;
|
clear: left;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
#SortItems input, #ShowChanged input {
|
.checkboxAboveTree input, #ShowChanged input {
|
||||||
float: left;
|
float: left;
|
||||||
margin: 0 3px 0 0;
|
margin: 0 3px 0 0;
|
||||||
}
|
}
|
||||||
|
@ -400,13 +400,13 @@ body.stillLoading select {
|
|||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
#left #TreeActions,
|
#left #TreeActions,
|
||||||
#left #SortItems {
|
#left .checkboxAboveTree {
|
||||||
background: #EEE;
|
background: #EEE;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
float: left;
|
float: left;
|
||||||
width: 95%;
|
width: 95%;
|
||||||
}
|
}
|
||||||
#left #SortItems {
|
#left .checkboxAboveTree {
|
||||||
border-bottom: 1px solid #CCC;
|
border-bottom: 1px solid #CCC;
|
||||||
}
|
}
|
||||||
#TreeTools label {
|
#TreeTools label {
|
||||||
|
@ -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
|
* Add Criteria Drop-down onchange action which allows more criteria to be shown
|
||||||
*/
|
*/
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<form class="actionparams" id="sortitems_options" style="display: none">
|
<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>
|
<p id="sortitems_message" style="margin: 0"><% _t('TOREORG','To reorganise your folders, drag them around as desired.') %></p>
|
||||||
</form>
|
</form>
|
||||||
<div id="SortItems">
|
<div class="checkboxAboveTree">
|
||||||
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag & drop reordering', PR_HIGH) %></label>
|
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag & drop reordering', PR_HIGH) %></label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -89,9 +89,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<% end_control %>
|
<% end_control %>
|
||||||
<div id="SortItems">
|
<div class="checkboxAboveTree">
|
||||||
|
<div>
|
||||||
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag & drop reordering', PR_HIGH) %></label>
|
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag & drop reordering', PR_HIGH) %></label>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<input type="checkbox" id="showdeletedpages" /> <label for="showdeletedpages"><% _t('SHOW_DELETED_PAGES','Show deleted pages', PR_HIGH) %></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<% if IsTranslatableEnabled %>
|
<% if IsTranslatableEnabled %>
|
||||||
<div id="LangSelector_holder">
|
<div id="LangSelector_holder">
|
||||||
Language: $LangSelector
|
Language: $LangSelector
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<p id="sortitems_message" style="margin: 0"><% _t('TOREORG','To reorganise your site, drag the pages around as desired.') %></p>
|
<p id="sortitems_message" style="margin: 0"><% _t('TOREORG','To reorganise your site, drag the pages around as desired.') %></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div id="SortItems">
|
<div class="checkboxAboveTree">
|
||||||
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag & drop reordering', PR_HIGH) %></label>
|
<input type="checkbox" id="sortitems" /> <label for="sortitems"><% _t('ENABLEDRAGGING','Allow drag & drop reordering', PR_HIGH) %></label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user