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_tag_threshold'));
58 text_box($class.
'[SQ_HIPO_TAG_THRESHOLD]', SQ_HIPO_TAG_THRESHOLD, 5);
59 echo
' '.translate(
'assets');
60 $o->note(translate(
'hipo_value_divided_by_tag'));
62 echo SQ_HIPO_TAG_THRESHOLD;
63 echo
' '.translate(
'assets');
80 'SQ_HIPO_TAG_THRESHOLD' => Array(
'editable' => 1,
'default' =>
'15'),
99 return parent::getCodeName().
'-'.md5(implode(
'-',array_keys($this->_running_vars[
'assets'])));
112 return translate(
'hipo_name_edit_tags');
128 'name' => translate(
'hipo_updating_tags'),
129 'function_call' => Array(
130 'process_function' =>
'processTags',
132 'running_mode' =>
'server',
134 'allow_cancel' => TRUE,
156 if (SQ_HIPO_TAG_THRESHOLD == 0)
return 0;
157 if (!isset($this->_running_vars[
'todo_assetids'])) {
160 return ((count($this->_running_vars[
'todo_assetids']) / (SQ_HIPO_TAG_THRESHOLD / count($this->_running_vars[
'tag_changes']))) * 100);
174 while (!empty($this->_running_vars[
'todo_assetids'])) {
175 if (!$this->
processTags($this->_steps[0], get_class($this))) {
193 if (empty($this->_running_vars[
'assets'])) {
194 trigger_localised_error(
'HIPO0017', E_USER_WARNING);
198 $this->_running_vars[
'done_assetids'] = Array();
200 if (empty($this->_running_vars[
'tag_changes'])) {
202 $this->_running_vars[
'todo_assetids'] = Array();
204 $assets = $this->_running_vars[
'assets'];
205 $child_assets = Array();
206 for (reset($assets); NULL !== ($assetid = key($assets)); next($assets)) {
207 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
208 if (is_null($asset)) {
209 trigger_localised_error(
'HIPO0016', E_USER_WARNING, $assetid);
212 $child_assets += $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid, Array(), NULL, FALSE, NULL, NULL, TRUE, NULL, NULL, TRUE, NULL, Array(SQ_SC_LINK_BACKEND_NAV));
214 $child_assets[$assetid] = Array (
216 'type_code' => $asset->type(),
223 $child_assets = array_filter($child_assets);
226 $this->_running_vars[
'todo_assetids'] = $child_assets;
229 return parent::prepare();
245 if (!empty($this->_running_vars[
'todo_assetids'])) {
246 $tag_manager = $GLOBALS[
'SQ_SYSTEM']->getTagManager();
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);
254 if (!is_null($asset)) {
255 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($assetid,
'links')) {
256 foreach ($this->_running_vars[
'tag_changes'] as $tag_data) {
257 if (!is_array($tag_data[
'tag_id'])) {
258 $tag_data[
'tag_id'] = Array($tag_data[
'tag_id']);
260 switch ($tag_data[
'action']) {
262 foreach ($tag_data[
'tag_id'] as $tag_data_id) {
264 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($asset->id, $tag_data_id, SQ_LINK_NOTICE);
266 $tag_manager->setTag($asset->id, $tag_data_id, $tag_data[
'weight']);
268 $tag_manager->setTagWeight($link[
'linkid'], $tag_data[
'weight']);
274 $tag_manager->deleteTag($asset->id, $tag_data[
'tag_id']);
278 $step_data[
'message'] = translate(
'hipo_editing_tags', htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
279 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'links');
280 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
284 trigger_localised_error(
'SYS0100', E_USER_WARNING, $asset->name);
287 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
288 $this->
_addError(translate(
'hipo_cannot_edit_tags', $assetid));
292 $this->_running_vars[
'done_assetids'][] = $assetid;
295 if (empty($this->_running_vars[
'todo_assetids'])) {
296 $step_data[
'percent_done'] = 100;
297 $step_data[
'complete'] = TRUE;
298 unset($this->_running_vars[
'done_assetids']);
300 $total = count($this->_running_vars[
'todo_assetids']) + count($this->_running_vars[
'done_assetids']);
301 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_assetids']) / $total) * 100;
302 $step_data[
'complete'] = FALSE;
322 $job_type =
'hipo_job_acquire_locks';
324 $options[
'auto_complete'] = TRUE;
327 $running_vars = Array(
328 'assetids' => array_keys($this->_running_vars[
'assets']),
329 'lock_type' => Array(
'links'),
330 'forceably_acquire' => FALSE,
331 'dependants_only' => FALSE,
348 if (!isset($this->_running_vars[
're_lock_assets'])) {
349 $this->_running_vars[
're_lock_assets'] = $this->_running_vars[
'assets'];
352 $assetid = key($this->_running_vars[
're_lock_assets']);
353 unset($this->_running_vars[
're_lock_assets'][$assetid]);
355 $children = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
357 foreach ($children as $dep_child_id => $dep_child_data) {
358 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($dep_child_id,
'links');
361 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
363 $step_data[
'message'] = translate(
'hipo_release_locks', $asset_info[$assetid][
'name']).translate(
'hipo_release_locks_dependents');
365 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'all');
367 $this->_running_vars[
'done_assetids'][] = $assetid;
369 if (empty($this->_running_vars[
're_lock_assets'])) {
370 unset($this->_running_vars[
'done_assetids']);
371 $step_data[
'percent_done'] = 100;
372 $step_data[
'complete'] = TRUE;
374 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / count($this->_running_vars[
'assets'])) * 100;
375 $step_data[
'complete'] = FALSE;