17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
52 public static function paintConfig(&$o, $class, $write_access)
55 $o->openField(translate(
'edit_status_threshold'));
58 text_box($class.
'[SQ_HIPO_EDIT_STATUS_THRESHOLD]', SQ_HIPO_EDIT_STATUS_THRESHOLD, 5);
60 echo SQ_HIPO_EDIT_STATUS_THRESHOLD;
62 echo
' '.translate(
'assets');
78 'SQ_HIPO_EDIT_STATUS_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
97 $running_dependants =
'';
98 if (!empty($this->_running_vars[
'process_dependants'])) {
99 $running_dependants =
'dependants';
101 return parent::getCodeName().$this->_running_vars[
'assetid'].$running_dependants;
114 return translate(
'hipo_name_edit_status');
130 'name' => translate(
'hipo_editing_status'),
131 'function_call' => Array(
132 'process_function' =>
'processStatus',
134 'running_mode' =>
'server',
136 'allow_cancel' => TRUE,
156 if (SQ_HIPO_EDIT_STATUS_THRESHOLD == 0)
return 0;
157 if (!isset($this->_running_vars[
'todo_assetids'])) {
161 return (((count($this->_running_vars[
'todo_assetids']) + 1) / SQ_HIPO_EDIT_STATUS_THRESHOLD) * 100);
176 if (!isset($this->_running_vars[
'assetid'])) {
177 trigger_localised_error(
'HIPO0012', E_USER_WARNING);
182 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'assetid']);
183 if (is_null($asset)) {
184 trigger_localised_error(
'HIPO0011', E_USER_WARNING, $this->_running_vars[
'assetid']);
188 if (!empty($this->_running_vars[
'process_dependants'])) {
191 $this->_running_vars[
'todo_assetids'] = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($asset->id);
192 $this->_running_vars[
'done_root'] = TRUE;
198 if (!isset($this->_running_vars[
'dependants_only']) || !empty($this->_running_vars[
'dependants_only'])) {
199 $this->_running_vars[
'dependants_only'] = FALSE;
200 $child_assets = Array();
203 $this->_running_vars[
'dependants_only'] = TRUE;
204 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($asset->id,
'', TRUE, FALSE);
207 foreach ($child_assets as $id => $asset) {
208 $id_parts = explode(
':', $id);
209 if(isset($id_parts[1])) {
210 unset($child_assets[$id]);
214 $this->_running_vars[
'todo_assetids'] = $child_assets;
215 $this->_running_vars[
'done_root'] = FALSE;
217 $this->_running_vars[
'done_assetids'] = Array();
220 if (!isset($this->_running_vars[
'messages']) || empty($this->_running_vars[
'messages'])) {
221 $this->_running_vars[
'messages'] = Array();
226 $to_do = array_keys($this->_running_vars[
'todo_assetids']);
227 if (empty($this->_running_vars[
'process_dependants'])) {
228 $to_do[] = $this->_running_vars[
'assetid'];
230 $this->_running_vars[
'current_asset_statuses'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($to_do,
'', TRUE,
'status');
232 return parent::prepare();
248 require_once SQ_INCLUDE_PATH.
'/internal_message.inc';
249 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
250 return parent::load($code_name);
269 parent::paint($o, $nested);
272 if (!empty($this->_running_vars[
'dependant_hipo_job'])) {
273 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
274 $hipo = $hh->getJob($this->_running_vars[
'dependant_hipo_job']);
275 if (!is_null($hipo)) {
276 $hipo->paint($o, TRUE);
278 unset($this->_running_vars[
'dependant_hipo_job']);
293 while (!empty($this->_running_vars[
'todo_assetids']) || !$this->_running_vars[
'done_root'] || !empty($this->_running_vars[
'dependant_hipo_job'])) {
294 if (!$this->
processStatus($this->_steps[0], get_class($this), TRUE)) {
318 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
321 if (!parent::processServer($step_data, $prefix)) {
347 $send_messages = array_get_index($this->_running_vars,
'send_messages', TRUE);
350 if (!empty($this->_running_vars[
'dependant_hipo_job'])) {
351 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
352 $hipo = $hh->getJob($this->_running_vars[
'dependant_hipo_job']);
355 if (is_null($hipo))
return FALSE;
357 if ($freestyle && $hipo->freestyle()) {
359 unset($this->_running_vars[
'dependant_hipo_job']);
362 $this->_running_vars[
'messages'] = array_get_index($hipo->_running_vars,
'messages', Array());
365 $hh->uncacheJob($hipo->code_name);
366 }
else if ($hipo->process() && $hipo->complete()) {
368 $running_vars = $hipo->getRunningVars();
369 if (isset($running_vars[
'assetid'])) {
370 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($running_vars[
'assetid']);
371 $asset->_updated(FALSE);
375 $this->_running_vars[
'messages'] = array_get_index($hipo->_running_vars,
'messages', Array());
377 unset($this->_running_vars[
'dependant_hipo_job']);
383 if ((empty($this->_running_vars[
'dependant_hipo_job']) === TRUE) && (empty($this->_running_vars[
'todo_assetids']) === TRUE)) {
384 $step_data[
'percent_done'] = 100;
385 $step_data[
'complete'] = TRUE;
391 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
397 if (!empty($this->_running_vars[
'todo_assetids']) || !$this->_running_vars[
'done_root']) {
398 if (empty($this->_running_vars[
'done_assetids']) && !$this->_running_vars[
'done_root']) {
401 $assetid = $this->_running_vars[
'assetid'];
402 $this->_running_vars[
'done_root'] = TRUE;
405 $tmp_keys = array_keys($this->_running_vars[
'todo_assetids']);
406 $assetid = $tmp_keys[0];
407 unset($this->_running_vars[
'todo_assetids'][$assetid]);
409 $new_status = $this->_running_vars[
'new_status'];
413 $current_status = array_get_index($this->_running_vars[
'current_asset_statuses'], $assetid, 0);
414 if (($current_status != $new_status) || ($current_status & SQ_SC_STATUS_PENDING)) {
415 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
416 if (!is_null($asset)) {
420 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($asset->id);
424 if ((($current_status & (SQ_SC_STATUS_CAN_APPROVE | SQ_STATUS_LIVE)) > 0) && (($new_status & SQ_SC_STATUS_PENDING) > 0)) {
425 if (array_get_index($this->_running_vars,
'workflow_stream') !== NULL) {
426 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
427 $wfm->setStartingStream($assetid, $this->_running_vars[
'workflow_stream']);
430 if (empty($dependants) || !empty($this->_running_vars[
'process_dependants'])) {
431 $asset->processStatusChange($new_status, FALSE);
433 $asset->processStatusChange($new_status, FALSE, FALSE);
435 $step_data[
'message'] = translate(
'hipo_edit_status', htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), $asset->id);
439 if (!empty($dependants) && empty($this->_running_vars[
'process_dependants'])) {
440 $messages = array_merge($this->_running_vars[
'messages'], $ms->queueContents());
442 $this->_running_vars[
'dependant_hipo_job'] = $code_name;
445 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
448 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
449 $this->
_addError(translate(
'hipo_cannot_edit_status', $assetid));
452 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
455 $this->_running_vars[
'done_assetids'][] = $assetid;
462 if(empty($this->_running_vars[
'process_dependants']) && isset($assetid)) {
463 $this->_running_vars[
'messages'] = array_merge($this->_running_vars[
'messages'], $ms->queueContents());
465 foreach($ms->queueContents() as $internal_message) {
466 $asset_id = $internal_message->parameters[
'assetid'];
467 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($asset_id,
'',TRUE,FALSE);
468 if(count($parents) > 1 ) {
469 $this->_running_vars[
'messages'][] = $internal_message;
477 if (empty($this->_running_vars[
'todo_assetids'])) {
480 if (empty($this->_running_vars[
'process_dependants']) && ($send_messages === TRUE) && isset($assetid)) {
483 $ms->send($this->_running_vars[
'messages']);
486 if (empty($this->_running_vars[
'dependant_hipo_job'])) {
488 $step_data[
'percent_done'] = 100;
489 $step_data[
'complete'] = TRUE;
493 $step_data[
'complete'] = FALSE;
496 $total = count($this->_running_vars[
'todo_assetids']) + count($this->_running_vars[
'done_assetids']);
497 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / $total) * 100;
498 $step_data[
'complete'] = FALSE;
518 $init_hipo =
new Hipo_Job_Edit_Status();
520 $options[
'auto_complete'] = TRUE;
525 $running_vars = Array(
526 'assetid' => $assetid,
527 'new_status' => $new_status,
528 'process_dependants' => TRUE,
529 'messages' => $messages,
532 if (array_key_exists(
'workflow_stream', $this->_running_vars) === TRUE) {
533 $running_vars[
'workflow_stream'] = $this->_running_vars[
'workflow_stream'];
536 $init_hipo->setRunningVars($running_vars);
537 foreach ($options as $k => $v) {
538 $init_hipo->setOption($k, $v);
543 $code_name = $init_hipo->initialise($this->source_code_name);
544 if ($code_name)
return $code_name;