17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
52 public static function paintConfig(&$o, $class, $write_access)
68 'SQ_HIPO_METADATA_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
87 return parent::getCodeName().
'-'.md5(implode(
'-',array_keys($this->_running_vars[
'assets'])));
100 return translate(
'hipo_name_edit_metadata_field_values');
116 'name' => translate(
'hipo_updating_metadata_field_values'),
117 'function_call' => Array(
118 'process_function' =>
'processFieldValues',
120 'running_mode' =>
'server',
122 'allow_cancel' => TRUE,
143 if (SQ_HIPO_METADATA_THRESHOLD == 0)
return 0;
144 if (!isset($this->_running_vars[
'todo_assetids'])) {
147 return ((count($this->_running_vars[
'todo_assetids']) / (SQ_HIPO_METADATA_THRESHOLD / count($this->_running_vars[
'metadata_field_value_changes']))) * 100);
160 while (!empty($this->_running_vars[
'todo_assetids'])) {
179 if (empty($this->_running_vars[
'assets'])) {
180 trigger_localised_error(
'HIPO0017', E_USER_WARNING);
187 if (empty($this->_running_vars[
'contextid'])) {
188 $this->_running_vars[
'contextid'] = $GLOBALS[
'SQ_SYSTEM']->getContextId();
191 $this->_running_vars[
'done_assetids'] = Array();
192 if (empty($this->_running_vars[
'metadata_field_value_changes'])) {
194 $this->_running_vars[
'todo_assetids'] = Array();
197 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
198 $assets = $this->_running_vars[
'assets'];
199 $child_assets = Array();
200 for (reset($assets); NULL !== ($assetid = key($assets)); next($assets)) {
201 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
202 if (is_null($asset)) {
203 trigger_localised_error(
'HIPO0016', E_USER_WARNING, $assetid);
206 $child_assets += $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid);
207 $child_assets[$assetid] = Array (
209 'type_code' => $asset->type(),
214 $types_with_assets = Array();
216 foreach ($child_assets as $assetid => $asset_info) {
220 if (!$mm->allowsMetadata($assetid)) {
221 unset($child_assets[$assetid]);
225 $this->_running_vars[
'todo_assetids'] = $child_assets;
228 return parent::prepare();
244 $GLOBALS[
'SQ_SYSTEM']->changeContext($this->_running_vars[
'contextid']);
246 if (!empty($this->_running_vars[
'todo_assetids'])) {
247 reset($this->_running_vars[
'todo_assetids']);
248 $assetid = key($this->_running_vars[
'todo_assetids']);
249 $asset_type = $this->_running_vars[
'todo_assetids'][$assetid][0][
'type_code'];
250 unset($this->_running_vars[
'todo_assetids'][$assetid]);
252 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
253 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
255 if (!is_null($asset)) {
256 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($assetid,
'metadata')) {
257 foreach ($this->_running_vars[
'metadata_field_value_changes'] as $set_data) {
258 $schemata = $mm->getSchemas($assetid);
260 if (!empty($schemata) && $set_data[
'field_asset_id']) {
261 $metadata_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($set_data[
'field_asset_id']);
262 if (is_null($metadata_field)) {
263 $field_name =
'Unknown Field';
265 $field_name = $metadata_field->name;
267 $mm->setMetadata($assetid, $set_data[
'field_value']);
269 if ((
boolean)$metadata_field->attr(
'is_contextable') === FALSE || $metadata_field instanceof
Metadata_Field_Select) {
270 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
271 foreach ($all_contexts as $contextid => $context_data) {
272 $mm->generateContentFile($assetid, FALSE, $contextid);
275 $mm->generateContentFile($assetid);
282 $step_data[
'message'] = translate(
'hipo_editing_metadata_field_values', htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
284 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'metadata');
285 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
289 trigger_localised_error(
'SYS0100', E_USER_WARNING, $asset->name);
292 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
293 $this->
_addError(translate(
'hipo_cannot_edit_schema', $assetid));
297 $this->_running_vars[
'done_assetids'][] = $assetid;
300 if (empty($this->_running_vars[
'todo_assetids'])) {
301 $step_data[
'percent_done'] = 100;
302 $step_data[
'complete'] = TRUE;
303 unset($this->_running_vars[
'done_assetids']);
305 $total = count($this->_running_vars[
'todo_assetids']) + count($this->_running_vars[
'done_assetids']);
306 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_assetids']) / $total) * 100;
307 $step_data[
'complete'] = FALSE;
310 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
329 $job_type =
'hipo_job_acquire_locks';
331 $options[
'auto_complete'] = TRUE;
333 $running_vars = Array(
334 'assetids' => array_keys($this->_running_vars[
'assets']),
335 'lock_type' => Array(
'metadata'),
336 'forceably_acquire' => FALSE,
337 'dependants_only' => FALSE,
354 if (!isset($this->_running_vars[
're_lock_assets'])) {
355 $this->_running_vars[
're_lock_assets'] = $this->_running_vars[
'assets'];
358 $assetid = key($this->_running_vars[
're_lock_assets']);
359 unset($this->_running_vars[
're_lock_assets'][$assetid]);
361 $children = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
363 foreach ($children as $dep_child_id => $dep_child_type_code) {
364 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($dep_child_id,
'metadata');
367 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
369 $step_data[
'message'] = translate(
'hipo_release_locks', $asset_info[$assetid][
'name']).translate(
'hipo_release_locks_dependents');
371 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'all');
373 $this->_running_vars[
'done_assetids'][] = $assetid;
375 if (empty($this->_running_vars[
're_lock_assets'])) {
376 unset($this->_running_vars[
'done_assetids']);
377 $step_data[
'percent_done'] = 100;
378 $step_data[
'complete'] = TRUE;
380 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / count($this->_running_vars[
'assets'])) * 100;
381 $step_data[
'complete'] = FALSE;