18 require_once SQ_CORE_PACKAGE_PATH.
'/system/cron/cron_job/cron_job.inc';
19 require_once SQ_INCLUDE_PATH.
'/workflow_manager.inc';
20 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
49 parent::__construct($assetid);
67 require_once SQ_CORE_PACKAGE_PATH.
'/system/system_asset_fns.inc';
68 if (!system_asset_fns_create_pre_check($this)) {
71 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
72 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
74 if ($linkid = parent::create($link)) {
75 if (!system_asset_fns_create_cleanup($this)) {
81 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
83 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
86 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
103 return translate(
'cron_job_expired_workflow');
154 aw.assetid, aw.schemaid, aw.wflow , aw.granted , a.name
156 sq_ast_wflow aw, sq_ast a
158 aw.assetid = a.assetid
160 DBMS_LOB.GETLENGTH(aw.wflow) > 0
170 throw new Exception (
'Unable to get running workflows due to database error: '.$e->getMessage());
174 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
175 $last_run = $cm->attr(
'last_run');
177 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
179 foreach ($rows as $row) {
182 $workflow = unserialize($row[
'wflow']);
183 $schemaid = $row[
'schemaid'];
184 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
185 $step =& $wfm->getCurrentStep($workflow);
187 if (($step[
'started'] != 0) && ($step[
'expiry_time'] != 0)) {
188 $exp_time = $step[
'started'] + $step[
'expiry_time'];
190 if ($exp_time < $now) {
193 if ($step[
'escalate']) {
195 if (!$wfm->escalateWorkflow($row[
'assetid'], $schemaid)) {
196 trigger_localised_error(
'CRON0052', E_USER_WARNING, $schemaid, $assetid);
201 if ($exp_time > $last_run) {
210 $escalation_wf_msgs = Array();
211 foreach($ms->queueContents() as $queued_message) {
212 $ms_assetid = $queued_message->parameters[
'assetid'];
214 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($ms_assetid,
'', TRUE, FALSE);
215 foreach($parents as $key => $parentid) {
216 if ($ms_assetid == $parentid) {
217 unset($parents[$key]);
222 if(count($parents) > 1 || empty($parents)) {
223 $escalation_wf_msgs[] = $queued_message;
226 $dependant_workflows = $wfm->getSchemaWorkflows($parents[0]);
227 if (empty($dependant_workflows[$schemaid][
'steps']) || (isset($dependant_workflows[$schemaid][
'complete']) && $dependant_workflows[$schemaid][
'complete'])) {
228 $escalation_wf_msgs[] = $queued_message;
238 $ms->send($escalation_wf_msgs);
239 unset($escalation_wf_msgs);
243 return SQ_CRON_JOB_COMPLETED;
266 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
267 if ($wfm->silentWorkflowParty($assetid)) {
271 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
272 $subject =
'Stale Workflow Step';
273 $hrefs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetBackendHref(Array($assetid =>
'workflow'), FALSE);
274 $href = str_replace(
'./',
'', current($hrefs));
275 $root_urls = explode(
"\n", SQ_CONF_SYSTEM_ROOT_URLS);
276 $url =
'http://'.current($root_urls).
'/'.$href;
277 $type =
'asset.workflow.stale';
278 $admins = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($assetid, SQ_PERMISSION_ADMIN, TRUE, FALSE, TRUE);
280 $schema_workflows = $wfm->getSchemaWorkflows($assetid);
281 $workflow =& $schema_workflows[$schemaid];
282 $schema_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid);
283 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
287 'asset_name' => $asset_name,
288 'assetid' => $assetid,
289 'step_id' => implode(
'.', $workflow[
'current_step']),
290 'step_name' => $step_data[
'step_name'],
291 'schema' => $schema_name,
292 'started_time' => easy_datetime($step_data[
'started']),
293 'expiry_time' => easy_time_total($step_data[
'expiry_time']),
294 'workflow_url' => $url,
295 'asset_url' => $asset->getDependantParentsURL(),
299 if (empty($admins)) $admins = Array(0);
300 $msg = $ms->newMessage($admins, $type, $msg_reps);
301 $msg->parameters[
'assetid'] = $assetid;
304 if (isset($step_data[
'message_stale']) && trim($step_data[
'message_stale']) !==
'' ) {
305 $msg->body = trim($step_data[
'message_stale']);
309 if (isset($step_data[
'subject_stale']) && trim($step_data[
'subject_stale']) !==
'' ) {
310 $subject = trim(array_get_index($step_data,
'subject_stale',
'Stale Workflow Step'));
311 $msg->subject = (!empty($subject)) ? $subject :
'Stale Workflow Step';
314 if (!is_null($schema_asset)) {
315 if ($schema_asset->attr(
'schema_reply_to_email_address') !=
'') {
316 $msg->parameters[
'reply_to'] = $schema_asset->attr(
'schema_reply_to_email_address');
318 $msg->parameters[
'reply_to'] = $msg->from;
320 if ($schema_asset->attr(
'schema_from_email_address') !=
'') {
321 $msg->from = $schema_asset->attr(
'schema_from_email_address');
325 $wfm->addMessageReplacements($asset, $msg->subject, $msg->body, $msg->replacements);
326 $ms->enqueueMessage($msg);
328 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
345 $res = parent::run();
346 if ($res & SQ_CRON_JOB_REMOVE) {
347 $res = $res - SQ_CRON_JOB_REMOVE;