/** * This returns the workflow requests outstanding for this user. * It does one query against draft for change requests, and another * request against live for the deletion requests (which are not in draft * any more), and merges the result sets together. */ function sourceRecords($params) { increase_time_limit_to(120); $currentStage = Versioned::current_stage(); $changes = WorkflowTwoStepRequest::get_by_author('WorkflowPublicationRequest', Member::currentUser(), array('AwaitingApproval')); if ($changes) { foreach ($changes as $change) { $change->RequestType = "Publish"; } } Versioned::reading_stage(Versioned::get_live_stage()); $deletions = WorkflowTwoStepRequest::get_by_author('WorkflowDeletionRequest', Member::currentUser(), array('AwaitingApproval')); if ($deletions) { foreach ($deletions as $deletion) { $deletion->RequestType = "Deletion"; } } if ($changes && $deletions) { $changes->merge($deletions); } else { if ($deletions) { $changes = $deletions; } } return $changes; }
/** * Unpublish the selected records passed from the unpublish bulk action * * @param SS_HTTPRequest $request * @return SS_HTTPResponse List of published record IDs */ public function unpublish(SS_HTTPRequest $request) { $ids = array(); foreach ($this->getRecords() as $record) { if ($record->hasExtension('Versioned')) { array_push($ids, $record->ID); $record->deleteFromStage(Versioned::get_live_stage()); } } $response = new SS_HTTPResponse(Convert::raw2json(array('done' => true, 'records' => $ids))); $response->addHeader('Content-Type', 'text/json'); return $response; }
/** * Unlink the selected records by setting the foreign key to zero * in both Stage and Live tables. * * @param SS_HTTPRequest $request * @return SS_HTTPResponse List of published record IDs */ public function versionedunlink(SS_HTTPRequest $request) { $ids = $this->getRecordIDList(); // remove the selected entries from Stage. $this->gridField->list->removeMany($ids); // Unpublish the unlinked records. // This is potentially destructive, but there's no other "good" way to do this. // When a unlinked record gets added to another page, the only way to "activate" the // record is to publish it.. so the published version will be overwritten anyway! foreach ($this->getRecords() as $record) { if ($record->hasExtension('Versioned')) { $record->deleteFromStage(Versioned::get_live_stage()); } } $response = new SS_HTTPResponse(Convert::raw2json(array('done' => true, 'records' => $ids))); $response->addHeader('Content-Type', 'text/json'); return $response; }
public function onAfterDelete() { $assets = $this->findAssets($this->owner); // When deleting from live, just secure assets // Note that DataObject::delete() ignores sourceQueryParams if ($this->isVersioned() && \Versioned::current_stage() === \Versioned::get_live_stage()) { $this->protectAll($assets); return; } // When deleting from stage then check if we should archive assets $archive = $this->owner->config()->archive_assets; if ($archive && $this->isVersioned()) { // Archived assets are kept protected $this->protectAll($assets); } else { // Otherwise remove all assets $this->deleteAll($assets); } }
function sourceRecords($params) { // Set stage, otherwise, we won't get any results $currentStage = Versioned::current_stage(); Versioned::reading_stage(Versioned::get_live_stage()); $res = WorkflowThreeStepRequest::get_by_author('WorkflowDeletionRequest', Member::currentUser(), array('AwaitingApproval', 'Approved')); // Reset stage back to what it was Versioned::reading_stage($currentStage); // Add WFRequestedWhen column $doSet = new DataObjectSet(); if ($res) { foreach ($res as $result) { if ($wf = $result->openWorkflowRequest()) { $result->WFRequestedWhen = $wf->Created; $doSet->push($result); } } } return $doSet; }
public function doCreate($data, $form) { if (!singleton('AdvancedReport')->canCreate()) { return Security::permissionFailure($this); } $data = $form->getData(); $description = $data['Description']; $class = $data['ClassName']; if (!is_subclass_of($class, 'AdvancedReport')) { $form->addErrorMessage('ClassName', _t('ReportHolder.INVALID_TYPE', 'An invalid report type was selected'), 'required'); return $this->redirectBack(); } $page = new ReportPage(); $page->update(array('Title' => $data['Title'], 'Content' => $description ? "<p>{$description}</p>" : '', 'ReportType' => $class, 'ParentID' => $this->data()->ID)); $page->writeToStage('Stage'); if (Versioned::current_stage() == Versioned::get_live_stage()) { $page->doPublish(); } return $this->redirect($page->Link()); }
/** * A function that returns the correct base table to use for custom forum queries. It uses the getVar stage to determine * what stage we are looking at, and determines whether to use SiteTree or SiteTree_Live (the general case). If the stage is * not specified, live is assumed (general case). It is a static function so it can be used for both ForumHolder and Forum. * * @return String */ static function baseForumTable() { $stage = Controller::curr()->getRequest() ? Controller::curr()->getRequest()->getVar('stage') : false; if (!$stage) { $stage = Versioned::get_live_stage(); } if (class_exists('SapphireTest', false) && SapphireTest::is_running_test() || $stage == "Stage") { return "SiteTree"; } else { return "SiteTree_Live"; } }
public static function getRequestedStage() { return Input::get('stage', \Versioned::get_live_stage()); }
/** * (non-PHPdoc) * * @see SiteTree::onBeforeWrite() */ public function onAfterWrite() { parent::onAfterWrite(); // Skip on publishing if (Versioned::get_live_stage() == Versioned::current_stage()) { return; } // Update the values of all fields added from editable field if ($this->ID && $this->many_many('Fields') && ($pageFields = $this->getEditableFields())) { foreach ($pageFields as $pageField) { // Set submitted value into the field $field = $pageField->getFormField(); if (!$field) { continue; } $field->setValue($this->{$pageField->Name}); // Extra fields to be saved $value = $field->Value(); $sort = $pageField->Sort; $group = $pageField->Group; // Clone the editable field object // Remove the current saved one $pageFields->remove($pageField); // Add the clone with the new extra data $pageFields->add($pageField, ['Value' => $value, 'Sort' => $sort, 'Group' => $group]); } } }