17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
60 public static function paintConfig(&$o, $class, $write_access)
63 $o->openField(translate(
'acquire_lock_threshold'));
66 text_box($class.
'[SQ_HIPO_ACQUIRE_LOCK_THRESHOLD]', SQ_HIPO_ACQUIRE_LOCK_THRESHOLD, 5);
68 echo SQ_HIPO_ACQUIRE_LOCK_THRESHOLD;
70 echo
' '.translate(
'assets');
86 'SQ_HIPO_ACQUIRE_LOCK_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
105 $code_name = parent::getCodeName();
106 return $code_name.
'-'.md5(implode(
',', $this->_running_vars[
'assetids']));
119 return translate(
'hipo_name_acquire_locks');
135 'name' => translate(
'hipo_acquiring_locks'),
136 'function_call' => Array(
137 'process_function' =>
'processLocking',
139 'running_mode' =>
'server',
141 'allow_cancel' =>
true,
162 if (isset($this->_running_vars[
'lock_type']) && isset($assetid)) {
163 if (is_array($this->_running_vars[
'lock_type'])) {
164 foreach ($this->_running_vars[
'lock_type'] as $lock_type) {
165 foreach ($GLOBALS[
'SQ_SYSTEM']->am->getLockTypes($assetid, $lock_type) as $type) {
166 if (!in_array($type, $types)) $types[] = $type;
170 $types = $GLOBALS[
'SQ_SYSTEM']->am->getLockTypes($assetid, $this->_running_vars[
'lock_type']);
189 if (SQ_HIPO_ACQUIRE_LOCK_THRESHOLD == 0)
return 0;
190 if (!isset($this->_running_vars[
'child_assetids'])) {
194 return ((($this->_running_vars[
'total_count'] + 1) / SQ_HIPO_ACQUIRE_LOCK_THRESHOLD) * 100);
207 while (!empty($this->_running_vars[
'assetids'])) {
226 if (empty($this->_running_vars[
'assetids']) || empty($this->_running_vars[
'lock_type'])) {
227 trigger_localised_error(
'HIPO0035', E_USER_WARNING);
231 if (!isset($this->_running_vars[
'todo_assetids']) || empty($this->_running_vars[
'todo_assetids'])) {
235 $child_assetids = Array();
236 $this->_running_vars[
'total_count'] = 0;
238 if (!isset($this->_running_vars[
'dependants_only']) || !empty($this->_running_vars[
'dependants_only'])) {
239 $this->_running_vars[
'dependants_only'] =
true;
240 foreach ($this->_running_vars[
'assetids'] as $assetid) {
241 $this->_running_vars[
'total_count']++;
242 $child_assets[$assetid] = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
243 $this->_running_vars[
'total_count'] += count($child_assets[$assetid]);
248 $this->_running_vars[
'dependants_only'] =
false;
249 foreach ($this->_running_vars[
'assetids'] as $assetid) {
250 $this->_running_vars[
'total_count']++;
251 $child_assets[$assetid] = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid);
252 $this->_running_vars[
'total_count'] += count($child_assets[$assetid]);
255 $this->_running_vars[
'child_assetids'] = $child_assets;
256 $this->_running_vars[
'current_assetid'] = reset($this->_running_vars[
'assetids']);
258 $this->_running_vars[
'current_assetid'] = key($this->_running_vars[
'todo_assetids']);
259 $this->_running_vars[
'total_count'] = count($this->_running_vars[
'todo_assetids']);
263 $this->_running_vars[
'done_assetids'] = Array();
265 if (!isset($this->_running_vars[
'forceably_acquire'])) {
266 $this->_running_vars[
'forceably_acquire'] =
false;
268 $this->_running_vars[
'forceably_acquire'] = (bool) $this->_running_vars[
'forceably_acquire'];
271 return parent::prepare();
287 if (!empty($this->_running_vars[
'assetids'])) {
288 $parent_assetid = $this->_running_vars[
'current_assetid'];
290 if (!in_array($parent_assetid, $this->_running_vars[
'done_assetids'])) {
291 $assetid = $parent_assetid;
292 $asset =$GLOBALS[
'SQ_SYSTEM']->am->getAsset($parent_assetid);
294 $parent_assetid_keys = array_keys($this->_running_vars[
'child_assetids'][$parent_assetid]);
295 $assetid = array_shift($parent_assetid_keys);
296 if (is_array($this->_running_vars[
'child_assetids'][$parent_assetid][$assetid])) {
297 $asset_type = $this->_running_vars[
'child_assetids'][$parent_assetid][$assetid][0][
'type_code'];
299 $asset_type = $this->_running_vars[
'child_assetids'][$parent_assetid][$assetid];
301 unset($this->_running_vars[
'child_assetids'][$parent_assetid][$assetid]);
302 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
305 if (!is_null($asset)) {
307 foreach ($lock_types as $lock_type) {
308 $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($asset->id, $lock_type, $parent_assetid, $this->_running_vars[
'forceably_acquire']);
310 $step_data[
'message'] = translate(
'hipo_acquire_lock', htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
311 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
314 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
315 $this->
_addError(translate(
'hipo_asset_not_exist', $assetid));
319 $this->_running_vars[
'done_assetids'][] = $assetid;
322 if (empty($this->_running_vars[
'child_assetids'][$parent_assetid])) {
323 array_shift($this->_running_vars[
'assetids']);
324 if (!empty($this->_running_vars[
'assetids'])) {
325 $this->_running_vars[
'current_assetid'] = $this->_running_vars[
'assetids'][0];
330 if (empty($this->_running_vars[
'assetids'])) {
331 $step_data[
'percent_done'] = 100;
332 $step_data[
'complete'] =
true;
334 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / $this->_running_vars[
'total_count']) * 100;
335 $step_data[
'complete'] =
false;