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_metadata_threshold'));
58 text_box($class.
'[SQ_HIPO_METADATA_THRESHOLD]', SQ_HIPO_METADATA_THRESHOLD, 5);
59 echo
' '.translate(
'assets');
60 $o->note(translate(
'hipo_value_divided_by_schema'));
62 echo SQ_HIPO_METADATA_THRESHOLD;
63 echo
' '.translate(
'assets');
80 'SQ_HIPO_METADATA_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
99 return parent::getCodeName().
'-'.md5(serialize($this->_running_vars[
'schema_changes']));
112 return translate(
'hipo_name_edit_metadata_schemas');
128 'name' => translate(
'hipo_updating_metadata_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(
'HIPO0017', E_USER_WARNING);
196 $this->_running_vars[
'done_changes'] = 0;
197 $this->_running_vars[
'total_changes'] = 0;
198 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
200 if (empty($this->_running_vars[
'schema_changes'])) {
202 $this->_running_vars[
'todo_assetids'] = Array();
204 $this->_running_vars[
'todo_assetids'] = Array();
205 foreach ($this->_running_vars[
'schema_changes'] as $schema_change) {
206 $assetids = $schema_change[
'assetids'];
207 foreach ($assetids as $assetid) {
208 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
210 if (is_null($asset)) {
211 trigger_localised_error(
'HIPO0016', E_USER_WARNING, $assetid);
215 if ($schema_change[
'cascades']) {
216 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid);
218 $child_assets = Array();
222 $child_assets[$assetid] = Array (
224 'type_code' => $asset->type(),
228 foreach ($child_assets as $assetid => $asset_info) {
232 if (!$mm->allowsMetadata($assetid)) {
233 unset($child_assets[$assetid]);
238 foreach ($child_assets as $child_assetid => $child_asset) {
239 $type_code = $child_asset[0][
'type_code'];
241 $this_todo =& $this->_running_vars[
'todo_assetids'][$child_assetid];
242 $this_todo[
'type_code'] = $type_code;
243 $this_todo[
'schema_changes'][] = $schema_change;
244 $this->_running_vars[
'total_changes']++;
253 return parent::prepare();
269 if (!empty($this->_running_vars[
'todo_assetids'])) {
270 reset($this->_running_vars[
'todo_assetids']);
271 $assetid = key($this->_running_vars[
'todo_assetids']);
272 $asset_type = $this->_running_vars[
'todo_assetids'][$assetid][
'type_code'];
273 $schema_changes = $this->_running_vars[
'todo_assetids'][$assetid][
'schema_changes'];
274 unset($this->_running_vars[
'todo_assetids'][$assetid]);
276 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
277 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
279 if (!is_null($asset)) {
280 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($assetid,
'metadata')) {
281 foreach ($schema_changes as $set_data) {
282 $this->_running_vars[
'done_changes']++;
284 if ($set_data[
'schemaid']) {
285 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($set_data[
'schemaid']);
286 if (is_null($schema)) {
287 $schema_name =
'Unknown Schema';
289 $schema_name = $schema->name;
295 if ($set_data[
'previous_access'] === NULL) {
298 $schemas = $mm->getSchemas($asset->id, $set_data[
'granted']);
299 if (isset($schemas[$set_data[
'schemaid']])) {
300 $new_access = ($set_data[
'granted']) ? translate(
'apply') : translate(
'deny');
301 $current_access = ($schemas[$set_data[
'schemaid']]) ? translate(
'applied') : translate(
'denied');
302 $this->
_addError(translate(
'hipo_cannot_modify_schema', $new_access, $schema_name, $asset->name, $current_access), TRUE);
307 $schemas = $mm->getSchemas($asset->id);
308 if (!isset($schemas[$set_data[
'schemaid']])) {
310 }
else if ($schemas[$set_data[
'schemaid']] != $set_data[
'previous_access']) {
311 $new_access = ($set_data[
'previous_access']) ? translate(
'revoke') : translate(
'apply');
312 $current_access = ($set_data[
'previous_access']) ? translate(
'applied') : translate(
'denied');
313 $this->
_addError(translate(
'hipo_cannot_modify_schema', $new_access, $schema_name, $asset->name, $current_access), TRUE);
318 switch ($set_data[
'granted']) {
321 $step_data[
'message'] = htmlentities(
'Removing "'.$schema->name.
'" (#'.$schema->id.
') from "'.$asset->name.
'" (#'.$asset->id.
')', ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
322 $mm->deleteSchema($asset->id, $set_data[
'schemaid']);
328 $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);
329 $mm->setSchema($asset->id, $set_data[
'schemaid'], $set_data[
'granted'], $set_data[
'cascades']);
336 if (count($schema_changes) > 1) {
337 $step_data[
'message'] = htmlentities(
'Making '.count($schema_changes).
' schema changes to '.$asset->name.
' (Id: #'.$asset->id.
')', ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
338 }
else if (count($schema_changes) == 0) {
339 $step_data[
'message'] = translate(
'hipo_skipping_asset', $asset->id);
342 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'metadata');
343 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
347 trigger_localised_error(
'SYS0100', E_USER_WARNING, $asset->name);
350 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
351 $this->
_addError(translate(
'hipo_cannot_edit_schema', $assetid));
355 $this->_running_vars[
'done_assetids'][] = $assetid;
358 if (empty($this->_running_vars[
'todo_assetids'])) {
359 $step_data[
'percent_done'] = 100;
360 $step_data[
'complete'] = TRUE;
362 $step_data[
'percent_done'] = ($this->_running_vars[
'done_changes'] / $this->_running_vars[
'total_changes']) * 100;
363 $step_data[
'complete'] = FALSE;