17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
70 public static function paintConfig(&$o, $class, $write_access)
72 $o->openField(translate(
'edit_role_threshold'));
75 text_box($class.
'[SQ_HIPO_EDIT_ROLE_THRESHOLD]', SQ_HIPO_EDIT_ROLE_THRESHOLD, 5);
77 echo SQ_HIPO_EDIT_ROLE_THRESHOLD;
79 echo
' '.translate(
'assets');
95 'SQ_HIPO_EDIT_ROLE_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
109 return parent::getCodeName().
'-'.md5(implode(
'-',array_keys($this->_running_vars[
'assets'])));
122 return translate(
'hipo_name_edit_roles');
138 'name' => translate(
'hipo_updating_roles'),
139 'function_call' => Array(
140 'process_function' =>
'processRoles',
142 'running_mode' =>
'server',
144 'allow_cancel' => TRUE,
164 if (SQ_HIPO_EDIT_ROLE_THRESHOLD == 0)
return 0;
165 if (!isset($this->_running_vars[
'todo_assetids']) || !isset($this->_running_vars[
'role_changes'])) {
171 foreach ($this->_running_vars[
'role_changes'] as $action_data) {
172 foreach ($action_data as $userids) {
173 $total_userids += count($userids);
179 return ((count($this->_running_vars[
'todo_assetids']) * $total_userids / SQ_HIPO_EDIT_ROLE_THRESHOLD) * 100);
192 while (!empty($this->_running_vars[
'todo_assetids'])) {
193 if (!$this->
processRoles($this->_steps[0], get_class($this))) {
210 if (empty($this->_running_vars[
'assets'])) {
211 trigger_localised_error(
'HIPO0075', E_USER_WARNING);
215 if (empty($this->_running_vars[
'role_changes'])) {
216 $this->_running_vars[
'role_changes'] = Array();
219 $assets = $this->_running_vars[
'assets'];
220 $child_assets = Array();
221 for (reset($assets); NULL !== ($assetid = key($assets)); next($assets)) {
222 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
223 if (empty($asset_info)) {
224 trigger_localised_error(
'HIPO0013', E_USER_WARNING, $assetid);
228 if (array_get_index($this->_running_vars,
'dependants_only')) {
229 $child_assets += $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
231 $child_assets += $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid);
234 $child_assets[$assetid] = Array (
236 'type_code' => $asset_info[$assetid][
'type_code'],
241 $child_assets = array_reverse($child_assets,TRUE);
242 $this->_running_vars[
'todo_assetids'] = $child_assets;
243 $this->_running_vars[
'done_assetids'] = Array();
244 return parent::prepare();
260 if (!empty($this->_running_vars[
'todo_assetids'])) {
261 reset($this->_running_vars[
'todo_assetids']);
262 $assetid = key($this->_running_vars[
'todo_assetids']);
263 $asset_type = $this->_running_vars[
'todo_assetids'][$assetid][0][
'type_code'];
264 unset($this->_running_vars[
'todo_assetids'][$assetid]);
265 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
267 if (!is_null($asset)) {
269 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($assetid,
'roles')) {
270 if ($asset->adminAccess(
'roles')) {
271 foreach ($this->_running_vars[
'role_changes'] as $action => $action_data) {
272 foreach ($action_data as $roleid => $userids) {
273 foreach ($userids as $userid) {
276 $GLOBALS[
'SQ_SYSTEM']->am->setRole($asset->id, $roleid, $userid);
279 $GLOBALS[
'SQ_SYSTEM']->am->deleteRole($asset->id, $roleid, $userid);
285 $step_data[
'message'] = translate(
'hipo_edit_role', htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
286 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'roles');
287 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
291 trigger_localised_error(
'SYS0313', E_USER_WARNING, $asset->name);
295 trigger_localised_error(
'SYS0100', E_USER_WARNING, $asset->name);
298 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
299 $this->
_addError(translate(
'hipo_skipping_role', $assetid));
303 $this->_running_vars[
'done_assetids'][] = $assetid;
307 if (empty($this->_running_vars[
'todo_assetids'])) {
308 $step_data[
'percent_done'] = 100;
309 $step_data[
'complete'] = TRUE;
310 unset($this->_running_vars[
'done_assetids']);
312 $total = count($this->_running_vars[
'todo_assetids']) + count($this->_running_vars[
'done_assetids']);
313 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_assetids']) / $total) * 100;
314 $step_data[
'complete'] = FALSE;
334 $job_type =
'hipo_job_acquire_locks';
335 $options[
'auto_complete'] = TRUE;
337 $running_vars = Array(
338 'assetids' => array_keys($this->_running_vars[
'assets']),
339 'lock_type' => Array(
'roles'),
340 'forceably_acquire' => FALSE,
341 'dependants_only' => isset($this->_running_vars[
'dependants_only']),
358 if (!isset($this->_running_vars[
're_lock_assets'])) {
359 $this->_running_vars[
're_lock_assets'] = $this->_running_vars[
'assets'];
362 $assetid = key($this->_running_vars[
're_lock_assets']);
363 unset($this->_running_vars[
're_lock_assets'][$assetid]);
365 $children = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
367 foreach ($children as $dep_child_id => $dep_child_data) {
368 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($dep_child_id,
'roles');
371 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
373 $step_data[
'message'] = translate(
'hipo_release_locks', $asset_info[$assetid][
'name']).translate(
'hipo_release_locks_dependents');
375 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'all');
377 $this->_running_vars[
'done_assetids'][] = $assetid;
379 if (empty($this->_running_vars[
're_lock_assets'])) {
380 unset($this->_running_vars[
'done_assetids']);
381 $step_data[
'percent_done'] = 100;
382 $step_data[
'complete'] = TRUE;
384 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / count($this->_running_vars[
'assets'])) * 100;
385 $step_data[
'complete'] = FALSE;