2009-05-14 23:51:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class representing back actions
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* CMSMain::register_batch_action('publishitems', new CMSBatchAction('doPublish',
|
2009-05-14 23:56:35 +02:00
|
|
|
* _t('CMSBatchActions.PUBLISHED_PAGES', 'published %d pages')));
|
2009-05-14 23:51:54 +02:00
|
|
|
* </code>
|
2009-05-14 23:56:35 +02:00
|
|
|
*
|
|
|
|
* @package cms
|
|
|
|
* @subpackage batchaction
|
2009-05-14 23:51:54 +02:00
|
|
|
*/
|
|
|
|
abstract class CMSBatchAction extends Object {
|
|
|
|
/**
|
|
|
|
* The the text to show in the dropdown for this action
|
|
|
|
*/
|
|
|
|
abstract function getActionTitle();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get text to be shown while the action is being processed, of the form
|
|
|
|
* "publishing pages".
|
|
|
|
*/
|
|
|
|
abstract function getDoingText();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run this action for the given set of pages.
|
|
|
|
* Return a set of status-updated JavaScript to return to the CMS.
|
|
|
|
*/
|
|
|
|
abstract function run(DataObjectSet $pages);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for processing batch actions.
|
|
|
|
* Returns a set of status-updating JavaScript to return to the CMS.
|
|
|
|
*
|
|
|
|
* @param $pages The DataObjectSet of SiteTree objects to perform this batch action
|
|
|
|
* on.
|
|
|
|
* @param $helperMethod The method to call on each of those objects.
|
|
|
|
* @para
|
|
|
|
*/
|
2009-10-16 00:44:08 +02:00
|
|
|
public function batchaction(DataObjectSet $pages, $helperMethod, $successMessage, $arguments = array()) {
|
2009-10-30 04:27:27 +01:00
|
|
|
$failures = 0;
|
|
|
|
|
2009-05-14 23:51:54 +02:00
|
|
|
foreach($pages as $page) {
|
2009-10-16 00:44:08 +02:00
|
|
|
|
2009-05-14 23:51:54 +02:00
|
|
|
// Perform the action
|
2009-10-30 04:27:27 +01:00
|
|
|
if (!call_user_func_array(array($page, $helperMethod), $arguments)) {
|
|
|
|
$failures++;
|
|
|
|
}
|
2009-05-14 23:51:54 +02:00
|
|
|
|
|
|
|
// Now make sure the tree title is appropriately updated
|
|
|
|
$publishedRecord = DataObject::get_by_id('SiteTree', $page->ID);
|
2009-08-02 23:57:26 +02:00
|
|
|
if ($publishedRecord) {
|
|
|
|
$JS_title = Convert::raw2js($publishedRecord->TreeTitle());
|
|
|
|
FormResponse::add("\$('sitetree').setNodeTitle($page->ID, '$JS_title');");
|
|
|
|
}
|
2009-05-14 23:51:54 +02:00
|
|
|
$page->destroy();
|
|
|
|
unset($page);
|
|
|
|
}
|
|
|
|
|
2009-10-30 01:55:37 +01:00
|
|
|
$message = sprintf($successMessage, $pages->Count()-$failures, $failures);
|
|
|
|
|
2009-05-14 23:51:54 +02:00
|
|
|
FormResponse::add('statusMessage("'.$message.'","good");');
|
|
|
|
|
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
|
|
|
|
2009-10-16 00:44:08 +02:00
|
|
|
// if your batchaction has parameters, return a fieldset here
|
|
|
|
function getParameterFields() {
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-14 23:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Publish items batch action.
|
2009-05-14 23:56:35 +02:00
|
|
|
*
|
|
|
|
* @package cms
|
|
|
|
* @subpackage batchaction
|
2009-05-14 23:51:54 +02:00
|
|
|
*/
|
|
|
|
class CMSBatchAction_Publish extends CMSBatchAction {
|
|
|
|
function getActionTitle() {
|
|
|
|
return _t('CMSBatchActions.PUBLISH_PAGES', 'Publish');
|
|
|
|
}
|
|
|
|
function getDoingText() {
|
|
|
|
return _t('CMSBatchActions.PUBLISHING_PAGES', 'Publishing pages');
|
|
|
|
}
|
|
|
|
|
|
|
|
function run(DataObjectSet $pages) {
|
|
|
|
return $this->batchaction($pages, 'doPublish',
|
2009-10-30 01:55:37 +01:00
|
|
|
_t('CMSBatchActions.PUBLISHED_PAGES', 'Published %d pages, %d failures')
|
2009-05-14 23:51:54 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete items batch action.
|
2009-05-14 23:56:35 +02:00
|
|
|
*
|
|
|
|
* @package cms
|
|
|
|
* @subpackage batchaction
|
2009-05-14 23:51:54 +02:00
|
|
|
*/
|
|
|
|
class CMSBatchAction_Delete extends CMSBatchAction {
|
|
|
|
function getActionTitle() {
|
2009-11-04 23:56:29 +01:00
|
|
|
return _t('CMSBatchActions.DELETE_DRAFT_PAGES', 'Delete from draft');
|
2009-05-14 23:51:54 +02:00
|
|
|
}
|
|
|
|
function getDoingText() {
|
2009-11-04 23:56:29 +01:00
|
|
|
return _t('CMSBatchActions.DELETING_DRAFT_PAGES', 'Deleting selected pages from draft');
|
2009-05-14 23:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function run(DataObjectSet $pages) {
|
|
|
|
foreach($pages as $page) {
|
|
|
|
$id = $page->ID;
|
|
|
|
|
|
|
|
// Perform the action
|
|
|
|
if($page->canDelete()) $page->delete();
|
|
|
|
|
|
|
|
// check to see if the record exists on the live site, if it doesn't remove the tree node
|
2009-05-21 07:11:14 +02:00
|
|
|
$liveRecord = Versioned::get_one_by_stage( 'SiteTree', 'Live', "\"SiteTree\".\"ID\"=$id");
|
2009-05-14 23:51:54 +02:00
|
|
|
if($liveRecord) {
|
|
|
|
$liveRecord->IsDeletedFromStage = true;
|
|
|
|
$title = Convert::raw2js($liveRecord->TreeTitle());
|
|
|
|
FormResponse::add("$('sitetree').setNodeTitle($id, '$title');");
|
|
|
|
FormResponse::add("$('Form_EditForm').reloadIfSetTo($id);");
|
|
|
|
} else {
|
|
|
|
FormResponse::add("var node = $('sitetree').getTreeNodeByIdx('$id');");
|
|
|
|
FormResponse::add("if(node && node.parentTreeNode) node.parentTreeNode.removeTreeNode(node);");
|
|
|
|
FormResponse::add("$('Form_EditForm').reloadIfSetTo($id);");
|
|
|
|
}
|
|
|
|
|
|
|
|
$page->destroy();
|
|
|
|
unset($page);
|
|
|
|
}
|
|
|
|
|
2009-11-04 23:56:29 +01:00
|
|
|
$message = sprintf(_t('CMSBatchActions.DELETED_DRAFT_PAGES', 'Deleted %d pages from the draft site'), $pages->Count());
|
2009-05-14 23:51:54 +02:00
|
|
|
FormResponse::add('statusMessage("'.$message.'","good");');
|
|
|
|
|
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete items batch action.
|
2009-05-14 23:56:35 +02:00
|
|
|
*
|
|
|
|
* @package cms
|
|
|
|
* @subpackage batchaction
|
2009-05-14 23:51:54 +02:00
|
|
|
*/
|
|
|
|
class CMSBatchAction_DeleteFromLive extends CMSBatchAction {
|
|
|
|
function getActionTitle() {
|
|
|
|
return _t('CMSBatchActions.DELETE_PAGES', 'Delete from published site');
|
|
|
|
}
|
|
|
|
function getDoingText() {
|
|
|
|
return _t('CMSBatchActions.DELETING_PAGES', 'Deleting selected pages from the published site');
|
|
|
|
}
|
|
|
|
|
|
|
|
function run(DataObjectSet $pages) {
|
2009-10-30 01:55:37 +01:00
|
|
|
$ids = $pages->column('ID');
|
|
|
|
$this->batchaction($pages, 'doUnpublish',
|
|
|
|
_t('CMSBatchActions.DELETED_PAGES', 'Deleted %d pages from the published site, %d failures')
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($ids as $pageID) {
|
|
|
|
$id = $pageID;
|
2009-05-14 23:51:54 +02:00
|
|
|
|
|
|
|
// check to see if the record exists on the live site, if it doesn't remove the tree node
|
2009-05-21 07:11:14 +02:00
|
|
|
$stageRecord = Versioned::get_one_by_stage( 'SiteTree', 'Stage', "\"SiteTree\".\"ID\"=$id");
|
2009-05-14 23:51:54 +02:00
|
|
|
if($stageRecord) {
|
|
|
|
$stageRecord->IsAddedToStage = true;
|
|
|
|
$title = Convert::raw2js($stageRecord->TreeTitle());
|
|
|
|
FormResponse::add("$('sitetree').setNodeTitle($id, '$title');");
|
|
|
|
FormResponse::add("$('Form_EditForm').reloadIfSetTo($id);");
|
|
|
|
} else {
|
|
|
|
FormResponse::add("var node = $('sitetree').getTreeNodeByIdx('$id');");
|
|
|
|
FormResponse::add("if(node && node.parentTreeNode) node.parentTreeNode.removeTreeNode(node);");
|
|
|
|
FormResponse::add("$('Form_EditForm').reloadIfSetTo($id);");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = sprintf(_t('CMSBatchActions.DELETED_PAGES', 'Deleted %d pages from the published site'), $pages->Count());
|
|
|
|
FormResponse::add('statusMessage("'.$message.'","good");');
|
|
|
|
|
|
|
|
return FormResponse::respond();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|