17 require_once SQ_INCLUDE_PATH.
'/asset_status/asset_status.inc';
48 $this->status_tag = SQ_STATUS_EDITING;
62 return translate(
'status_editing');
79 if (!$this->owner->writeAccess(
''))
return $statii;
82 $statii[SQ_STATUS_LIVE] = translate(
'status_change_cancel_safe_edit');
84 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
85 $running_schemas = $wfm->getSchemas($this->owner->id,
true,
true);
87 if (!empty($running_schemas)) {
90 pre_echo(
'FIXME: SOMETHING HAS GONE WRONG HERE');
93 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
94 if ($mm->allowsMetadata($this->owner->id)) {
95 $is_dependant = $GLOBALS[
'SQ_SYSTEM']->am->isDependant($this->owner->id);
97 if (($mm->requiredFieldsComplete($this->owner->id) && !$is_dependant) || $is_dependant) {
99 $schemas = $wfm->getSchemas($this->owner->id,
true);
100 if (empty($schemas)) {
102 if ($this->owner->adminAccess(
'')) {
103 $statii[SQ_STATUS_EDITING_APPROVED] = translate(
'status_change_approve');
108 if ($this->owner->adminAccess(
'')) {
111 $needs_workflow = FALSE;
112 $wf_complete = FALSE;
114 foreach ($schemas as $schemaid) {
115 $streams = $wfm->getStreams($schemaid);
117 foreach ($streams as $streamid => $stream_name) {
118 $publish_result = $wfm->testPublish($this->owner->id, $GLOBALS[
'SQ_SYSTEM']->currentUserId(), $stream_name);
119 if ($publish_result === TRUE) {
122 $needs_workflow = TRUE;
129 $wf_complete = $wfm->testPublish($this->owner->id, $GLOBALS[
'SQ_SYSTEM']->currentUserId(),
'');
130 $needs_workflow = !$wf_complete;
136 if ($wf_complete === TRUE) {
137 $statii[SQ_STATUS_EDITING_APPROVED] = translate(
'status_change_approve');
139 if ($needs_workflow === TRUE) {
140 $statii[SQ_STATUS_EDITING_APPROVAL] = translate(
'status_change_apply_for_approval');
145 $statii[SQ_STATUS_EDITING_APPROVAL] = translate(
'status_change_apply_for_approval');
151 $statii[SQ_STATUS_EDITING_APPROVED] = translate(
'status_change_approve');
152 $statii[SQ_STATUS_EDITING_APPROVAL] = translate(
'status_change_apply_for_approval');
169 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
170 if ($mm->allowsMetadata($this->owner->id) && !$mm->requiredFieldsComplete($this->owner->id)) {
171 return translate(
'cannot_approve_metadata_incomplete',
'<a href="'.htmlspecialchars(replace_query_string_vars(Array(
'asset_ei_screen' =>
'metadata'))).
'">'.strtolower(translate(
'metadata')).
'</a>');
190 if (!parent::processStatusChange($new_status, $update_parent)) {
194 switch ($new_status) {
196 case SQ_STATUS_LIVE :
198 if (!$this->owner->revertToSystemVersion()) {
203 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
204 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
205 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
207 if (!$wfm->silentWorkflowParty($this->owner->id)) {
208 $log = $ms->newMessage();
210 'user_name' => $user->name,
211 'workflow_user' => $user->name,
212 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->owner->type(),
'name'),
213 'asset_name' => $this->owner->name,
214 'status' => get_status_description($new_status),
216 $log->replacements = $msg_reps;
217 $log->type =
'asset.workflow.log.safeedit.cancel';
218 $log->parameters[
'assetid'] = $this->owner->id;
219 $log->parameters[
'version'] = substr($this->owner->version, 0, strrpos($this->owner->version,
'.'));
227 case SQ_STATUS_EDITING_APPROVAL :
228 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
231 $current_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
233 if (!$wfm->startWorkflow($this->owner->id)) {
234 trigger_localised_error(
'SYS0262', E_USER_WARNING, $this->owner->name);
239 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
240 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($current_userid);
243 if (!$wfm->silentWorkflowParty($this->owner->id)) {
244 $log = $ms->newMessage();
246 'user_name' => $user->name,
247 'workflow_user' => $user->name,
248 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->owner->type(),
'name'),
249 'asset_name' => $this->owner->name,
250 'status' => $this->getDescription(),
251 'workflow_url' => current_url().$this->owner->getBackendHref(
'workflow', FALSE),
253 $log->replacements = $msg_reps;
254 $asset_edt_fns = $this->owner->getEditFns();
255 if (isset($asset_edt_fns->static_screens[
'preview'])) {
256 $log->replacements[
'preview_url'] = current_url().$this->owner->getBackendHref(
'preview', FALSE);
258 $log->replacements[
'preview_url'] = current_url().$this->owner->getBackendHref(
'details', FALSE);
261 $log->type =
'asset.workflow.log.started';
262 $log->parameters[
'assetid'] = $this->owner->id;
263 $log->parameters[
'version'] = substr($this->owner->version, 0, strrpos($this->owner->version,
'.'));
264 $ms->enqueueMessage($log);
266 $running_schemas = $wfm->getSchemas($this->owner->id, TRUE, TRUE);
267 foreach ($running_schemas as $schemaid) {
268 $publishers = $wfm->whoCanPublish($this->owner->id, $schemaid);
269 if (count($publishers) > 0) {
270 $msg = $ms->newMessage();
271 $msg->type =
'asset.workflow.announce.started';
274 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid);
275 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
276 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
278 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
280 if ($schema->attr(
'schema_from_email_address') !=
'') {
281 $msg->from = $schema->attr(
'schema_from_email_address');
284 $msg->to = array_merge($msg->to, $publishers);
285 $msg->replacements = $msg_reps;
286 $msg->parameters[
'assetid'] = $this->owner->id;
287 $ms->enqueueMessage($msg);
294 case SQ_STATUS_EDITING_APPROVED :
296 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
299 $current_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
300 $wfm->setCurrentUserAsLastStarted($current_userid, $this->owner->id);