17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
52 public static function paintConfig(&$o, $class, $write_access)
55 $o->openField(translate(
'workflow_schemas_threshold'));
58 text_box($class.
'[SQ_HIPO_WORKFLOW_SCHEMAS_THRESHOLD]', SQ_HIPO_WORKFLOW_SCHEMAS_THRESHOLD, 5);
59 echo
' '.translate(
'assets');
60 $o->note(translate(
'hipo_value_divided_by_schema'));
62 echo SQ_HIPO_WORKFLOW_SCHEMAS_THRESHOLD;
63 echo
' '.translate(
'assets');
80 'SQ_HIPO_WORKFLOW_SCHEMAS_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
99 return parent::getCodeName().
'-'.md5(serialize($this->_running_vars[
'schema_changes']));
112 return translate(
'hipo_name_edit_workflow_schemas');
128 'name' => translate(
'hipo_updating_workflow_schemas'),
129 'function_call' => Array(
130 'process_function' =>
'processSchemas',
132 'running_mode' =>
'server',
134 'allow_cancel' =>
true,
155 if (SQ_HIPO_WORKFLOW_SCHEMAS_THRESHOLD == 0)
return 0;
156 if (!isset($this->_running_vars[
'todo_assetids'])) {
159 return ($this->_running_vars[
'total_changes'] / SQ_HIPO_WORKFLOW_SCHEMAS_THRESHOLD) * 100;
172 while (!empty($this->_running_vars[
'todo_assetids'])) {
191 if (empty($this->_running_vars[
'schema_changes'])) {
192 trigger_localised_error(
'HIPO0010', E_USER_WARNING);
196 $this->_running_vars[
'done_changes'] = 0;
197 $this->_running_vars[
'total_changes'] = 0;
199 if (empty($this->_running_vars[
'schema_changes'])) {
201 $this->_running_vars[
'todo_assetids'] = Array();
203 $this->_running_vars[
'todo_assetids'] = Array();
204 foreach ($this->_running_vars[
'schema_changes'] as $schema_change) {
205 $assetids = $schema_change[
'assetids'];
206 foreach ($assetids as $assetid) {
207 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
209 if (is_null($asset)) {
210 trigger_localised_error(
'HIPO0009', E_USER_WARNING, $assetid);
214 if ((!array_get_index($schema_change,
'cascades')) || array_get_index($schema_change,
'dependants_only')) {
215 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
217 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid);
221 $child_assets[$assetid] = Array (
223 'type_code' => $asset->type(),
227 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
229 foreach ($child_assets as $child_assetid => $child_asset) {
230 if (!$wfm->allowsWorkflow($child_assetid)) {
233 $type_code = $child_asset[0][
'type_code'];
235 $this_todo =& $this->_running_vars[
'todo_assetids'][$child_assetid];
236 $this_todo[
'type_code'] = $type_code;
237 $this_todo[
'schema_changes'][] = $schema_change;
238 $this->_running_vars[
'total_changes']++;
247 return parent::prepare();
263 if (!empty($this->_running_vars[
'todo_assetids'])) {
264 reset($this->_running_vars[
'todo_assetids']);
265 $assetid = key($this->_running_vars[
'todo_assetids']);
266 $asset_type = $this->_running_vars[
'todo_assetids'][$assetid][
'type_code'];
267 $schema_changes = $this->_running_vars[
'todo_assetids'][$assetid][
'schema_changes'];
268 unset($this->_running_vars[
'todo_assetids'][$assetid]);
270 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
272 if (!is_null($asset)) {
273 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($assetid,
'workflow')) {
274 foreach ($schema_changes as $set_data) {
275 $this->_running_vars[
'done_changes']++;
277 if ($set_data[
'schemaid']) {
278 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($set_data[
'schemaid']);
279 if (is_null($schema)) {
280 $schema_name =
'Unknown Schema';
282 $schema_name = $schema->name;
288 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
290 if ($set_data[
'previous_access'] === null) {
293 $schemas = $wfm->getSchemas($asset->id, $set_data[
'granted']);
294 if (isset($schemas[$set_data[
'schemaid']])) {
295 $new_access = ($set_data[
'granted']) ? translate(
'apply') : translate(
'deny');
296 $current_access = ($schemas[$set_data[
'schemaid']]) ? translate(
'applied') : translate(
'denied');
297 $this->
_addError(translate(
'hipo_cannot_modify_schema', $new_access, $schema_name, $asset->name, $current_access),
true);
302 $schemas = $wfm->getSchemas($asset->id);
304 if (!isset($schemas[$set_data[
'schemaid']])) {
306 }
else if ($schemas[$set_data[
'schemaid']] != $set_data[
'previous_access']) {
307 $new_access = ($set_data[
'previous_access']) ? translate(
'revoke') : translate(
'apply');
308 $current_access = ($set_data[
'previous_access']) ? translate(
'applied') : translate(
'denied');
309 $this->
_addError(translate(
'hipo_cannot_modify_schema', $new_access, $schema_name, $asset->name, $current_access),
true);
314 switch ($set_data[
'granted']) {
317 $step_data[
'message'] = htmlentities(
'Deleting "'.$schema->name.
'" (#'.$schema->id.
') from "'.$asset->name.
'" (#'.$asset->id.
')', ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
318 $wfm->deleteSchema($asset->id, $set_data[
'schemaid']);
325 $step_data[
'message'] = htmlentities(($set_data[
'granted'] ?
'Apply' :
'Deny').
'ing "'.$schema->name.
'" (#'.$schema->id.
') to "'.$asset->name.
'" (#'.$asset->id.
')', ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
326 $wfm->setSchema($asset->id, $set_data[
'schemaid'], $set_data[
'granted'], $set_data[
'cascades']);
333 if (count($schema_changes) > 1) {
334 $step_data[
'message'] = htmlentities(
'Making '.count($schema_changes).
' schema changes to '.$asset->name.
' (Id: #'.$asset->id.
')', ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
335 }
else if (count($schema_changes) == 0) {
336 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
339 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'workflow');
340 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
344 trigger_localised_error(
'SYS0100', E_USER_WARNING, $asset->name);
348 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
349 $this->
_addError(translate(
'hipo_cannot_edit_schema', $assetid));
353 if (empty($this->_running_vars[
'todo_assetids'])) {
354 $step_data[
'percent_done'] = 100;
355 $step_data[
'complete'] = TRUE;
357 $step_data[
'percent_done'] = ($this->_running_vars[
'done_changes'] / $this->_running_vars[
'total_changes']) * 100;
358 $step_data[
'complete'] = FALSE;