18 require_once SQ_PACKAGES_PATH.
'/web_services/api/soap_api/soap_api.inc';
43 parent::__construct($assetid);
58 'StartWorkflow' =>
'1',
59 'SafeEditAsset' =>
'1',
60 'CancelWorkflow' =>
'1',
61 'CompleteWorkflow' =>
'1',
62 'SetWorkflowSchema' =>
'1',
63 'ApproveAssetInWorkflow' =>
'1',
84 $request_info = (Array) $request;
88 $assetid = array_get_index($request_info,
'AssetID',
'');
89 if (!empty($assetid)) {
90 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
91 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
92 $asset_status = $asset->status;
93 if (!in_array($asset_status, Array (SQ_STATUS_UNDER_CONSTRUCTION, SQ_STATUS_LIVE, SQ_STATUS_EDITING))) {
94 throw new SoapFault(
'Server',
'Can Not Start Workflow When Asset Is In '.get_status_description($asset_status).
' Status');
97 $wm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
98 $current_schemas = $wm->getSchemas($assetid, TRUE);
99 if (empty($current_schemas)) {
100 throw new SoapFault(
'Server',
'There Is No Workflow Schemas Applied On This Asset');
104 $running_vars = Array (
105 'assetid' => $assetid,
106 'new_status' => self::getNextStatusStartWorkflow($asset_status),
107 'dependants_only' => TRUE,
110 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
111 $errors = $hh->freestyleHipo(
'hipo_job_edit_status', $running_vars);
112 if (empty($errors)) {
114 'StartWorkflowResult' => TRUE,
117 throw new SoapFault(
'Server',
'Unable To Start Workflow');
121 throw new SoapFault(
'Server',
'Asset ID Is Not Valid. Please Provide A Valid Asset ID');
133 private static function getNextStatusStartWorkflow($status)
135 $next_statuses = Array (
136 SQ_STATUS_UNDER_CONSTRUCTION => SQ_STATUS_PENDING_APPROVAL,
137 SQ_STATUS_LIVE => SQ_STATUS_LIVE_APPROVAL,
138 SQ_STATUS_EDITING => SQ_STATUS_EDITING_APPROVAL,
140 if (isset($next_statuses)) {
141 return ($next_statuses[$status]);
143 throw new SoapFault(
'Server',
'There are no status to advance to from status '.$status);
155 private static function getNextStatusCancelWorkflow($status)
157 $next_statuses = Array (
158 SQ_STATUS_PENDING_APPROVAL => SQ_STATUS_UNDER_CONSTRUCTION,
159 SQ_STATUS_APPROVED => SQ_STATUS_UNDER_CONSTRUCTION,
160 SQ_STATUS_LIVE_APPROVAL => SQ_STATUS_EDITING,
161 SQ_STATUS_EDITING => SQ_STATUS_LIVE,
162 SQ_STATUS_EDITING_APPROVAL => SQ_STATUS_EDITING
164 if (isset($next_statuses[$status])) {
165 return ($next_statuses[$status]);
167 throw new SoapFault(
'Server',
'There are no status to advance to from status '.$status);
179 private static function getNextStatusCompleteWorkflow($status)
181 $next_statuses = Array (
182 SQ_STATUS_APPROVED => SQ_STATUS_LIVE,
183 SQ_STATUS_LIVE_APPROVAL => SQ_STATUS_LIVE,
184 SQ_STATUS_EDITING_APPROVED => SQ_STATUS_LIVE,
186 if (isset($next_statuses[$status])) {
187 return ($next_statuses[$status]);
189 throw new SoapFault(
'Server',
'There are no status to advance to from status '.$status);
201 private static function getNextStatusApproveAssetInWorkflow($status)
203 $next_statuses = Array (
204 SQ_STATUS_EDITING => SQ_STATUS_EDITING_APPROVED,
205 SQ_STATUS_UNDER_CONSTRUCTION=> SQ_STATUS_APPROVED,
206 SQ_STATUS_PENDING_APPROVAL => SQ_STATUS_APPROVED,
207 SQ_STATUS_LIVE_APPROVAL => SQ_STATUS_LIVE_APPROVAL,
210 if (isset($next_statuses[$status])) {
211 return ($next_statuses[$status]);
213 throw new SoapFault(
'Server',
'There are no status to advance to from status '.$status);
234 $request_info = (Array) $request;
235 $assetid = array_get_index($request_info,
'AssetID',
'');
236 if (!empty($assetid)) {
237 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
239 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
240 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
241 $asset_status = $asset->status;
242 if (!in_array($asset_status, Array (SQ_STATUS_PENDING_APPROVAL, SQ_STATUS_LIVE_APPROVAL, SQ_STATUS_EDITING, SQ_STATUS_APPROVED, SQ_STATUS_EDITING_APPROVAL))) {
243 throw new SoapFault(
'Server',
'Can Not Cancel Workflow When Asset Is In '.get_status_description($asset_status).
' Status');
246 $wm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
247 $current_schemas = $wm->getSchemas($assetid, TRUE, ($asset_status == SQ_STATUS_EDITING) ? FALSE : TRUE);
248 if (empty($current_schemas)) {
249 throw new SoapFault(
'Server',
'There is no workflow schemas applied on this asset');
253 $running_vars = Array (
254 'assetid' => $assetid,
255 'new_status' => self::getNextStatusCancelWorkflow($asset_status),
256 'dependants_only' => TRUE,
259 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
260 $errors = $hh->freestyleHipo(
'hipo_job_edit_status', $running_vars);
261 if (empty($errors)) {
263 'CancelWorkflowResult' => TRUE,
266 throw new SoapFault(
'Server',
'Unable To Cancel Workflow');
270 throw new SoapFault(
'Server',
'Asset ID is not valid. Please provide a valid Asset ID');
291 $request_info = (Array) $request;
292 $assetid = array_get_index($request_info,
'AssetID',
'');
294 if (!empty($assetid)) {
295 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
296 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
297 $asset_status = $asset->status;
298 if (!in_array($asset_status, Array (SQ_STATUS_APPROVED, SQ_STATUS_EDITING_APPROVED, SQ_STATUS_LIVE_APPROVAL))) {
299 throw new SoapFault(
'Server',
'Can Not Complete Workflow When Asset Is In '.get_status_description($asset_status).
' Status');
302 $wm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
303 $current_schemas = $wm->getSchemas($assetid, TRUE, TRUE);
305 if (empty($current_schemas) && !in_array($asset_status, Array(SQ_STATUS_APPROVED, SQ_STATUS_EDITING_APPROVED))) {
306 throw new SoapFault(
'Server',
'There is no workflow schemas applied on this asset');
309 $new_status = self::getNextStatusCompleteWorkflow($asset_status);
312 $running_vars = Array (
313 'assetid' => $assetid,
314 'new_status' => $new_status,
315 'dependants_only' => TRUE,
318 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
319 $errors = $hh->freestyleHipo(
'hipo_job_edit_status', $running_vars);
320 if (empty($errors)) {
322 'CompleteWorkflowResult' => TRUE,
325 throw new SoapFault(
'Server',
'Unable To Complete Workflow');
329 throw new SoapFault(
'Server',
'Asset ID Is Not Valid. Please Provide A Valid Asset ID');
350 $request_info = (Array) $request;
351 $assetid = array_get_index($request_info,
'AssetID',
'');
353 if (!empty($assetid)) {
354 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
355 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
356 $asset_status = $asset->status;
357 if (!in_array($asset_status, Array (SQ_STATUS_LIVE))) {
358 throw new SoapFault(
'Server',
'Can Not Bring Asset To Safe Edit When Asset Is In '.get_status_description($asset_status).
' Status');
361 $wm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
362 $current_schemas = $wm->getSchemas($assetid, TRUE);
363 if (empty($current_schemas)) {
364 throw new SoapFault(
'Server',
'There Is No Workflow Schemas Applied On This Asset');
368 $running_vars = Array (
369 'assetid' => $assetid,
370 'new_status' => SQ_STATUS_EDITING,
371 'dependants_only' => TRUE,
374 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
375 $errors = $hh->freestyleHipo(
'hipo_job_edit_status', $running_vars);
376 if (empty($errors)) {
378 'SafeEditAssetResult' => TRUE,
381 throw new SoapFault(
'Server',
'Unable To Bring Asset To Safe Edit mode');
385 throw new SoapFault(
'Server',
'Asset ID Is Not Valid. Please Provide A Valid Asset ID');
406 $request_info = (Array) $request;
407 $assetid = array_get_index($request_info,
'AssetID',
'');
408 $workflow_message = array_get_index($request_info,
'WorkflowMessage',
'');
410 if (!empty($assetid)) {
411 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
412 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
414 $available_statuses = $asset->getAvailableStatii();
415 $asset_status = $asset->status;
417 if (!in_array($asset_status, Array (SQ_STATUS_EDITING, SQ_STATUS_UNDER_CONSTRUCTION, SQ_STATUS_APPROVED, SQ_STATUS_LIVE_APPROVAL, SQ_STATUS_PENDING_APPROVAL, SQ_STATUS_EDITING_APPROVAL))) {
418 throw new SoapFault(
'Server',
'Can Not Approve Workflow When Asset Is In '.get_status_description($asset_status).
' Status');
421 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
422 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
423 $current_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
425 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
426 $running_schemas = $wfm->getSchemas($assetid, TRUE, TRUE);
427 $userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
429 if (empty($running_schemas) && $asset_status != SQ_STATUS_UNDER_CONSTRUCTION) {
430 throw new SoapFault(
'Server',
'There is no workflow schemas running on this asset');
433 if (in_array($asset_status, Array ( SQ_STATUS_PENDING_APPROVAL, SQ_STATUS_EDITING_APPROVAL))) {
438 $wf_complete = $wfm->testPublish($asset->id, $userid);
441 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
442 $publishers = $wfm->whoCanPublish($asset->id);
443 if ($mm->allowsMetadata($asset->id) && !$GLOBALS[
'SQ_SYSTEM']->am->isDependant($asset->id)) {
444 $m_complete = $mm->requiredFieldsComplete($asset->id);
446 if ($wf_complete && $m_complete) {
447 if ($asset_status == SQ_STATUS_PENDING_APPROVAL) {
448 $new_status = SQ_STATUS_APPROVED;
449 }
else if ($asset_status == SQ_STATUS_EDITING_APPROVAL) {
450 $new_status = SQ_STATUS_EDITING_APPROVED;
452 $statii[SQ_STATUS_APPROVED] = translate(
'status_change_approve');
453 }
else if (in_array($userid, $publishers)) {
454 if ($asset_status == SQ_STATUS_PENDING_APPROVAL) {
455 $new_status = SQ_STATUS_PENDING_APPROVAL;
456 }
else if ($asset_status == SQ_STATUS_EDITING_APPROVAL) {
457 $new_status = SQ_STATUS_EDITING_APPROVAL;
462 $new_status = self::getNextStatusApproveAssetInWorkflow($asset_status);
466 $require_comment = $wfm->requiresComment($asset->id, $current_userid);
468 if ($require_comment && empty($workflow_message)) {
469 throw new SoapFault(
'Server',
'This approval step requires a comment and no comment have been provided');
472 if (!empty($running_schemas) && !($require_comment && empty($workflow_message))) {
476 $running_vars = Array (
477 'assetid' => $assetid,
478 'new_status' => $new_status,
479 'dependants_only' => TRUE,
481 $errors = $hh->freestyleHipo(
'hipo_job_edit_status', $running_vars);
484 if (!empty($workflow_message)) {
485 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
487 'message' => $workflow_message,
489 $message = $ms->newMessage(Array(),
'asset.workflow.userlog', $msg_reps);
490 $message->parameters[
'assetid'] = $asset->id;
491 $message->parameters[
'version'] = substr($asset->version, 0, strrpos($asset->version,
'.'));
496 if (empty($errors)) {
498 'ApproveAssetInWorkflowResult' => TRUE,
501 throw new SoapFault(
'Server',
'Unable To Complete Workflow');
507 throw new SoapFault(
'Server',
'Asset ID Is Not Valid. Please Provide A Valid Asset ID');
521 $request_info = (Array) $request;
523 $assetid = array_get_index($request_info,
'AssetID',
'');
524 $schemaid = array_get_index($request_info,
'SchemaID',
'');
525 $grant = self::array_get_index_restricted_value($request_info,
'Grant',
'');
526 $grant_level = Array (
531 $grant_val = $grant_level[$grant];
532 $auto_cascade = self::getBooleanIndex($request_info,
'AutoCascadeToNewChildren', TRUE);
533 $cascade = self::getBooleanIndex($request_info,
'Cascade', TRUE);
535 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
536 $has_dependants = !empty($dependants);
538 if (!empty($assetid) && !empty($schemaid)) {
539 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid);
541 throw new SoapFault(
'Server',
'The provided schemaid does not belong to a workflow schema asset');
544 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
545 $running_vars = Array (
546 'schema_changes' => Array (
548 'assetids' => Array ( $assetid),
549 'granted' => $grant_val,
550 'schemaid' => $schemaid,
551 'cascades' => $auto_cascade,
552 'previous_access' => NULL,
553 'dependants_only' => (!($cascade && $auto_cascade) && $has_dependants) || (!$has_dependants && !$cascade),
558 $errors = $hh->freestyleHipo(
'hipo_job_edit_workflow_schemas', $running_vars);
559 if (empty($errors)) {
561 'SetWorkflowSchemaResult' => TRUE,
565 if (isset($errors[0][
'message'])) $message = $errors[0][
'message'];
566 throw new SoapFault(
'Server',
'Unable to set Workflow Schema on Asset. '.$message);
569 throw new SoapFault(
'Server',
'Asset ID or Schema ID is not valid. Please provide a valid AssetID and SchemaID');
583 $obj_optional = self::getArgType(
'AssetObject', 0, 1);
584 $grant_type = self::getArgType(
'Grant', 1, 1);
586 $complex_types = Array (
587 'StartWorkflow' => Array (
588 'StartWorkflow' => Array (
589 'AssetID' => self::$string_non_optional,
591 'StartWorkflowResponse' => Array (
592 'StartWorkflowResult' => self::$boolean_optional,
595 'SafeEditAsset' => Array (
596 'SafeEditAsset' => Array (
597 'AssetID' => self::$string_non_optional,
599 'SafeEditAssetResponse' => Array (
600 'SafeEditAssetResult' => self::$boolean_optional,
603 'CancelWorkflow' => Array (
604 'CancelWorkflow' => Array (
605 'AssetID' => self::$string_non_optional,
607 'CancelWorkflowResponse' => Array (
608 'CancelWorkflowResult' => self::$boolean_optional,
611 'CompleteWorkflow' => Array (
612 'CompleteWorkflow' => Array (
613 'AssetID' => self::$string_non_optional,
615 'CompleteWorkflowResponse' => Array (
616 'CompleteWorkflowResult' => self::$boolean_optional,
619 'SetWorkflowSchema' => Array (
620 'SetWorkflowSchema' => Array (
621 'AssetID' => self::$string_non_optional,
622 'SchemaID' => self::$string_non_optional,
623 'Grant' => $grant_type,
624 'AutoCascadeToNewChildren' => self::$boolean_optional,
625 'Cascade' => self::$boolean_optional,
627 'SetWorkflowSchemaResponse' => Array (
628 'SetWorkflowSchemaResult' => self::$boolean_optional,
631 'ApproveAssetInWorkflow' => Array (
632 'ApproveAssetInWorkflow' => Array (
633 'AssetID' => self::$string_non_optional,
634 'WorkflowMessage' => self::$string_optional,
636 'ApproveAssetInWorkflowResponse' => Array (
637 'ApproveAssetInWorkflowResult' => self::$string_optional,
642 $complex_types_available = parent::getComplexElements($complex_types);
644 return $complex_types_available;
658 $simple_restricted_types = Array (
659 'SetWorkflowSchema' => Array (
661 'restriction_base' =>
'string',
662 'enumeration' => Array (
663 'Apply',
'Deny',
'Revoke',
669 $simple_restricted_types_available = parent::processSimpleRestrictedTypes($simple_restricted_types);
671 return $simple_restricted_types_available;