mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Calling doRestoreToStage() on orphans which don't have a stage record before unpublishing them in RemoveOrphanedPagesTask
MINOR Added "unselect all" and better permission checks to RemoveOrphanedPagesTask (from r78478) MINOR Fixed visibility of RemoveOrphanedPagesTask->getOrphanedPages() (from r78486) ENHANCEMENT Allow rebasing of orphans in a subfolder for RemoveOrphanedPagesTask (from r78494) MINOR set_time_limit for RemoveOrphanedPagesTask (from r78495) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@81471 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f88fb435e3
commit
f515ed7898
@ -52,6 +52,14 @@ in the other stage:<br />
|
|||||||
return $this->class;
|
return $this->class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
if(!Permission::check('ADMIN')) {
|
||||||
|
return Security::permissionFailure($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function index() {
|
function index() {
|
||||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
|
||||||
Requirements::customCSS('#OrphanIDs .middleColumn {width: auto;}');
|
Requirements::customCSS('#OrphanIDs .middleColumn {width: auto;}');
|
||||||
@ -110,15 +118,28 @@ in the other stage:<br />
|
|||||||
$fields->push(new LiteralField(
|
$fields->push(new LiteralField(
|
||||||
'SelectAllLiteral',
|
'SelectAllLiteral',
|
||||||
sprintf(
|
sprintf(
|
||||||
'<p><a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'checked\'); return false;">%s</a></p>',
|
'<p><a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'checked\'); return false;">%s</a> ',
|
||||||
_t('RemoveOrphanedPagesTask.SELECTALL', 'select all')
|
_t('RemoveOrphanedPagesTask.SELECTALL', 'select all')
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
$fields->push(new LiteralField(
|
||||||
|
'UnselectAllLiteral',
|
||||||
|
sprintf(
|
||||||
|
'<a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'\'); return false;">%s</a></p>',
|
||||||
|
_t('RemoveOrphanedPagesTask.UNSELECTALL', 'unselect all')
|
||||||
|
)
|
||||||
|
));
|
||||||
$fields->push(new OptionSetField(
|
$fields->push(new OptionSetField(
|
||||||
'OrphanOperation',
|
'OrphanOperation',
|
||||||
_t('RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'),
|
_t('RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'),
|
||||||
array(
|
array(
|
||||||
'rebase' => _t('RemoveOrphanedPagesTask.OPERATION_REBASE', 'Rebase selected to tree root and unpublish'),
|
'rebase' => _t(
|
||||||
|
'RemoveOrphanedPagesTask.OPERATION_REBASE',
|
||||||
|
sprintf(
|
||||||
|
'Rebase selected to a new holder page "%s" and unpublish. None of these pages will show up for website visitors.',
|
||||||
|
$this->rebaseHolderTitle()
|
||||||
|
)
|
||||||
|
),
|
||||||
'remove' => _t('RemoveOrphanedPagesTask.OPERATION_REMOVE', 'Remove selected from all stages (WARNING: Will destroy all selected pages from both stage and live)'),
|
'remove' => _t('RemoveOrphanedPagesTask.OPERATION_REMOVE', 'Remove selected from all stages (WARNING: Will destroy all selected pages from both stage and live)'),
|
||||||
),
|
),
|
||||||
'rebase'
|
'rebase'
|
||||||
@ -163,6 +184,8 @@ in the other stage:<br />
|
|||||||
}
|
}
|
||||||
|
|
||||||
function doSubmit($data, $form) {
|
function doSubmit($data, $form) {
|
||||||
|
set_time_limit(60*10); // 10 minutes
|
||||||
|
|
||||||
if(!isset($data['OrphanIDs']) || !isset($data['OrphanOperation'])) return false;
|
if(!isset($data['OrphanIDs']) || !isset($data['OrphanOperation'])) return false;
|
||||||
|
|
||||||
switch($data['OrphanOperation']) {
|
switch($data['OrphanOperation']) {
|
||||||
@ -229,7 +252,18 @@ in the other stage:<br />
|
|||||||
return $removedOrphans;
|
return $removedOrphans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function rebaseHolderTitle() {
|
||||||
|
return sprintf('Rebased Orphans (%s)', date('d/m/Y g:ia', time()));
|
||||||
|
}
|
||||||
|
|
||||||
protected function rebaseOrphans($orphanIDs) {
|
protected function rebaseOrphans($orphanIDs) {
|
||||||
|
$holder = new SiteTree();
|
||||||
|
$holder->ShowInMenus = 0;
|
||||||
|
$holder->ShowInSearch = 0;
|
||||||
|
$holder->ParentID = 0;
|
||||||
|
$holder->Title = $this->rebaseHolderTitle();
|
||||||
|
$holder->write();
|
||||||
|
|
||||||
$removedOrphans = array();
|
$removedOrphans = array();
|
||||||
foreach($orphanIDs as $id) {
|
foreach($orphanIDs as $id) {
|
||||||
$stageRecord = Versioned::get_one_by_stage(
|
$stageRecord = Versioned::get_one_by_stage(
|
||||||
@ -242,11 +276,13 @@ in the other stage:<br />
|
|||||||
);
|
);
|
||||||
if($stageRecord) {
|
if($stageRecord) {
|
||||||
$removedOrphans[$stageRecord->ID] = sprintf('Rebased %s (#%d)', $stageRecord->Title, $stageRecord->ID);
|
$removedOrphans[$stageRecord->ID] = sprintf('Rebased %s (#%d)', $stageRecord->Title, $stageRecord->ID);
|
||||||
$stageRecord->ParentID = 0;
|
$stageRecord->ParentID = $holder->ID;
|
||||||
|
$stageRecord->ShowInMenus = 0;
|
||||||
|
$stageRecord->ShowInSearch = 0;
|
||||||
$stageRecord->write();
|
$stageRecord->write();
|
||||||
$stageRecord->doUnpublish();
|
$stageRecord->doUnpublish();
|
||||||
$stageRecord->destroy();
|
$stageRecord->destroy();
|
||||||
unset($stageRecord);
|
//unset($stageRecord);
|
||||||
}
|
}
|
||||||
$liveRecord = Versioned::get_one_by_stage(
|
$liveRecord = Versioned::get_one_by_stage(
|
||||||
$this->orphanedSearchClass,
|
$this->orphanedSearchClass,
|
||||||
@ -258,12 +294,18 @@ in the other stage:<br />
|
|||||||
);
|
);
|
||||||
if($liveRecord) {
|
if($liveRecord) {
|
||||||
$removedOrphans[$liveRecord->ID] = sprintf('Rebased %s (#%d)', $liveRecord->Title, $liveRecord->ID);
|
$removedOrphans[$liveRecord->ID] = sprintf('Rebased %s (#%d)', $liveRecord->Title, $liveRecord->ID);
|
||||||
$liveRecord->ParentID = 0;
|
$liveRecord->ParentID = $holder->ID;
|
||||||
|
$liveRecord->ShowInMenus = 0;
|
||||||
|
$liveRecord->ShowInSearch = 0;
|
||||||
$liveRecord->write();
|
$liveRecord->write();
|
||||||
|
if(!$stageRecord) $liveRecord->doRestoreToStage();
|
||||||
$liveRecord->doUnpublish();
|
$liveRecord->doUnpublish();
|
||||||
$liveRecord->destroy();
|
$liveRecord->destroy();
|
||||||
unset($liveRecord);
|
unset($liveRecord);
|
||||||
}
|
}
|
||||||
|
if($stageRecord) {
|
||||||
|
unset($stageRecord);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $removedOrphans;
|
return $removedOrphans;
|
||||||
@ -279,7 +321,7 @@ in the other stage:<br />
|
|||||||
* @param int|array $limit
|
* @param int|array $limit
|
||||||
* @return DataObjectSet
|
* @return DataObjectSet
|
||||||
*/
|
*/
|
||||||
protected function getOrphanedPages($class = 'SiteTree', $filter = '', $sort = null, $join = null, $limit = null) {
|
function getOrphanedPages($class = 'SiteTree', $filter = '', $sort = null, $join = null, $limit = null) {
|
||||||
$filter .= ($filter) ? ' AND ' : '';
|
$filter .= ($filter) ? ' AND ' : '';
|
||||||
$filter .= sprintf('`%s`.`ParentID` != 0 AND `Parents`.`ID` IS NULL', $class);
|
$filter .= sprintf('`%s`.`ParentID` != 0 AND `Parents`.`ID` IS NULL', $class);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user