getPOSTRecordList($request); if($recordList && count($recordList)) { $records = $this->gridField->List->byIDs($recordList); foreach($records as $record) { if(!$this->doPublish($record)) unset($recordList[$record->ID]); } } return $this->completeAction($recordList, 'Published {count} items'); } public function unpublish(SS_HTTPRequest $request) { $recordList = $this->getPOSTRecordList($request); if($recordList && count($recordList)) { $records = $this->gridField->List->byIDs($recordList); foreach($records as $record) { if(!$this->doUnpublish($record)) unset($recordList[$record->ID]); } } return $this->completeAction($recordList, 'Unpublished {count} items'); } 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; } }