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) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@96821 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
59899c68cf
commit
ee2490fe68
@ -64,6 +64,46 @@ abstract class CMSBatchAction extends Object {
|
|||||||
|
|
||||||
return FormResponse::respond();
|
return FormResponse::respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
// if your batchaction has parameters, return a fieldset here
|
||||||
function getParameterFields() {
|
function getParameterFields() {
|
||||||
@ -90,6 +130,10 @@ class CMSBatchAction_Publish extends CMSBatchAction {
|
|||||||
_t('CMSBatchActions.PUBLISHED_PAGES', 'Published %d pages, %d failures')
|
_t('CMSBatchActions.PUBLISHED_PAGES', 'Published %d pages, %d failures')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applicablePages($ids) {
|
||||||
|
return $this->applicablePagesHelper($ids, 'canPublish', true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,6 +182,10 @@ class CMSBatchAction_Delete extends CMSBatchAction {
|
|||||||
|
|
||||||
return FormResponse::respond();
|
return FormResponse::respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applicablePages($ids) {
|
||||||
|
return $this->applicablePagesHelper($ids, 'canDelete', true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,6 +227,10 @@ class CMSBatchAction_DeleteFromLive extends CMSBatchAction {
|
|||||||
|
|
||||||
return FormResponse::respond();
|
return FormResponse::respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applicablePages($ids) {
|
||||||
|
return $this->applicablePagesHelper($ids, 'canDelete', false, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user