mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
API CHANGE: Added applicablePagesHelper to CMSBatchAction to ease the process of creating new applicable page methods.
ENHANCEMENT: Added applicable pages checks to delete from live, delete from draft, and publish (from r94775) (from r96821) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@102680 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
184289b3d9
commit
feeb1e40fa
@ -72,6 +72,46 @@ abstract class CMSBatchAction extends Object {
|
||||
return Convert::raw2json($status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper method for applicablePages() methods. Acts as a skeleton implementation.
|
||||
*
|
||||
* @param $ids The IDs passed to applicablePages
|
||||
* @param $methodName The canXXX() method to call on each page to check if the action is applicable
|
||||
* @param $checkStagePages Set to true if you want to check stage pages
|
||||
* @param $checkLivePages Set to true if you want to check live pages (e.g, for deleted-from-draft)
|
||||
*/
|
||||
function applicablePagesHelper($ids, $methodName, $checkStagePages = true, $checkLivePages = true) {
|
||||
if(!is_array($ids)) user_error("Bad \$ids passed to applicablePagesHelper()", E_USER_WARNING);
|
||||
if(!is_string($methodName)) user_error("Bad \$methodName passed to applicablePagesHelper()", E_USER_WARNING);
|
||||
|
||||
$applicableIDs = array();
|
||||
|
||||
$SQL_ids = implode(', ', array_filter($ids, 'is_numeric'));
|
||||
$draftPages = DataObject::get("SiteTree", "\"SiteTree\".\"ID\" IN ($SQL_ids)");
|
||||
|
||||
$onlyOnLive = array_fill_keys($ids, true);
|
||||
if($checkStagePages) {
|
||||
foreach($draftPages as $page) {
|
||||
unset($onlyOnLive[$page->ID]);
|
||||
if($page->$methodName()) $applicableIDs[] = $page->ID;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the pages that only exist on live (deleted from stage)
|
||||
if($checkLivePages && $onlyOnLive) {
|
||||
$SQL_ids = implode(', ', array_keys($onlyOnLive));
|
||||
$livePages = Versioned::get_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" IN ($SQL_ids)");
|
||||
|
||||
if($livePages) foreach($livePages as $page) {
|
||||
if($page->$methodName()) $applicableIDs[] = $page->ID;
|
||||
}
|
||||
}
|
||||
|
||||
return $applicableIDs;
|
||||
}
|
||||
|
||||
// if your batchaction has parameters, return a fieldset here
|
||||
function getParameterFields() {
|
||||
return false;
|
||||
@ -94,6 +134,10 @@ class CMSBatchAction_Publish extends CMSBatchAction {
|
||||
_t('CMSBatchActions.PUBLISHED_PAGES', 'Published %d pages, %d failures')
|
||||
);
|
||||
}
|
||||
|
||||
function applicablePages($ids) {
|
||||
return $this->applicablePagesHelper($ids, 'canPublish', true, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,6 +199,10 @@ class CMSBatchAction_Delete extends CMSBatchAction {
|
||||
|
||||
return Convert::raw2json($status);
|
||||
}
|
||||
|
||||
function applicablePages($ids) {
|
||||
return $this->applicablePagesHelper($ids, 'canDelete', true, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,4 +243,8 @@ class CMSBatchAction_DeleteFromLive extends CMSBatchAction {
|
||||
|
||||
return Convert::raw2json($status);
|
||||
}
|
||||
|
||||
function applicablePages($ids) {
|
||||
return $this->applicablePagesHelper($ids, 'canDelete', false, true);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user