/** * Restore a completely deleted page from the SiteTree_versions table. */ function restore($data, $form) { if (($id = $_REQUEST['ID']) && is_numeric($id)) { $restoredPage = Versioned::get_latest_version("SiteTree", $id); if ($restoredPage) { $restoredPage = $restoredPage->doRestoreToStage(); FormResponse::get_page($id); $title = Convert::raw2js($restoredPage->TreeTitle()); FormResponse::add("\$('sitetree').setNodeTitle({$id}, '{$title}');"); FormResponse::status_message(sprintf(_t('CMSMain.RESTORED', "Restored '%s' successfully", PR_MEDIUM, 'Param %s is a title'), $title), 'good'); return FormResponse::respond(); } else { return new SS_HTTPResponse("SiteTree #{$id} not found", 400); } } else { return new SS_HTTPResponse("Please pass an ID in the form content", 400); } }
/** * Delete the current page from draft stage. * @see deletefromlive() */ public function delete($urlParams, $form) { $id = $_REQUEST['ID']; $record = DataObject::get_one("SiteTree", "SiteTree.ID = $id"); if($record && !$record->canDelete()) return Security::permissionFailure(); // save ID and delete record $recordID = $record->ID; $record->delete(); if(Director::is_ajax()) { // need a valid ID value even if the record doesn't have one in the database // (its still present in the live tables) $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "SiteTree_Live.ID = $recordID"); // if the page has never been published to live, we need to act the same way as in deletefromlive() if($liveRecord) { // the form is readonly now, so we need to refresh the representation FormResponse::get_page($recordID); return $this->tellBrowserAboutPublicationChange($liveRecord, sprintf(_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"),$record->Title)); } else { FormResponse::add($this->deleteTreeNodeJS($record)); FormResponse::status_message(sprintf(_t('CMSMain.REMOVEDPAGEFROMDRAFT',"Removed '%s' from the draft site"),$record->Title), 'good'); return FormResponse::respond(); } } else { Director::redirectBack(); } }
public function revert($urlParams, $form) { $id = $_REQUEST['ID']; Versioned::reading_stage('Live'); $obj = DataObject::get_by_id("SiteTree", $id); Versioned::reading_stage('Stage'); $obj->publish("Live", "Stage"); $title = Convert::raw2js($obj->Title); FormResponse::get_page($id); FormResponse::add("\$('sitetree').setNodeTitle({$id}, '{$title}');"); FormResponse::status_message(sprintf(_t('CMSMain.RESTORED', "Restored '%s' successfully", PR_MEDIUM, 'Param %s is a title'), $title), 'good'); return FormResponse::respond(); }
/** * Process a workflow action. * @param string $workflowClass The sub-class of WorkflowRequest that is expected. * @param string $actionName The action method to call on the given WorkflowRequest objec.t * @param int $id The ID# of the page. * @param string $comment The comment to attach. * @param string $successMessage The message to show on success. */ function workflowAction($workflowClass, $actionName, $id, $comment) { if (is_numeric($id)) { // For 2.3 and 2.4 compatibility $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; $page = DataObject::get_by_id("SiteTree", $id); if (!$page) { $page = Versioned::get_one_by_stage("SiteTree", "Live", "{$bt}SiteTree{$bt}.{$bt}ID{$bt} = {$id}"); } if (!$page) { return new HTTPResponse("Can't find Page #{$id}", 400); } } else { return new HTTPResponse("Bad ID", 400); } // If we are creating and approving a workflow in one step, then don't bother emailing $notify = !($actionName == 'action' && !$page->openWorkflowRequest($workflowClass)); if ($request = $page->openOrNewWorkflowRequest($workflowClass, $notify)) { $request->clearMembersEmailed(); if ($successMessage = $request->{$actionName}($comment, null, $notify)) { FormResponse::get_page($id); $title = Convert::raw2js($page->TreeTitle()); FormResponse::add("\$('sitetree').setNodeTitle({$id}, \"{$title}\");"); // gather members for status output if ($notify) { $peeps = $request->getMembersEmailed(); if ($peeps && $peeps->Count()) { $emails = ''; foreach ($peeps as $peep) { if ($peep->Email) { $emails .= $peep->Email . ', '; } } $emails = trim($emails, ', '); } else { $emails = 'no-one'; } } else { $emails = "no-one"; } if ($successMessage) { FormResponse::status_message(sprintf($successMessage, $emails), 'good'); return FormResponse::respond(); } else { return; } } } // Failure FormResponse::status_message(_t('SiteTreeCMSWorkflow.WORKFLOW_ACTION_FAILED', "There was an error when processing your workflow request."), 'bad'); return FormResponse::respond(); }