2013-07-11 09:08:07 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Milkyway Multimedia
|
|
|
|
* VersionedGridFieldBulkManager_Request.php
|
|
|
|
*
|
|
|
|
* Adding extra bulk edit actions specifically for versioned objects,
|
|
|
|
* just like the Multi-selection action dropdown in the Pages section
|
|
|
|
*
|
2013-07-11 09:10:53 +02:00
|
|
|
* @todo Extend the bulk edit action to allow publish and unpublish records from that interface
|
|
|
|
*
|
2013-07-11 09:08:07 +02:00
|
|
|
* @package GridFieldBulkEditingTools
|
|
|
|
* @author Mellisa Hankins
|
|
|
|
* @author colymba
|
|
|
|
*/
|
|
|
|
|
|
|
|
class VersionedGridFieldBulkManager_Request extends GridFieldBulkManager_Request {
|
|
|
|
private static $allowed_actions = array(
|
|
|
|
'edit',
|
|
|
|
'update',
|
|
|
|
'unlink',
|
|
|
|
'delete',
|
|
|
|
'publish',
|
|
|
|
'unpublish',
|
|
|
|
);
|
|
|
|
|
|
|
|
public function publish(SS_HTTPRequest $request) {
|
|
|
|
$recordList = $this->getPOSTRecordList($request);
|
|
|
|
|
2013-07-11 09:31:16 +02:00
|
|
|
if($recordList && count($recordList)) {
|
|
|
|
$records = $this->gridField->List->byIDs($recordList);
|
|
|
|
|
|
|
|
foreach($records as $record) {
|
|
|
|
if(!$this->doPublish($record))
|
|
|
|
unset($recordList[$record->ID]);
|
|
|
|
}
|
2013-07-11 09:08:07 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 10:08:35 +02:00
|
|
|
return $this->completeAction($recordList, 'Published {count} items');
|
2013-07-11 09:08:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function unpublish(SS_HTTPRequest $request) {
|
|
|
|
$recordList = $this->getPOSTRecordList($request);
|
|
|
|
|
2013-07-11 09:31:16 +02:00
|
|
|
if($recordList && count($recordList)) {
|
|
|
|
$records = $this->gridField->List->byIDs($recordList);
|
|
|
|
|
|
|
|
foreach($records as $record) {
|
|
|
|
if(!$this->doUnpublish($record))
|
|
|
|
unset($recordList[$record->ID]);
|
|
|
|
}
|
2013-07-11 09:08:07 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 10:08:35 +02:00
|
|
|
return $this->completeAction($recordList, 'Unpublished {count} items');
|
2013-07-11 09:08:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function doPublish($record) {
|
|
|
|
if(!$record || !$record->hasExtension('Versioned') || ($record->hasMethod('canPublish') && !$record->canPublish())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($record->hasMethod('doPublish'))
|
|
|
|
$record->doPublish();
|
|
|
|
else
|
|
|
|
$record->publish("Stage", "Live");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function doUnpublish($record) {
|
|
|
|
if(!$record || !$record->hasExtension('Versioned') || ($record->hasMethod('canDeleteFromLive') && !$record->canDeleteFromLive())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($record->hasMethod('doPublish'))
|
|
|
|
$record->doUnpublish();
|
|
|
|
else {
|
|
|
|
$origStage = Versioned::current_stage();
|
|
|
|
Versioned::reading_stage('Live');
|
|
|
|
|
|
|
|
// This way our ID won't be unset
|
|
|
|
$clone = clone $record;
|
|
|
|
$clone->delete();
|
|
|
|
|
|
|
|
Versioned::reading_stage($origStage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|