18 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
39 var $_valid_logic_with_right_operand = Array(
'>=');
46 var $_valid_step_logic = Array(
'>=' =>
'At least',
'all' =>
'All');
53 var $_valid_cond_logic = Array(
'>=' =>
'At least',
'all' =>
'All');
76 if (preg_match(
'/:/',$assetid))
return FALSE;
96 function getSchemas($assetid, $granted=NULL, $running=FALSE, $cascades=NULL)
98 $storage_access = ((is_null($granted)) ? 2 : (
int) $granted);
99 if (!isset($this->_tmp[
'schemas'][(
int)$assetid][$storage_access][(int)$running])) {
101 $sql =
' SELECT DISTINCT schemaid, granted, cascades
102 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_wflow ';
103 $where =
'assetid = :assetid';
106 $where .=
' AND DBMS_LOB.GETLENGTH(wflow) > 0';
108 $where .=
' AND wflow IS NOT NULL';
111 if (!is_null($granted) || $running) {
112 $where .=
' AND granted = :granted';
114 if (!is_null($cascades)) {
115 $where .=
' AND cascades = :cascades';
117 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
122 if (!is_null($granted) || $running) {
126 $granted_bind = $granted ?
'1' :
'0';
130 if (!is_null($cascades)) {
134 }
catch (Exception $e) {
135 throw new Exception(
'Unable to get workflow schemas for asset ID #'.$assetid.
' due to database error: '.$e->getMessage());
139 foreach ($result as $data) {
140 if (is_null($granted)) {
141 $schemas[$data[
'schemaid']] = $data[
'granted'];
143 $schemas[] = $data[
'schemaid'];
147 $this->_tmp[
'schemas'][(int)$assetid][$storage_access][(
int)$running] = $schemas;
150 return $this->_tmp[
'schemas'][(int)$assetid][$storage_access][(
int)$running];
169 function getAssetSchemaInfo($assetid, $schemaid=NULL, $cascades=NULL, $include_cascades=TRUE, $include_last_started_by=FALSE)
171 $sql =
' SELECT DISTINCT schemaid, granted, cascades, last_started_by
172 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_wflow ';
173 $where =
'assetid = :assetid';
174 if (!is_null($schemaid)) {
175 $where .=
' AND schemaid = :schemaid';
177 if (!is_null($cascades)) {
178 $where .=
' AND cascades = :cascades';
180 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
185 if (!is_null($schemaid)) {
188 if (!is_null($cascades)) {
192 }
catch (Exception $e) {
193 throw new Exception(
'Unable to get asset workflow schemas of asset ID #'.$assetid.
' due to database error: '.$e->getMessage());
197 foreach ($result as $data) {
198 if ($include_cascades || $include_last_started_by) {
199 $schemas[$data[
'schemaid']] = Array(
200 'granted' => $data[
'granted'],
202 if ($include_cascades) $schemas[$data[
'schemaid']][
'cascades'] = $data[
'cascades'];
203 if ($include_last_started_by) $schemas[$data[
'schemaid']][
'last_started_by'] = $data[
'last_started_by'];
206 $schemas[$data[
'schemaid']] = $data[
'granted'];
211 if (!is_null($schemaid)) {
212 if (array_key_exists($schemaid, $schemas)) {
213 $schemas = $schemas[$schemaid];
235 function setSchema($assetid, $schemaid, $granted, $cascades=TRUE, $force_set=FALSE)
237 $assetid = (int) $assetid;
238 $schemaid = (int) $schemaid;
239 $granted = (bool) $granted;
240 $db_action =
'insert';
242 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid);
243 if (is_null($schema)) {
244 trigger_localised_error(
'SYS0175', E_USER_WARNING, $schemaid);
249 trigger_localised_error(
'SYS0173', E_USER_WARNING, $schema->name, $schemaid);
253 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
254 if (is_null($asset)) {
255 trigger_localised_error(
'SYS0174', E_USER_WARNING, $assetid);
259 if (!$asset->adminAccess(
'workflow')) {
260 trigger_localised_error(
'SYS0117', E_USER_WARNING, $asset->name);
265 $running_schemas = $this->
getSchemas($assetid, TRUE, TRUE);
266 if (!empty($running_schemas)) {
267 trigger_localised_error(
'SYS0118', E_USER_WARNING, $asset->name);
275 if (!empty($schema_info)) {
277 if ((
bool)$schema_info[
'granted'] == $granted) {
279 if ((
bool)$schema_info[
'cascades'] == $cascades) {
284 $db_action =
'update';
288 $db_action =
'update';
291 $new_access = ($granted) ?
'apply' :
'deny';
292 $current_access = ($granted) ?
'denied' :
'applied';
294 trigger_localised_error(
'SYS0124', E_USER_WARNING, $new_access, $schema->name, $asset->name, $current_access);
300 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
301 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
303 if ($db_action ==
'insert') {
304 $query_name =
'setWorkflowSchema';
305 }
else if ($db_action ==
'update') {
306 $query_name =
'updateWorkflowSchema';
311 'assetid' => (
string)$assetid,
312 'schemaid' => (
string)$schemaid,
314 'granted' => $granted ?
'1' :
'0',
315 'cascades' => $cascades ?
'1' :
'0',
319 throw new Exception (
'Unable to set workflow schema for "'.$asset->name.
'" (#'.$asset->id.
') due to database error: '.$e->getMessage());
322 unset($this->_tmp[
'schemas'][(
int)$assetid]);
323 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
324 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
343 $assetid = (int) $assetid;
344 $schemaid = (int) $schemaid;
346 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
347 if (is_null($asset)) {
348 trigger_localised_error(
'SYS0153', E_USER_WARNING, $assetid);
352 if (!$asset->adminAccess(
'workflow')) {
353 trigger_localised_error(
'SYS0105', E_USER_WARNING, $asset->name);
359 $running_schemas = $this->
getSchemas($assetid, TRUE, TRUE);
360 if (!empty($running_schemas)) {
361 trigger_localised_error(
'SYS0106', E_USER_WARNING, $asset->name);
366 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
367 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
371 'assetid' => (
string)$asset->id,
372 'schemaid' => (
string)$schemaid,
376 throw new Exception (
'Unable to delete workflow schema for "'.$asset->name.
'" (#'.$asset->id.
') due to database error: '.$e->getMessage());
379 unset($this->_tmp[
'schemas'][(
int)$assetid]);
380 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
381 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
402 $assetid = (int) $assetid;
404 if ($schemaid !=
'all') {
407 if (isset($this->_tmp[
'schema_workflows'][$assetid][
'all'][$schemaid])) {
408 $this->_tmp[
'schema_workflows'][$assetid][$schemaid] = $this->_tmp[
'schema_workflows'][$assetid][
'all'][$schemaid];
412 if (!isset($this->_tmp[
'schema_workflows'][$assetid][$schemaid])) {
413 $workflows = Array();
414 $bind_vars = Array();
419 '.SQ_TABLE_RUNNING_PREFIX.
'ast_wflow ';
421 $where =
'assetid = :assetid
422 AND granted = \'1\'';
423 $bind_vars[
'assetid'] = $assetid;
425 if ($schemaid !=
'all') {
426 $where .=
' AND schemaid = :schemaid';
427 $bind_vars[
'schemaid'] = $schemaid;
429 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
433 foreach ($bind_vars as $bind_var => $bind_value) {
437 }
catch (Exception $e) {
438 throw new Exception(
'Unable to get workflow schema(s) for asset: '.$assetid.
' due to database error: '.$e->getMessage());
441 foreach ($results as $assetid => $serialized_wflow) {
442 $workflows[$assetid] = (empty($serialized_wflow[0][
'wflow']) ?
'' : unserialize($serialized_wflow[0][
'wflow']));
445 if ($schemaid ==
'all') {
446 $this->_tmp[
'schema_workflows'][$assetid][
'all'] = $workflows;
448 $this->_tmp[
'schema_workflows'][$assetid][$schemaid] = $workflows[$schemaid];
452 if (!isset($this->_tmp[
'schema_workflows'][$assetid][$schemaid])) {
456 return $this->_tmp[
'schema_workflows'][$assetid][$schemaid];
472 $assetid = (int) $assetid;
474 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
475 if (is_null($asset)) {
476 trigger_localised_error(
'SYS0177', E_USER_WARNING, $assetid);
480 if (!$asset->adminAccess(
'workflow')) {
481 trigger_localised_error(
'SYS0117', E_USER_WARNING, $asset->name);
485 $schemas = $this->
getSchemas($asset->id, TRUE);
486 if (empty($schemas))
return FALSE;
488 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
489 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
491 foreach ($schemas as $schemaid) {
492 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid);
493 if (is_null($schema)) {
494 trigger_localised_error(
'SYS0174', E_USER_WARNING, $schemaid);
495 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
496 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
501 trigger_localised_error(
'SYS0176', E_USER_WARNING, $schema->name, $schemaid);
502 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
503 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
507 if (!isset($workflow[$schema->name]))
continue;
511 'wflow' => serialize($workflow[$schema->name]),
512 'assetid' => $asset->id,
513 'schemaid' => $schema->id,
516 }
catch (Exception $e) {
517 throw new Exception(
'Unable to update workflow table for asset: '.$assetid.
' due to database error: '.$e->getMessage());
520 $this->_tmp[
'schema_workflows'][$assetid][$schemaid] = $workflow[$schema->name];
523 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
524 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
546 $running_schemas = $this->
getSchemas($assetid, TRUE, TRUE);
547 if (empty($running_schemas))
return Array();
551 $can_publish = Array();
553 foreach ($running_schemas as $sid) {
554 if (!is_null($schemaid) && $sid != $schemaid) {
559 $can_publish[$sid] = array_unique($can_publish[$sid]);
565 if (!$group) $can_publish = array_unique($can_publish);
585 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
586 if (is_null($asset)) {
587 trigger_localised_error(
'SYS0180', E_USER_WARNING, $assetid);
593 if (empty($schemas))
return TRUE;
595 foreach ($schemas as $schemaid => $schema_info) {
596 if (!$schema_info[
'granted'])
continue;
601 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid,
'workflow_schema');
602 if ($schema && $schema->attr(
'notify_starter_on_live')){
603 if (!empty($schema_info[
'last_started_by'])){
604 $started_by_user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schema_info[
'last_started_by'],
'', TRUE);
605 if ($started_by_user){
608 if ($started_by_user instanceof
Simple_Edit_User) $started_by_user->_tmp[
'starter_of_workflow'] = TRUE;
609 $notify[] = $schema_info[
'last_started_by'];
614 $conditions = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($schemaid,
'workflow_step_condition');
615 foreach ($conditions as $cond_id => $type_code) {
616 $condition = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($cond_id,
'workflow_step_condition');
617 if (is_null($condition))
continue;
618 if ($condition->attr(
'notify')) {
620 if (SQ_CONF_ENABLE_ROLES_WF_SYSTEM ==
'1') {
621 $fetch_global_roles = (SQ_CONF_ENABLE_GLOBAL_ROLES ==
'1');
622 $role = $GLOBALS[
'SQ_SYSTEM']->am->getRole($assetid, $condition->attr(
'userid'), NULL, FALSE, $fetch_global_roles);
624 foreach ($role as $roleid => $userids) {
625 for ($i=0; $i<count($userids); $i++) {
626 $notify[] = $userids[$i];
631 $notify[] = $condition->attr(
'userid');
635 $notify[] = $condition->attr(
'userid');
640 if (!empty($notify)) {
641 $notify = array_unique($notify);
642 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
643 $msg = $ms->newMessage($notify);
644 $msg->type =
'asset.status.notify';
646 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name'),
647 'asset_name' => $asset->name,
648 'status' => get_status_description($old_status),
652 $asset_edt_fns = $asset->getEditFns();
653 if (isset($asset_edt_fns->static_screens[
'preview'])) {
654 $msg_reps[
'asset_url'] = current_url().$asset->getBackendHref(
'preview', FALSE);
656 $msg_reps[
'asset_url'] = current_url().$asset->getBackendHref(
'details', FALSE);
659 $msg->replacements = $msg_reps;
663 if (trim($schema->attr(
'message_notify_on_live')) !==
'' ) {
664 $msg->body = trim($schema->attr(
'message_notify_on_live'));
668 if (trim($schema->attr(
'subject_notify_on_live')) !==
'') {
669 $subject = trim($schema->attr(
'subject_notify_on_live'));
670 $msg->subject = (!empty($subject)) ? $subject :
'Asset Made Live';
673 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
674 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
676 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
678 if ($schema->attr(
'schema_from_email_address') !=
'') {
679 $msg->from = $schema->attr(
'schema_from_email_address');
685 $msg->parameters[
'assetid'] = $asset->id;
686 $ms->enqueueMessage($msg);
708 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
709 if (is_null($asset)) {
711 trigger_localised_error(
'SYS0180', E_USER_WARNING, $assetid);
717 if (empty($schemas))
return FALSE;
722 foreach ($schemas as $schemaid) {
724 if (empty($schema_workflows[$schemaid]))
continue;
727 if (empty($current_workflow_steps[$schemaid])) {
732 $current_step =& $this->
getCurrentStep($schema_workflows[$schemaid]);
734 $listed_user = FALSE;
737 $condition_type_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeInfo(array_keys($current_step[
'conditions']));
738 foreach ($current_step[
'conditions'] as $conditionid => $condition_details) {
740 if (in_array(
'user_group', $condition_type_info[$conditionid])) {
741 $group_users = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($conditionid, Array(
'user'), FALSE, NULL, NULL, NULL, TRUE, NULL, NULL, FALSE, NULL, Array(), TRUE));
742 if (in_array($userid, $group_users)) {
747 if ($conditionid == $userid) $listed_user = TRUE;
750 if (array_get_index($condition_details,
'require_comment', FALSE)) {
759 if (!$listed_user && array_get_index($current_step,
'require_comment_from_unlisted_users', FALSE)) {
783 $am = $GLOBALS[
'SQ_SYSTEM']->am;
785 $can_publish = Array();
787 if (!isset($workflow[
'steps']))
return Array();
790 if (empty($step_data))
return Array();
792 for (reset($step_data[
'conditions']);
793 NULL !== ($pub = key($step_data[
'conditions'])); next($step_data[
'conditions'])) {
794 $cond_data =& $step_data[
'conditions'][$pub];
797 if (!isset($cond_data[
'complete'])) {
798 $cond_data[
'complete'] = FALSE;
800 if (!isset($cond_data[
'published_by'])) {
801 $cond_data[
'published_by'] = Array();
804 if ($cond_data[
'complete']) {
808 $can_publish_cond = Array();
811 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($pub);
813 $asset_class = get_class($asset);
816 if ($am->isTypeDecendant($asset_class,
'user')) {
817 $can_publish_cond[] = $asset->id;
818 }
else if ($am->isTypeDecendant($asset_class,
'role')) {
820 if (SQ_CONF_ENABLE_ROLES_WF_SYSTEM ==
'1') {
821 $fetch_global_roles = (SQ_CONF_ENABLE_GLOBAL_ROLES ==
'1');
822 $roles = $GLOBALS[
'SQ_SYSTEM']->am->getRole($assetid, $asset->id, NULL, FALSE, TRUE);
823 foreach ($roles as $roleid => $userids) {
824 foreach ($userids as $userid) {
825 $info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($userid), Array(), FALSE,
'type_code');
826 if ($GLOBALS[
'SQ_SYSTEM']->am->isTypeDecendant($info[$userid],
'user_group')) {
827 $can_publish_cond = array_merge($can_publish_cond, array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($userid, Array(
'user'), FALSE, NULL, NULL, NULL, TRUE, NULL, NULL, FALSE, NULL, Array(), TRUE)));
829 $can_publish_cond[] = $userid;
834 }
else if ($am->isTypeDecendant($asset_class,
'user_group')) {
836 $can_publish_cond = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($asset->id, Array(
'user'), FALSE, NULL, NULL, NULL, TRUE, NULL, NULL, FALSE, NULL, Array(), TRUE));
840 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
842 if ($cond_data[
'logic'] ==
'all') {
843 $cond_string =
'if ('.count($cond_data[
'published_by']).
844 ' >= '.count($can_publish_cond).
') { $complete = true; }';
846 $cond_string =
'if ('.count($cond_data[
'published_by']).
847 ' '.$cond_data[
'logic'].
') { $complete = true; }';
854 $can_publish = array_merge($can_publish, array_diff($can_publish_cond, array_keys($cond_data[
'published_by'])));
858 return array_unique($can_publish);
875 $workflow[
'current_step'] = Array();
877 $current_step_found = FALSE;
878 $step_array =& $workflow[
'steps'];
880 while (!$current_step_found) {
881 $current_step_found = TRUE;
882 for (reset($step_array); NULL !== ($stepid = key($step_array)); next($step_array)) {
883 $step_data =& $step_array[$stepid];
887 $step_keys = array_keys($workflow[
'current_step']);
888 $last_key = end($step_keys);
889 $workflow[
'current_step'][$last_key] = $stepid;
891 if ($step_data[
'expired']) {
892 if ($step_data[
'completed']) {
895 $current_step_found = FALSE;
899 $step_array =& $step_data[
'escalation_steps'];
902 $workflow[
'current_step'][] = $stepid;
903 $current_step_found = FALSE;
910 $current_step_found = TRUE;
911 $completed_conds = 0;
913 for (reset($step_data[
'conditions']);
914 NULL !== ($pub = key($step_data[
'conditions'])); next($step_data[
'conditions'])) {
915 $current_step_found = TRUE;
916 $cond_data =& $step_data[
'conditions'][$pub];
919 if (!isset($cond_data[
'complete'])) {
920 $cond_data[
'complete'] = FALSE;
922 if (!isset($cond_data[
'published_by'])) {
923 $cond_data[
'published_by'] = Array();
926 if (empty($cond_data[
'published_by'])) {
928 if ($step_data[
'logic'] ==
'all') {
929 $current_step_found = TRUE;
937 if ($cond_data[
'complete']) {
938 $current_step_found = FALSE;
942 $current_step_found = TRUE;
943 if ($cond_data[
'logic'] ==
'all') {
945 $can_publish_cond = Array();
946 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($pub);
948 if ($asset instanceof
User) {
949 $can_publish_cond[] = $asset->id;
951 $can_publish_cond = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($asset->id, Array(
'user'), FALSE, NULL, NULL, NULL, TRUE, NULL, NULL, FALSE, NULL, Array(), TRUE));
954 $cond_string =
'if ('.count($cond_data[
'published_by']).
955 ' >= '.count($can_publish_cond).
') { $complete = true; }';
957 $cond_string =
'if ('.count($cond_data[
'published_by']).
958 ' '.$cond_data[
'logic'].
') { $complete = true; }';
965 $cond_data[
'complete'] = TRUE;
966 $current_step_found = FALSE;
968 if ($step_data[
'logic'] ==
'all')
continue;
970 $step_completed = FALSE;
971 $logic_string =
'if ('.$completed_conds.
' '.$step_data[
'logic'].
' ) { $step_completed = true; }';
974 if ($step_completed) {
979 $current_step_found = TRUE;
987 if ($step_data[
'logic'] ==
'all' && $completed_conds < count($step_data[
'conditions'])) {
988 $current_step_found = TRUE;
990 if ($current_step_found)
break;
995 $step_keys = array_keys($workflow[
'current_step']);
996 $last_key = end($step_keys);
997 if ($workflow[
'current_step'][$last_key] == count($step_array) && $current_step_found == FALSE) {
1000 if (count($workflow[
'current_step']) == 1) {
1001 $workflow[
'current_step'] = Array();
1002 $current_step_found = TRUE;
1008 $completed_step_id = array_pop($workflow[
'current_step']);
1010 $step_array[$completed_step_id][
'completed'] = time();
1016 $current_step_id = end($workflow[
'current_step']);
1017 $step_array[$current_step_id][
'completed'] = time();
1036 $assetid = (int) $assetid;
1037 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1038 if (is_null($asset)) {
1039 trigger_localised_error(
'SYS0160', E_USER_WARNING, $assetid);
1044 $running_schemas = $this->
getSchemas($assetid, TRUE, TRUE);
1045 if (empty($running_schemas))
return FALSE;
1050 $schema_publishers_before = Array();
1052 foreach ($running_schemas as $schemaid) {
1053 $schema_publishers_before[$schemaid] = $this->
whoCanPublish($asset->id, $schemaid);
1057 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1058 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1060 for (reset($schema_workflows); NULL !== ($schemaid = key($schema_workflows)); next($schema_workflows)) {
1061 if (!in_array($schemaid, $running_schemas))
continue;
1062 $workflow =& $schema_workflows[$schemaid];
1063 if ($workflow[
'complete'] == TRUE)
continue;
1065 $new_workflow = serialize($workflow);
1069 'wflow' => $new_workflow,
1070 'assetid' => $assetid,
1071 'schemaid' => $schemaid,
1074 }
catch (Exception $e) {
1075 throw new Exception(
'Unable to update workflow table for asset: '.$assetid.
' due to database error: '.$e->getMessage());
1079 $this->_tmp[
'schema_workflows'][$assetid][$schemaid] = $workflow;
1080 if (isset($this->_tmp[
'schema_workflows'][$assetid][
'all'][$schemaid])) {
1081 $this->_tmp[
'schema_workflows'][$assetid][
'all'][$schemaid] = $workflow;
1087 $asset_type = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name');
1088 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
1089 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
1093 $comments = $ms->getMessages(0,
'asset.workflow.userlog', Array(), Array(), $workflow[
'started'], NULL,
'name', Array(
'assetid' => $asset->id));
1094 foreach ($comments as $comment) {
1095 $log_message .=
'"'.$comment[
'body'].
'"'.
', by '.$comment[
'from_name'].
', '.ts_iso8601($comment[
'sent']).
"\n";
1098 $log = $ms->newMessage();
1100 'workflow_user' => $user->name,
1101 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name'),
1102 'asset_name' => $asset->name,
1103 'assetid' => $asset->id,
1104 'workflow_url' => current_url().$asset->getBackendHref(
'workflow', FALSE),
1105 'asset_url' => $asset->getDependantParentsURL(),
1106 'asset_version' => $asset->version,
1107 'log_message' => $log_message,
1109 $log->replacements = $msg_reps;
1110 $log->type =
'asset.workflow.log.approve';
1111 $log->parameters[
'assetid'] = $asset->id;
1112 $log->parameters[
'version'] = substr($asset->version, 0, strrpos($asset->version,
'.'));
1113 $ms->enqueueMessage($log);
1117 $base_msg = $ms->newMessage();
1118 $base_msg->type =
'asset.workflow.announce.approve';
1119 $base_msg->parameters[
'assetid'] = $asset->id;
1120 $base_msg->replacements = $msg_reps;
1123 $generic_publishers_before = Array();
1124 foreach ($schema_publishers_before as $schemaid => $publishers_step) {
1125 $workflow =& $schema_workflows[$schemaid];
1126 $current_step = $this->
getCurrentStep($workflow, $steps_before[$schemaid]);
1127 if (in_array($publisher, $publishers_step)) {
1129 if (isset($current_step[
'message_approve']) && trim($current_step[
'message_approve']) !==
'' ) {
1130 $msg = clone $base_msg;
1131 $msg->to = $publishers_step;
1133 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid,
'workflow_schema');
1134 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
1135 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
1137 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1139 if ($schema->attr(
'schema_from_email_address') !=
'') {
1140 $msg->from = $schema->attr(
'schema_from_email_address');
1143 $subject = trim(array_get_index($current_step,
'subject_approve',
'Asset Changes Approved'));
1144 $msg->subject = (!empty($subject)) ? $subject :
'Asset Changes Approved';
1145 $msg->body = trim($current_step[
'message_approve']);
1147 $ms->enqueueMessage($msg);
1148 }
else if (isset($current_step[
'subject_approve']) && trim($current_step[
'subject_approve']) !==
'') {
1149 $msg = clone $base_msg;
1150 $msg->to = $publishers_step;
1152 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid,
'workflow_schema');
1153 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
1154 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
1156 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1158 if ($schema->attr(
'schema_from_email_address') !=
'') {
1159 $msg->from = $schema->attr(
'schema_from_email_address');
1162 $subject = trim(array_get_index($current_step,
'subject_approve',
'Asset Changes Approved'));
1163 $msg->subject = (!empty($subject)) ? $subject :
'Asset Changes Approved';
1165 $ms->enqueueMessage($msg);
1167 $generic_publishers_before = array_merge($generic_publishers_before, $publishers_step);
1170 $generic_publishers_before = array_merge($generic_publishers_before, $publishers_step);
1177 if (count($generic_publishers_before) > 0) {
1178 $msg = clone $base_msg;
1179 $msg->to = $generic_publishers_before;
1181 $ms->enqueueMessage($msg);
1185 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_workflow_approval', $asset);
1192 foreach ($steps_after as $schemaid => $step) {
1194 if (empty($step))
continue;
1196 if (!($step == $steps_before[$schemaid])) {
1200 $workflow_backend_href = $asset->getBackendHref(
'workflow', FALSE);
1201 if (!empty($workflow_backend_href) && substr($workflow_backend_href, 0, 2) !=
'./') {
1202 $workflow_backend_href =
'/'.$workflow_backend_href;
1205 $asset_edt_fns = $asset->getEditFns();
1206 if (isset($asset_edt_fns->static_screens[
'preview'])) {
1207 $preview_backend_href = $asset->getBackendHref(
'preview', FALSE);
1208 if (!empty($preview_backend_href) && substr($preview_backend_href, 0, 2) !=
'./') {
1209 $preview_backend_href =
'/'.$preview_backend_href;
1211 $preview_url = current_url().$preview_backend_href;
1213 $details_backend_href = $asset->getBackendHref(
'preview', FALSE);
1214 if (!empty($details_backend_href) && substr($details_backend_href, 0, 2) !=
'./') {
1215 $details_backend_href =
'/'.$details_backend_href;
1217 $preview_url = current_url().$details_backend_href;
1220 if ($asset->status == SQ_STATUS_LIVE_APPROVAL){
1221 $msg = $ms->newMessage($publishers);
1223 $workflow = $schema_workflows[$schemaid];
1227 'workflow_user' => $user->name,
1228 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name'),
1229 'asset_name' => $asset->name,
1230 'assetid' => $asset->id,
1231 'workflow_url' => current_url().$workflow_backend_href,
1232 'preview_url' => $preview_url,
1235 $msg->type =
'asset.workflow.review';
1236 $msg->parameters[
'assetid'] = $asset->id;
1238 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid,
'workflow_schema');
1239 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
1240 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
1242 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1244 if ($schema->attr(
'schema_from_email_address') !=
'') {
1245 $msg->from = $schema->attr(
'schema_from_email_address');
1249 if (isset($current_step[
'message_review_invitation']) && trim($current_step[
'message_review_invitation']) !==
'' ) {
1250 $msg->body = trim($current_step[
'message_review_invitation']);
1254 if (isset($current_step[
'subject_review_invitation']) && trim($current_step[
'subject_review_invitation']) !==
'' ) {
1255 $subject = trim(array_get_index($current_step,
'subject_review_invitation',
'Asset Up For Review'));
1256 $msg->subject = (!empty($subject)) ? $subject :
'Asset Up For Review';
1259 $msg->replacements = $msg_reps;
1261 $ms->enqueueMessage($msg);
1264 $msg = $ms->newMessage($publishers);
1266 $workflow =& $schema_workflows[$schemaid];
1267 $previous_step =& $this->
getCurrentStep($workflow, $steps_before[$schemaid]);
1268 $previous_step_name =& $previous_step[
'step_name'];
1270 $current_step_name =& $current_step[
'step_name'];
1272 $accept_url = $workflow_backend_href.
'&asset_version='.$asset->version.
'&workflow_link_action=approve';
1273 $reject_url = $workflow_backend_href.
'&asset_version='.$asset->version.
'&workflow_link_action=reject';
1276 'workflow_user' => $user->name,
1277 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name'),
1278 'asset_name' => $asset->name,
1279 'assetid' => $asset->id,
1280 'previous_step_id' => implode(
'.', $steps_before[$schemaid]),
1281 'previous_step_name' => $previous_step_name,
1282 'current_step_id' => implode(
'.', $step),
1283 'current_step_name' => $current_step_name,
1284 'workflow_url' => current_url().$workflow_backend_href,
1285 'accept_url' => current_url().$accept_url,
1286 'reject_url' => current_url().$reject_url,
1287 'asset_url' => $asset->getDependantParentsURL(),
1288 'asset_version' => $asset->version,
1289 'log_message' => $log_message,
1290 'preview_url' => $preview_url,
1293 $msg->type =
'asset.workflow.invitation.progress';
1294 $msg->parameters[
'assetid'] = $asset->id;
1295 $msg->replacements = $msg_reps;
1297 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid,
'workflow_schema');
1298 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
1299 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
1301 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1303 if ($schema->attr(
'schema_from_email_address') !=
'') {
1304 $msg->from = $schema->attr(
'schema_from_email_address');
1308 if (isset($current_step[
'message_invitation']) && trim($current_step[
'message_invitation']) !==
'' ) {
1309 $msg->body = trim($current_step[
'message_invitation']);
1313 if (isset($current_step[
'subject_invitation']) && trim($current_step[
'subject_invitation']) !==
'' ) {
1314 $subject = trim(array_get_index($current_step,
'subject_invitation',
'Workflow Approval Required'));
1315 $msg->subject = (!empty($subject)) ? $subject :
'Workflow Approval Required';
1319 $ms->enqueueMessage($msg);
1329 $current_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1332 if (in_array($current_userid, $list_of_publishers)) {
1334 trigger_localised_error(
'SYS0078', E_USER_WARNING, $current_userid);
1339 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1340 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1372 $running_schemas = $this->
getSchemas($assetid, TRUE, TRUE);
1374 if (empty($running_schemas)) {
1376 $schemas = $this->
getSchemas($assetid, TRUE);
1377 $streamids = Array();
1381 foreach ($schemas as $index => $schema) {
1382 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetExists($schema)) {
1383 trigger_error(
"Workflow Schema Id #$schema is applied to Asset Id #$assetid but cannot be found in system anymore.", E_USER_WARNING);
1384 unset($schemas[$index]);
1387 if ($stream_name === NULL) {
1389 foreach ($schemas as $schemaid) {
1390 $streamids[$schemaid] = $this->
getStreams($schemaid);
1392 }
else if ($stream_name ===
'') {
1397 foreach ($default_streamids as $schemaid => $streamid) {
1398 $streamids[$schemaid] = Array($streamid =>
'Default Stream');
1405 foreach ($named_streamids as $schemaid => $streamid) {
1406 $streamids[$schemaid] = Array($streamid => $stream_name);
1410 foreach ($schemas as $schemaid) {
1411 foreach ($streamids[$schemaid] as $streamid => &$stream_name) {
1414 $running_schemas[] = $schemaid;
1418 foreach($schema_workflows as $schemaid => &$schema_workflow) {
1420 $streamid = array_get_index($schema_workflow,
'stream_assetid', 0);
1421 $schema_workflow = Array($streamid => $schema_workflow);
1425 for (reset($schema_workflows); NULL !== ($schemaid = key($schema_workflows)); next($schema_workflows)) {
1426 if (!in_array($schemaid, $running_schemas))
continue;
1428 foreach ($schema_workflows[$schemaid] as $streamid => &$workflow) {
1430 if ($workflow[
'complete'])
continue;
1434 while (!$workflow[
'complete']) {
1441 if (!$workflow[
'complete'])
return FALSE;
1466 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1467 $workflow_updated = FALSE;
1469 if (empty($workflow[
'steps'])) {
1470 $workflow_updated = TRUE;
1471 $workflow[
'complete'] = TRUE;
1472 $workflow[
'steps'] = Array();
1475 for (reset($step_data[
'conditions']);
1476 NULL !== ($pub = key($step_data[
'conditions'])); next($step_data[
'conditions'])) {
1478 $cond_data =& $step_data[
'conditions'][$pub];
1480 $can_publish = Array();
1481 $publisher = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($pub);
1482 if ($publisher->id) {
1483 $asset_class = get_class($publisher);
1487 if ($am->isTypeDecendant($asset_class,
'user')) {
1488 $can_publish[] = $publisher->id;
1489 }
else if ($am->isTypeDecendant($asset_class,
'role')) {
1490 if (SQ_CONF_ENABLE_ROLES_WF_SYSTEM ==
'1') {
1491 $fetch_global_roles = (SQ_CONF_ENABLE_GLOBAL_ROLES ==
'1');
1492 $roles = $GLOBALS[
'SQ_SYSTEM']->am->getRole($assetid, $publisher->id, NULL, FALSE, $fetch_global_roles, TRUE);
1493 foreach ($roles as $roleid => $userids) {
1494 foreach ($userids as $userid) {
1495 $can_publish[] = $userid;
1499 }
else if ($am->isTypeDecendant($asset_class,
'user_group')) {
1500 $can_publish = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($publisher->id, Array(
'user'), FALSE, NULL, NULL, NULL, TRUE, NULL, NULL, FALSE, NULL, Array(), TRUE));
1504 if (in_array($publisherid, $can_publish)) {
1505 if (!isset($cond_data[
'published_by'])) {
1506 $cond_data[
'published_by'] = Array();
1509 if (!isset($cond_data[
'published_by'][$publisherid])) {
1510 $cond_data[
'published_by'][$publisherid] = time();
1511 $workflow_updated = TRUE;
1517 if ($workflow_updated) {
1522 if ($workflow[
'current_step'] === Array()) {
1523 $workflow[
'complete'] = TRUE;
1525 $num_steps = count($workflow[
'steps']);
1526 if ($num_steps > 0) {
1527 $workflow[
'steps'][$num_steps][
'completed'] = time();
1532 if (!$current_step[
'started']) {
1533 $current_step[
'started'] = time();
1536 $step_keys = array_keys($workflow[
'current_step']);
1537 $last_key = end($step_keys);
1538 if ($workflow[
'current_step'][$last_key] > 1) {
1539 $previous_step_address = $workflow[
'current_step'];
1540 $previous_step_address[$last_key]--;
1541 $previous_step =& $this->
getCurrentStep($workflow, $previous_step_address);
1542 if (!$previous_step[
'completed']) {
1543 $previous_step[
'completed'] = time();
1550 return $workflow_updated;
1569 $assetid = (int) $assetid;
1570 $streamid = (int) $streamid;
1572 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1573 if (is_null($asset)) {
1574 trigger_localised_error(
'SYS0155', E_USER_WARNING, $assetid);
1578 $stream = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($streamid);
1579 if (is_null($stream)) {
1580 trigger_localised_error(
'SYS0156', E_USER_WARNING, $streamid);
1585 trigger_localised_error(
'SYS0154', E_USER_WARNING, $stream->name, $streamid);
1590 $asset_schemas = $this->
getSchemas($assetid, TRUE);
1591 $stream_parents = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($streamid,
'workflow_schema', TRUE);
1593 if (count(array_intersect($asset_schemas, $stream_parents)) === 0) {
1597 $edit_fns = $stream->getEditFns();
1598 return $edit_fns->generateWorkflowArray($stream);
1613 function startWorkflow($assetid, $auto_approve=TRUE, $base_msg=NULL, $stream_name=NULL)
1615 $assetid = (int) $assetid;
1616 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1617 if (is_null($asset)) {
1618 trigger_localised_error(
'SYS0179', E_USER_WARNING, $assetid);
1622 $schemas = $this->
getSchemas($assetid, TRUE, FALSE);
1624 if (empty($schemas))
return FALSE;
1625 if ($stream_name === NULL) {
1630 if ($stream_name === NULL) {
1632 $stream_name =
'Default Stream';
1637 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1638 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1640 $workflow_names = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($schemas);
1642 foreach ($schemas as $schemaid) {
1646 $workflow[
'schema_name'] = $workflow_names[$schemaid][
'name'];
1648 $stream_names = $this->
getStreams($schemaid);
1649 $workflow[
'stream_assetid'] = $streams[$schemaid];
1650 $workflow[
'stream_name'] = $stream_names[$streams[$schemaid]];
1651 if (empty($workflow[
'steps']))
continue;
1652 $new_workflow = serialize($workflow);
1655 '.SQ_TABLE_RUNNING_PREFIX.
'ast_wflow
1658 last_started_by = :last_started_by
1661 AND schemaid = :schemaid';
1666 'wflow' => $new_workflow,
1667 'assetid' => $assetid,
1668 'schemaid' => $schemaid,
1669 'last_started_by' => $workflow[
'started_by'],
1671 foreach ($bind_vars as $bind_name => $bind_value){
1676 throw new Exception(
'Unable to update workflow table for asset: '.$assetid.
' due to database error: '.$e->getMessage());
1680 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1681 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1683 $this->_tmp = Array();
1685 if ($auto_approve) {
1690 $current_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1691 if (in_array($current_userid, $publishers)) {
1693 trigger_localised_error(
'SYS0078', E_USER_WARNING, $current_userid);
1707 $generic_msg = NULL;
1709 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
1711 foreach ($schema_workflows as $schemaid => $schema_workflow) {
1717 if (is_null($base_msg)) {
1718 if (empty($publishers)) {
1722 $msg = $ms->newMessage();
1726 $msg = clone $base_msg;
1727 if (empty($msg->to) && empty($msg->type) && empty($publishers)) {
1733 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid,
'workflow_schema');
1734 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
1735 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
1737 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1739 if ($schema->attr(
'schema_from_email_address') !=
'') {
1740 $msg->from = $schema->attr(
'schema_from_email_address');
1744 $msg->to = array_merge($msg->to, $publishers);
1746 if (empty($msg->replacements)) {
1747 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
1749 $workflow_backend_href = $asset->getBackendHref(
'workflow', FALSE);
1750 if (!empty($workflow_backend_href) && substr($workflow_backend_href, 0, 2) !=
'./') {
1751 $workflow_backend_href =
'/'.$workflow_backend_href;
1754 $accept_url = $workflow_backend_href.
'&asset_version='.$asset->version.
'&workflow_link_action=approve';
1755 $reject_url = $workflow_backend_href.
'&asset_version='.$asset->version.
'&workflow_link_action=reject';
1759 'workflow_user' => $user->name,
1760 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name'),
1761 'asset_name' => $asset->name,
1762 'assetid' => $asset->id,
1763 'workflow_url' => current_url().$workflow_backend_href,
1764 'accept_url' => current_url().$accept_url,
1765 'reject_url' => current_url().$reject_url,
1766 'previous_step_id' =>
'',
1767 'previous_step_name' =>
'',
1768 'current_step_id' => implode(
'.', $schema_workflow[
'current_step']),
1769 'current_step_name' => $current_step[
'step_name'],
1770 'stream' => $schema_workflow[
'stream_name'],
1771 'asset_url' => $asset->getDependantParentsURL(),
1772 'asset_version' => $asset->version,
1773 'log_message' =>
'',
1775 $asset_edt_fns = $asset->getEditFns();
1776 if (isset($asset_edt_fns->static_screens[
'preview'])) {
1777 $preview_backend_href = $asset->getBackendHref(
'preview', FALSE);
1778 if (!empty($preview_backend_href) && substr($preview_backend_href, 0, 2) !=
'./') {
1779 $preview_backend_href =
'/'.$preview_backend_href;
1781 $msg_reps[
'preview_url'] = current_url().$preview_backend_href;
1783 $details_backend_href = $asset->getBackendHref(
'preview', FALSE);
1784 if (!empty($details_backend_href) && substr($details_backend_href, 0, 2) !=
'./') {
1785 $details_backend_href =
'/'.$details_backend_href;
1787 $msg_reps[
'preview_url'] = current_url().$details_backend_href;
1789 $msg->replacements = $msg_reps;
1792 if (isset($current_step[
'message_invitation']) && trim($current_step[
'message_invitation']) !==
'' ) {
1794 $subject = trim(array_get_index($current_step,
'subject_invitation',
'Workflow Approval Required'));
1795 $msg->subject = (!empty($subject)) ? $subject :
'Workflow Approval Required';
1796 $msg->body = trim($current_step[
'message_invitation']);
1797 }
else if (isset($current_step[
'subject_invitation']) && trim($current_step[
'subject_invitation']) !==
'') {
1799 $subject = trim(array_get_index($current_step,
'subject_invitation',
'Workflow Approval Required'));
1800 $msg->subject = (!empty($subject)) ? $subject :
'Workflow Approval Required';
1804 if ($generic_msg === NULL) {
1805 $generic_msg = $msg;
1807 $generic_msg->to = array_merge($generic_msg->to, $msg->to);
1813 if (empty($msg->type)) {
1814 $msg->type =
'asset.workflow.invitation';
1815 }
else if ($msg->type ==
'asset.workflow.review'){
1817 if (isset($current_step[
'message_review_invitation']) && trim($current_step[
'message_review_invitation']) !==
'' ) {
1818 $msg->body = trim($current_step[
'message_review_invitation']);
1822 if (isset($current_step[
'subject_review_invitation']) && trim($current_step[
'subject_review_invitation']) !==
'' ) {
1823 $subject = trim(array_get_index($current_step,
'subject_review_invitation',
'Asset Up For Review'));
1824 $msg->subject = (!empty($subject)) ? $subject :
'Asset Up For Review';
1830 $msg->parameters[
'assetid'] = $asset->id;
1831 $ms->enqueueMessage($msg);
1850 $running_schemas = $this->
getSchemas($assetid, TRUE, TRUE);
1851 if (empty($running_schemas))
return TRUE;
1854 foreach ($schema_workflows as $schemaid => $workflow) {
1855 if (!in_array($schemaid, $running_schemas))
continue;
1856 if (empty($workflow[
'steps']))
continue;
1857 if (!$workflow[
'complete'])
return FALSE;
1875 $running_schemas = $this->
getSchemas($assetid, TRUE, TRUE);
1876 if (empty($running_schemas))
return Array();
1880 foreach ($schema_workflows as $schemaid => $workflow) {
1881 if (!in_array($schemaid, $running_schemas))
continue;
1882 if (empty($workflow[
'steps']))
continue;
1883 $steps[$schemaid] = $workflow[
'current_step'];
1903 $assetid = (int) $assetid;
1904 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1905 if (is_null($asset)) {
1906 trigger_localised_error(
'SYS0146', E_USER_WARNING, $assetid);
1914 $workflow = reset($workflow_values);
1915 $started_by = $workflow[
'started_by'];
1916 $started_by_user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($started_by,
'', TRUE);
1917 if ($started_by_user){
1920 if ($started_by_user instanceof
Simple_Edit_User) $started_by_user->_tmp[
'starter_of_workflow'] = TRUE;
1922 $publishers = array_unique(array_merge($publishers, Array($started_by)));
1929 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
1932 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_workflow_rejection', $asset);
1933 $generic_msg = NULL;
1937 $comments = $ms->getMessages(0,
'asset.workflow.userlog', Array(), Array(), $workflow[
'started'], NULL,
'name', Array(
'assetid' => $asset->id));
1938 foreach ($comments as $comment) {
1939 $log_message .=
'"'.$comment[
'body'].
'"'.
', by '.$comment[
'from_name'].
', '.ts_iso8601($comment[
'sent']).
"\n";
1942 foreach ($current_steps as $schemaid => $current_step_num) {
1943 $current_step = $this->
getCurrentStep($workflow_values[$schemaid], $current_step_num);
1947 if (is_null($base_msg)) {
1948 if (empty($publishers)) {
1952 $msg = $ms->newMessage();
1955 $msg = clone $base_msg;
1956 if (empty($msg->to) && empty($msg->type) && empty($publishers)) {
1962 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid,
'workflow_schema');
1963 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
1964 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
1966 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1968 if ($schema->attr(
'schema_from_email_address') !=
'') {
1969 $msg->from = $schema->attr(
'schema_from_email_address');
1975 $msg->to = array_merge($msg->to, $publishers);
1978 if (empty($msg->replacements)) {
1979 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
1981 'workflow_user' => $user->name,
1982 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name'),
1983 'asset_name' => $asset->name,
1984 'assetid' => $asset->id,
1985 'workflow_url' => current_url().$asset->getBackendHref(
'workflow', FALSE),
1986 'asset_url' => $asset->getDependantParentsURL(),
1987 'asset_version' => $asset->version,
1988 'log_message' => $log_message,
1990 $asset_edt_fns = $asset->getEditFns();
1991 if (isset($asset_edt_fns->static_screens[
'preview'])) {
1992 $msg_reps[
'preview_url'] = current_url().$asset->getBackendHref(
'preview', FALSE);
1994 $msg_reps[
'preview_url'] = current_url().$asset->getBackendHref(
'details', FALSE);
1996 $msg->replacements = $msg_reps;
1999 if (isset($current_step[
'message_reject']) && trim($current_step[
'message_reject']) !==
'' ) {
2000 $subject = trim(array_get_index($current_step,
'subject_reject',
'Asset Changes Rejected'));
2001 $msg->subject = (!empty($subject)) ? $subject :
'Asset Changes Rejected';
2002 $msg->body = trim($current_step[
'message_reject']);
2003 }
else if (isset($current_step[
'subject_reject']) && trim($current_step[
'subject_reject']) !==
'') {
2004 $subject = trim(array_get_index($current_step,
'subject_reject',
'Asset Changes Rejected'));
2005 $msg->subject = (!empty($subject)) ? $subject :
'Asset Changes Rejected';
2009 if ($generic_msg === NULL) {
2010 $generic_msg = $msg;
2012 $generic_msg->to = array_merge($generic_msg->to, $msg->to);
2017 if (empty($msg->type)) {
2018 $msg->type =
'asset.workflow.announce.reject';
2019 }
else if ($msg->type ==
'asset.workflow.review.cancel'){
2021 if (isset($current_step[
'message_review_cancel']) && trim($current_step[
'message_review_cancel']) !==
'' ) {
2022 $subject = trim(array_get_index($current_step,
'subject_review_cancel',
'Asset Review Cancelled'));
2023 $msg->subject = (!empty($subject)) ? $subject :
'Asset Review Cancelled';
2024 $msg->body = trim($current_step[
'message_review_cancel']);
2025 }
else if (isset($current_step[
'subject_review_cancel']) && trim($current_step[
'subject_review_cancel']) !==
'') {
2026 $subject = trim(array_get_index($current_step,
'subject_review_cancel',
'Asset Review Cancelled'));
2027 $msg->subject = (!empty($subject)) ? $subject :
'Asset Review Cancelled';
2031 if ($generic_msg === NULL) {
2032 $generic_msg = $msg;
2034 $generic_msg->to = array_merge($generic_msg->to, $msg->to);
2041 $msg->parameters[
'assetid'] = $asset->id;
2042 $ms->enqueueMessage($msg);
2063 $assetid = (int) $assetid;
2064 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2065 if (is_null($asset)) {
2066 trigger_localised_error(
'SYS0150', E_USER_WARNING, $assetid);
2085 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2086 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2093 assetid = :assetid';
2100 throw new Exception (
'Unable to clear workflow for asset: '.$assetid.
' due to database error: '.$e->getMessage());
2103 unset($this->_tmp[
'schemas'][$assetid]);
2104 unset($this->_tmp[
'schema_workflows'][$assetid]);
2106 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2107 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2124 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2125 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2129 'assetid' => (
string)$assetid,
2133 throw new Exception (
'Unable to purge workflow schema for "'.$asset->name.
'" (#'.$asset->id.
') due to database error: '.$e->getMessage());
2136 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2137 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2159 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
int) $assetid);
2160 if (is_null($asset))
return TRUE;
2161 $edit_fns = $asset->getEditFns();
2162 return !isset($edit_fns->static_screens[
'workflow']);
2180 $assetid = (int) $assetid;
2181 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2182 if (is_null($asset)) {
2183 trigger_localised_error(
'SYS0160', E_USER_WARNING, $assetid);
2187 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
2189 $workflow =& $schema_workflows[$schemaid];
2193 $comments = $ms->getMessages(0,
'asset.workflow.userlog', Array(), Array(), $workflow[
'started'], NULL,
'name', Array(
'assetid' => $asset->id));
2194 foreach ($comments as $comment) {
2195 $log_message .=
'"'.$comment[
'body'].
'"'.
', by '.$comment[
'from_name'].
', '.ts_iso8601($comment[
'sent']).
"\n";
2202 $step_before = $current_step;
2203 $step_before_id = $workflow[
'current_step'];
2207 $current_step[
'expired'] = TRUE;
2210 if (empty($current_step[
'escalation_steps'])) {
2211 $current_step[
'completed'] = time();
2217 if ($workflow[
'current_step'] == Array()) {
2220 $hrefs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetBackendHref(Array($assetid =>
'workflow'), FALSE);
2221 $href = str_replace(
'./',
'', current($hrefs));
2222 $root_urls = explode(
"\n", SQ_CONF_SYSTEM_ROOT_URLS);
2223 $url =
'http://'.current($root_urls).
'/'.$href;
2224 $type =
'asset.workflow.stale';
2225 $admins = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($assetid, SQ_PERMISSION_ADMIN, TRUE, FALSE, TRUE);
2230 'asset_name' => $asset->attr(
'name'),
2231 'assetid' => $assetid,
2232 'step_id' => implode(
'.', $step_before_id),
2233 'step_name' => $current_step[
'step_name'],
2234 'schema' => $workflow[
'schema_name'],
2235 'stream' => $workflow[
'stream_name'],
2236 'started_time' => easy_datetime($current_step[
'started']),
2237 'expiry_time' => easy_time_total($current_step[
'expiry_time']),
2238 'workflow_url' => $url,
2239 'asset_url' => $asset->getDependantParentsURL(),
2240 'asset_version' => $asset->version,
2241 'log_message' => $log_message,
2245 if (empty($admins)) $admins = Array(0);
2247 $msg = $ms->newMessage($admins, $type, $msg_reps);
2250 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid,
'workflow_schema');
2251 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
2252 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
2254 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
2256 if ($schema->attr(
'schema_from_email_address') !=
'') {
2257 $msg->from = $schema->attr(
'schema_from_email_address');
2261 if (isset($current_step[
'message_stale']) && trim($current_step[
'message_stale']) !==
'' ) {
2262 $msg->body = trim($current_step[
'message_stale']);
2266 if (isset($current_step[
'subject_stale']) && trim($current_step[
'subject_stale']) !==
'' ) {
2267 $subject = trim(array_get_index($current_step,
'subject_stale',
'Stale Workflow Step'));
2268 $msg->subject = (!empty($subject)) ? $subject :
'Stale Workflow Step';
2271 $msg->parameters[
'assetid'] = $asset->id;
2273 $ms->enqueueMessage($msg);
2280 if (!$current_step[
'started']) {
2281 $current_step[
'started'] = time();
2285 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2286 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2288 $new_workflow = serialize($workflow);
2291 'wflow' => $new_workflow,
2292 'assetid' => $assetid,
2293 'schemaid' => $schemaid,
2296 }
catch (Exception $e) {
2297 throw new Exception(
'Unable to update workflow table for asset: '.$assetid.
' due to database error: '.$e->getMessage());
2300 $this->_tmp[
'schema_workflows'][$assetid][$schemaid] = $workflow;
2301 if (isset($this->_tmp[
'schema_workflows'][$assetid][
'all'][$schemaid])) {
2302 $this->_tmp[
'schema_workflows'][$assetid][
'all'][$schemaid] = $workflow;
2307 $asset_type = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name');
2308 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
2310 $log = $ms->newMessage();
2312 $url_parts = explode(
'://' , $asset->getURL());
2314 if (count($url_parts) > 1) {
2315 $site_url = $GLOBALS[
'SQ_SYSTEM']->am->getRootURL($url_parts[1]);
2316 $root_url = $url_parts[0].
'://'.$site_url[
'url'];
2319 $hrefs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetBackendHref(Array($assetid =>
'workflow'), FALSE);
2320 $href = str_replace(
'./',
'', current($hrefs));
2321 $root_urls = explode(
"\n", SQ_CONF_SYSTEM_ROOT_URLS);
2322 $root_url =
'http://'.current($root_urls).
'/'.$href;
2326 'workflow_user' => $user->name,
2327 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name'),
2328 'asset_name' => $asset->name,
2329 'workflow_url' => $root_url.
'/'.$asset->getBackendHref(
'workflow', FALSE),
2330 'assetid' => $assetid,
2331 'previous_step_id' => implode(
'.', $step_before_id),
2332 'previous_step_name' => $step_before[
'step_name'],
2333 'current_step_id' => implode(
'.', $workflow[
'current_step']),
2334 'current_step_name' => $current_step[
'step_name'],
2335 'schema' => $workflow[
'schema_name'],
2336 'stream' => $workflow[
'stream_name'],
2337 'started_time' => easy_datetime($step_before[
'started']),
2338 'expiry_time' => easy_time_total($step_before[
'expiry_time']),
2339 'asset_url' => $asset->getDependantParentsURL(),
2340 'asset_version' => $asset->version,
2341 'log_message' => $log_message,
2345 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid,
'workflow_schema');
2346 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
2347 $log->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
2349 $log->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
2351 if ($schema->attr(
'schema_from_email_address') !=
'') {
2352 $log->from = $schema->attr(
'schema_from_email_address');
2355 $log->replacements = $msg_reps;
2356 $log->type =
'asset.workflow.log.escalated';
2358 $log->parameters[
'assetid'] = $asset->id;
2359 $log->parameters[
'version'] = substr($asset->version, 0, strrpos($asset->version,
'.'));
2360 $ms->enqueueMessage($log);
2366 $msg = $ms->newMessage($publishers_before);
2368 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
2369 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
2371 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
2373 if ($schema->attr(
'schema_from_email_address') !=
'') {
2374 $msg->from = $schema->attr(
'schema_from_email_address');
2377 $msg->type =
'asset.workflow.announce.escalated';
2378 $msg->parameters[
'assetid'] = $asset->id;
2379 $msg->replacements = $msg_reps;
2382 if (isset($step_before[
'message_escalated']) && trim($step_before[
'message_escalated']) !==
'' ) {
2383 $msg->body = trim($step_before[
'message_escalated']);
2387 if (isset($step_before[
'subject_escalated']) && trim($step_before[
'subject_escalated']) !==
'' ) {
2388 $subject = trim(array_get_index($step_before,
'subject_escalated',
'Workflow Escalated'));
2389 $msg->subject = (!empty($subject)) ? $subject :
'Workflow Escalated';
2393 $ms->enqueueMessage($msg);
2398 $url_parts = explode(
'://' , $asset->getURL());
2399 if (count($url_parts) > 1) {
2400 $site_url = $GLOBALS[
'SQ_SYSTEM']->am->getRootURL($url_parts[1]);
2401 $root_url = $url_parts[0].
'://'.$site_url[
'url'];
2404 $hrefs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetBackendHref(Array($assetid =>
'workflow'), FALSE);
2405 $href = str_replace(
'./',
'', current($hrefs));
2406 $root_urls = explode(
"\n", SQ_CONF_SYSTEM_ROOT_URLS);
2407 $root_url =
'http://'.current($root_urls).
'/'.$href;
2410 if ($asset->status == SQ_STATUS_LIVE_APPROVAL){
2411 $msg = $ms->newMessage($publishers);
2414 'workflow_user' => $user->name,
2415 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name'),
2416 'asset_name' => $asset->name,
2417 'assetid' => $asset->id,
2418 'workflow_url' => $root_url.
'/'.$asset->getBackendHref(
'workflow', FALSE),
2421 $asset_edt_fns = $asset->getEditFns();
2422 if (isset($asset_edt_fns->static_screens[
'preview'])) {
2423 $msg_reps[
'preview_url'] = $root_url.
'/'.$asset->getBackendHref(
'preview', FALSE);
2425 $msg_reps[
'preview_url'] = $root_url.
'/'.$asset->getBackendHref(
'details', FALSE);
2428 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
2429 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
2431 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
2433 if ($schema->attr(
'schema_from_email_address') !=
'') {
2434 $msg->from = $schema->attr(
'schema_from_email_address');
2437 $msg->type =
'asset.workflow.review';
2438 $msg->parameters[
'assetid'] = $asset->id;
2441 if (isset($current_step[
'message_review_invitation']) && trim($current_step[
'message_review_invitation']) !==
'' ) {
2442 $msg->body = trim($current_step[
'message_review_invitation']);
2446 if (isset($current_step[
'subject_review_invitation']) && trim($current_step[
'subject_review_invitation']) !==
'' ) {
2447 $subject = trim(array_get_index($current_step,
'subject_review_invitation',
'Asset Up For Review'));
2448 $msg->subject = (!empty($subject)) ? $subject :
'Asset Up For Review';
2451 $msg->replacements = $msg_reps;
2453 $ms->enqueueMessage($msg);
2457 $msg = $ms->newMessage($publishers);
2459 $workflow_backend_href = $asset->getBackendHref(
'workflow', FALSE);
2460 $accept_url = $workflow_backend_href.
'&asset_version='.$asset->version.
'&workflow_link_action=approve';
2461 $reject_url = $workflow_backend_href.
'&asset_version='.$asset->version.
'&workflow_link_action=reject';
2464 'workflow_user' => $user->name,
2465 'type_code' => $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->type(),
'name'),
2466 'asset_name' => $asset->name,
2467 'assetid' => $asset->id,
2468 'previous_step_id' => implode(
'.',$step_before_id),
2469 'previous_step_name' => $step_before[
'step_name'],
2470 'current_step_id' => implode(
'.',$workflow[
'current_step']),
2471 'current_step_name' => $current_step[
'step_name'],
2472 'stream' => $workflow[
'stream_name'],
2473 'workflow_url' => $root_url.
'/'.$workflow_backend_href,
2474 'accept_url' => $root_url.
'/'.$accept_url,
2475 'reject_url' => $root_url.
'/'.$reject_url,
2476 'asset_url' => $asset->getDependantParentsURL(),
2477 'asset_version' => $asset->version,
2478 'log_message' => $log_message,
2481 $asset_edt_fns = $asset->getEditFns();
2482 if (isset($asset_edt_fns->static_screens[
'preview'])) {
2483 $msg_reps[
'preview_url'] = $root_url.
'/'.$asset->getBackendHref(
'preview', FALSE);
2485 $msg_reps[
'preview_url'] = $root_url.
'/'.$asset->getBackendHref(
'details', FALSE);
2488 if ($schema->attr(
'schema_reply_to_email_address') !=
'') {
2489 $msg->parameters[
'reply_to'] = $schema->attr(
'schema_reply_to_email_address');
2491 $msg->parameters[
'reply_to'] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
2493 if ($schema->attr(
'schema_from_email_address') !=
'') {
2494 $msg->from = $schema->attr(
'schema_from_email_address');
2497 $msg->type =
'asset.workflow.invitation.progress';
2498 $msg->parameters[
'assetid'] = $asset->id;
2501 if (isset($current_step[
'message_invitation']) && trim($current_step[
'message_invitation']) !==
'' ) {
2502 $msg->body = trim($current_step[
'message_invitation']);
2506 if (isset($current_step[
'subject_invitation']) && trim($current_step[
'subject_invitation']) !==
'' ) {
2507 $subject = trim(array_get_index($current_step,
'subject_invitation',
'Workflow Approval Required'));
2508 $msg->subject = (!empty($subject)) ? $subject :
'Workflow Approval Required';
2511 $msg->replacements = $msg_reps;
2513 $ms->enqueueMessage($msg);
2517 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2518 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2537 if ($current_step == NULL) {
2538 $current_step = $workflow[
'current_step'];
2541 array_pop($current_step);
2542 $steps =& $workflow[
'steps'];
2543 foreach ($current_step as $step_id) {
2544 $steps =& $steps[$step_id][
'escalation_steps'];
2562 if ($current_step == NULL) {
2563 $current_step = $workflow[
'current_step'];
2567 return $steps[end($current_step)];
2585 $stream_names = Array();
2586 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetExists($schemaid)) {
2587 trigger_error(
"Workflow Schema Id #$schemaid is applied to this asset but cannot be found in system anymore.", E_USER_WARNING);
2588 return $stream_names;
2590 $stream_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($schemaid, SQ_LINK_TYPE_2,
'workflow_stream', FALSE);
2591 $streamids = Array();
2593 foreach ($stream_links as $stream_link) {
2594 if (($ignore_default === FALSE) || ($stream_link[
'value'] !==
'default_stream')) {
2595 $streamids[] = $stream_link[
'minorid'];
2599 $stream_names = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($streamids,
'workflow_stream', TRUE,
'name');
2600 return $stream_names;
2615 if ($current_userid === NULL) {
2616 $current_userid = $GLOBALS[
'SQ_SYSTEM']->user->id;
2619 $bypassable_streams = Array();
2621 foreach ($streams as $streamid => $stream_name) {
2622 $test_result = $this->
testPublish($assetid, $current_userid, $stream_name);
2623 if ($test_result === TRUE) {
2624 $bypassable_streams[] = $streamid;
2628 return $bypassable_streams;
2647 $return_array = TRUE;
2648 if (is_array($schemaids) === FALSE) {
2649 $return_array = FALSE;
2650 $schemaids = Array($schemaids);
2653 $return_value = Array();
2654 foreach ($schemaids as $schemaid) {
2655 $stream_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($schemaid, SQ_LINK_TYPE_2,
'workflow_stream', FALSE,
'default_stream');
2657 if (empty($stream_link) === FALSE) {
2658 $return_value[$schemaid] = $stream_link[
'minorid'];
2662 if ($return_array === FALSE) {
2663 $return_value = reset($return_value);
2666 return $return_value;
2689 $return_array = TRUE;
2690 if (is_array($schemaids) === FALSE) {
2691 $return_array = FALSE;
2692 $schemaids = Array($schemaids);
2696 $return_value = Array();
2697 foreach ($schemaids as $schemaid) {
2698 $schema_stream_names = $this->
getStreams($schemaid);
2699 $found_streamid = array_search($stream_name, $schema_stream_names);
2700 if ($found_streamid !== FALSE) {
2701 $return_value[$schemaid] = $found_streamid;
2706 $unfound_streams = array_diff($schemaids, array_keys($return_value));
2707 if (count($unfound_streams) > 0) {
2709 $return_value += $unfound_streamids;
2712 if ($return_array === FALSE) {
2713 $return_value1 = reset($return_value);
2716 return $return_value;
2745 $this->_tmp[
'starting_streams'][$assetid] = $stream_name;
2759 $starting_streams = array_get_index($this->_tmp,
'starting_streams', Array());
2760 return array_get_index($starting_streams, $assetid, NULL);
2779 require_once SQ_FUDGE_PATH.
'/general/text.inc';
2780 $keywords = retrieve_keywords_replacements($subject);
2781 foreach ($keywords as $keyword) {
2782 if (isset($replacements[$keyword]))
continue;
2783 $replacement = $asset->getKeywordReplacement($keyword);
2784 if (!empty($replacement) && trim($replacement,
'%') != $keyword) $replacements[$keyword] = $replacement;
2787 $keywords = retrieve_keywords_replacements($body);
2788 foreach ($keywords as $keyword) {
2789 if (isset($replacements[$keyword]))
continue;
2790 $replacement = $asset->getKeywordReplacement($keyword);
2791 if (!empty($replacement) && trim($replacement,
'%') != $keyword) $replacements[$keyword] = $replacement;
2812 $schemas = $this->
getSchemas($assetid, TRUE, FALSE);
2814 $sql =
"UPDATE sq_ast_wflow
2815 SET last_started_by = :last_started_by
2816 WHERE schemaid = :schemaid AND assetid = :assetid";
2818 foreach ($schemas as $schemaid) {
2825 }
catch (Exception $e) {
2826 trigger_localised_error(
'CORE0320', E_USER_NOTICE, $assetid, $schemaid, $e->getMessage());