17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
54 public static function paintConfig(&$o, $class, $write_access)
57 $o->openField(translate(
'clone_asset_threshold'));
60 text_box($class.
'[SQ_DUPE_ASSET_THRESHOLD]',SQ_DUPE_ASSET_THRESHOLD, 5);
62 echo SQ_DUPE_ASSET_THRESHOLD;
64 echo
' '.translate(
'assets');
80 'SQ_DUPE_ASSET_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
99 return parent::getCodeName().
'-'.md5(implode(
'-',array_keys($this->_running_vars[
'assets'])));
112 return translate(
'hipo_name_clone_assets');
128 'name' => translate(
'hipo_clone_options'),
129 'function_call' => Array(
130 'paint_function' =>
'paintCloneOptions',
131 'process_function' =>
'processCloneOptions',
133 'running_mode' =>
'web',
134 'skip_step' => FALSE,
135 'auto_step' => FALSE,
136 'allow_cancel' => TRUE,
142 'name' => translate(
'hipo_acquiring_locks'),
144 'init_details_function' =>
'getLockAssetDetails',
146 'running_mode' =>
'server',
148 'allow_cancel' => FALSE,
154 'name' => translate(
'hipo_cloning_assets'),
155 'function_call' => Array(
156 'process_function' =>
'processCloneAssets',
158 'running_mode' =>
'server',
159 'skip_step' => FALSE,
161 'allow_cancel' => TRUE,
167 'name' => translate(
'hipo_remapping_assets'),
168 'function_call' => Array(
169 'process_function' =>
'processRemap',
171 'running_mode' =>
'server',
172 'skip_step' => FALSE,
174 'allow_cancel' => FALSE,
180 'name' => translate(
'hipo_releasing_locks'),
181 'function_call' => Array(
182 'process_function' =>
'releaseLocks',
184 'running_mode' =>
'server',
186 'skip_step' => FALSE,
187 'allow_cancel' => FALSE,
193 'name' => translate(
'hipo_refreshing_asset_map'),
194 'function_call' => Array(
195 'paint_function' =>
'paintRefresh',
196 'process_function' =>
'processRefresh',
198 'running_mode' =>
'web',
200 'skip_step' => FALSE,
201 'allow_cancel' => FALSE,
222 if (SQ_DUPE_ASSET_THRESHOLD == 0)
return 0;
223 if (!isset($this->_running_vars[
'todo_assetids'])) {
226 return ((count($this->_running_vars[
'todo_assetids']) / SQ_DUPE_ASSET_THRESHOLD) * 100);
239 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
240 $step_data = Array();
244 $running_vars = Array();
247 $errors = $hh->freestyleHipo($job_type, $running_vars);
248 if (!empty($errors)) {
249 $this->
_addError(
'acquiring locks failed');
270 $this->
_addError(
'releasing locks failed');
288 if (empty($this->_running_vars[
'assets'])) {
289 trigger_localised_error(
'HIPO0031', E_USER_WARNING);
293 foreach ($this->_running_vars[
'assets'] as $assetid => $info) {
294 $id_parts = explode(
':', $assetid);
295 if (isset($id_parts[1])) {
296 trigger_localised_error(
'HIPO0084', E_USER_WARNING, $assetid);
301 $this->_running_vars[
'remap'] = Array();
303 return parent::prepare();
320 $job_type =
'hipo_job_acquire_locks';
322 $options[
'auto_complete'] = TRUE;
324 $running_vars = Array(
325 'assetids' => array_keys($this->_running_vars[
'assets']),
326 'lock_type' => Array(
'all'),
327 'forceably_acquire' => FALSE,
328 'dependants_only' => TRUE,
345 if (!isset($this->_running_vars[
're_lock_assets'])) {
346 $this->_running_vars[
're_lock_assets'] = $this->_running_vars[
'assets'];
349 $assetid = key($this->_running_vars[
're_lock_assets']);
350 unset($this->_running_vars[
're_lock_assets'][$assetid]);
352 $children = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
354 foreach ($children as $dep_child_id => $dep_child_data) {
355 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($dep_child_id,
'all');
358 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
360 $step_data[
'message'] = translate(
'hipo_release_locks', $asset_info[$assetid][
'name']).translate(
'hipo_release_locks_dependents');
362 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'all');
364 $this->_running_vars[
'done_assetids'][] = $assetid;
366 if (empty($this->_running_vars[
're_lock_assets'])) {
367 unset($this->_running_vars[
'done_assetids']);
368 $step_data[
'percent_done'] = 100;
369 $step_data[
'complete'] = TRUE;
371 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / count($this->_running_vars[
'assets'])) * 100;
372 $step_data[
'complete'] = FALSE;
395 $to_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'to_parent_assetid']);
397 $o->openSection(translate(
'cloning_confirmation'));
398 $o->openField(translate(
'confirm'));
399 $o->addHiddenField(
'form_submitted', 1);
401 <p><?php echo translate(
'hipo_cloning_confirm', htmlentities($to_parent->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)); ?></p>
404 $assets = $this->_running_vars[
'assets'];
405 for (reset($assets); NULL !== ($assetid = key($assets)); next($assets)) {
406 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
407 ?><li>
"<?php echo htmlentities($asset_info[$assetid]['short_name'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET); ?>"</li><?php
412 <p><!-- Show the change name dialog -->
413 <script type=
"text/javascript">
415 function toggleChangeName() {
416 toggleBox = document.getElementById(
'<?php echo $prefix; ?>_change_name');
417 renamedialog = document.getElementById(
'<?php echo $prefix; ?>_rename_assets');
418 if (toggleBox.checked ==
true) {
419 renamedialog.style.visibility =
"visible";
420 renamedialog.style.display =
"block";
422 renamedialog.style.visibility =
"hidden";
423 renamedialog.style.display =
"none";
428 <input type=
"checkbox" id=
"<?php echo $prefix; ?>_change_name" name=
"<?php echo $prefix; ?>_change_name" onclick=
"toggleChangeName();">
429 <label
for=
"<?php echo $prefix; ?>_change_name">(Optionally) Change the name of the cloned assets</label>
430 <div
id=
"<?php echo $prefix; ?>_rename_assets" style=
"display:none;visibility:hidden;">
433 require_once(SQ_LIB_PATH.
'/html_form/html_form.inc');
434 $assets = $this->_running_vars[
'assets'];
435 for (reset($assets); NULL !== ($assetid = key($assets)); next($assets)) {
436 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
439 <td><li>Change from</li></td>
440 <td>
"<?php echo htmlentities($asset_info[$assetid]['short_name'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET); ?>"</td>
442 <td><?php text_box($prefix.
'_new_names['.$assetid.
']', $asset_info[$assetid][
'short_name'],
'25'); ?></td>
451 <p><?php echo translate(
'hipo_confirm_abort');?></p>
470 if (isset($_POST[
'form_submitted'])) {
472 if (isset($_POST[$prefix.
'_change_name']) && $_POST[$prefix.
'_change_name']) {
473 foreach ($_POST[$prefix.
'_new_names'] as $assetid => $name) {
475 $this->_running_vars[
'assets'][$assetid][
'new_name'] = $name;
481 if ($step_data[
'percent_done'] == 0) {
482 $step_data[
'percent_done'] = 50;
484 $step_data[
'percent_done'] = 100;
485 $step_data[
'complete'] = TRUE;
504 if (!isset($this->_running_vars[
'clone_assets'])) {
505 $this->_running_vars[
'clone_assets'] = $this->_running_vars[
'assets'];
506 $this->_running_vars[
'done_asset_count'] = 0;
507 $this->_running_vars[
'todo_asset_count'] = 0;
508 foreach ($this->_running_vars[
'clone_assets'] as $info) {
509 $this->_running_vars[
'todo_asset_count'] += array_get_index($info,
'number_of_clones', 1);
511 reset($this->_running_vars[
'clone_assets']);
514 $assetid = key($this->_running_vars[
'clone_assets']);
516 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'to_parent_assetid']);
518 if (is_null($parent_asset)) {
519 trigger_localised_error(
'HIPO0030', E_USER_WARNING, $this->_running_vars[
'to_parent_assetid']);
523 $orig = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
525 if (is_null($orig)) {
526 trigger_localised_error(
'HIPO0029', E_USER_WARNING, $assetid);
531 'asset' => $parent_asset,
532 'sort_order' => $this->_running_vars[
'to_parent_pos'],
535 if (!isset($this->_running_vars[
'link_type'])) {
536 $orig_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($this->_running_vars[
'clone_assets'][$assetid][
'parentid'], $orig->id, SQ_LINK_TYPE_1 | SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3);
537 $link[
'link_type'] = $orig_link[
'link_type'];
539 $link[
'link_type'] = $this->_running_vars[
'link_type'];
542 if (!isset($this->_running_vars[
'value'])) {
543 if (empty($orig_link)) {
544 $orig_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($this->_running_vars[
'clone_assets'][$assetid][
'parentid'], $orig->id, SQ_LINK_TYPE_1 | SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3);
546 $link[
'value'] = $orig_link[
'value'];
548 $link[
'value'] = $this->_running_vars[
'value'];
551 if ($this->_running_vars[
'to_parent_pos'] != -1) {
552 $this->_running_vars[
'to_parent_pos']++;
566 $step_data[
'message'] =
'Cloning "'.htmlentities($orig->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'" to "'.htmlentities($parent_asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'".';
568 $clone = $GLOBALS[
'SQ_SYSTEM']->am->cloneAsset($orig, $link, $remap, $components, TRUE);
569 if (is_null($clone)) {
570 trigger_localised_error(
'HIPO0028', E_USER_WARNING);
575 if (isset($this->_running_vars[
'clone_assets'][$assetid][
'new_name']) && !empty($this->_running_vars[
'clone_assets'][$assetid][
'new_name'])) {
576 if (isset($clone->vars[
'name'])) {
577 $clone->setAttrValue(
'name', $this->_running_vars[
'clone_assets'][$assetid][
'new_name']);
579 if (isset($clone->vars[
'short_name'])) {
580 $clone->setAttrValue(
'short_name', $this->_running_vars[
'clone_assets'][$assetid][
'new_name']);
582 if (isset($clone->vars[
'id_name'])) {
583 $clone->setAttrValue(
'id_name', $this->_running_vars[
'clone_assets'][$assetid][
'new_name']);
585 if (!$clone->saveAttributes()) {
586 trigger_localised_error(
'HIPO0028', E_USER_WARNING);
594 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
595 if (isset($this->_running_vars[
'clone_assets'][$assetid][
'new_name']) && !empty($this->_running_vars[
'clone_assets'][$assetid][
'new_name'])) {
596 if(isset($clone->vars[
'id_name'])){
597 $valid_paths = make_valid_web_paths(Array(strtolower($clone->attr(
'id_name'))));
600 $valid_paths = make_valid_web_paths(Array(strtolower($clone->attr(
'name'))));
602 $good_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($link[
'asset'], $valid_paths, $clone->id, TRUE);
604 $valid_paths = make_valid_web_paths($orig->getWebPaths());
605 $good_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($link[
'asset'], $valid_paths, $clone->id, TRUE);
608 $link_info = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($clone->id, $this->_running_vars[
'to_parent_assetid'], $link[
'link_type'], NULL,
'minor');
610 $this->_running_vars[
'cloned_asset'][$clone->id][
'linkid'] = $link_info[
'linkid'];
611 $this->_running_vars[
'cloned_asset'][$clone->id][
'parentid'] = $this->_running_vars[
'to_parent_assetid'];
613 if (!$clone->saveWebPaths($good_paths))
return FALSE;
616 if (method_exists($orig,
'cloneDependantAdditional')) {
617 $orig->cloneDependantAdditional($clone);
620 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($parent_asset);
621 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($orig);
622 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($clone);
624 $this->_running_vars[
'remap'][$assetid] = $remap;
626 if (!empty($this->_running_vars[
'finalise_function'])) {
627 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($this->_running_vars[
'finalise_function'][0]);
628 call_user_func_array($this->_running_vars[
'finalise_function'], Array(&$clone, &$this->_running_vars));
631 if (empty($this->_running_vars[
'clone_assets'][$assetid][
'number_of_clones']) || ($this->_running_vars[
'clone_assets'][$assetid][
'number_of_clones'] == 1)) {
632 unset($this->_running_vars[
'clone_assets'][$assetid]);
634 $this->_running_vars[
'clone_assets'][$assetid][
'number_of_clones']--;
636 $this->_running_vars[
'done_asset_count']++;
638 if (empty($this->_running_vars[
'clone_assets'])) {
639 unset($this->_running_vars[
'done_asset_count']);
640 unset($this->_running_vars[
'todo_asset_count']);
641 $step_data[
'percent_done'] = 100;
642 $step_data[
'complete'] = TRUE;
644 $step_data[
'percent_done'] = (int)(($this->_running_vars[
'done_asset_count'] / $this->_running_vars[
'todo_asset_count']) * 100);
645 $step_data[
'complete'] = FALSE;
666 $assetid = key($this->_running_vars[
'remap']);
668 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
669 $map = $this->_running_vars[
'remap'][$assetid];
670 unset($this->_running_vars[
'remap'][$assetid]);
672 $step_data[
'message'] =
'Remapping "'.htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'" and its dependant assets.';
674 if (!$asset->remapAssetids($map)) {
675 trigger_localised_error(
'HIPO0027', E_USER_WARNING, $asset->id);
679 $this->_running_vars[
'done_assetids'][] = $assetid;
681 if (empty($this->_running_vars[
'remap'])) {
682 unset($this->_running_vars[
'done_assetids']);
683 $step_data[
'percent_done'] = 100;
684 $step_data[
'complete'] = TRUE;
686 $remap_total = count($this->_running_vars[
'done_assetids'])+count($this->_running_vars[
'remap']);
687 $remap_percentage = (int)(count($this->_running_vars[
'done_assetids']) / $remap_total * 100);
688 $step_data[
'percent_done'] = $remap_percentage;
689 $step_data[
'complete'] = FALSE;
709 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
710 if (is_null($hh))
return FALSE;
712 $assets = $this->_running_vars[
'assets'];
715 for (reset($assets); NULL !== ($assetid = key($assets)); next($assets)) {
716 $o->addHiddenField(
'link_assetid['.$c.
']', $assetid);
720 $o->addHiddenField(
'link_parentid', $this->_running_vars[
'to_parent_assetid']);
722 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'to_parent_assetid']);
723 if (is_null($parent)) {
724 trigger_localised_error(
'HIPO0018', E_USER_WARNING, $this->_running_vars[
'to_parent_assetid']);
728 $o->openSection(translate(
'note'));
729 $o->openField(
' ');
730 $o->addHiddenField(
'link_completed',
'0');
732 if (count($this->_running_vars[
'assets']) > 0) {
733 echo
'<p><b>'.translate(
'hipo_asset_cloning_successful', htmlentities($parent->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)).
'</b></p>';
735 for (reset($assets); NULL !== ($assetid = key($assets)); next($assets)) {
736 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid,));
737 echo
'<li>"'.$asset_info[$assetid][
'name'].
'"</li>';
744 <p><?php echo translate(
'hipo_permission_workflow_metadata_display', htmlentities($parent->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)); ?></p>
745 <p><?php echo translate(
'hipo_permission_workflow_metadata_cascade_select', htmlentities($parent->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)); ?></p>
746 <p><?php echo translate(
'hipo_permission_workflow_metadata_cascade_none'); ?></p>
748 $ei = $parent->getEI();
750 $ei->includeStaticScreen(
'permissions');
751 $pe = paintInlinePermissions($parent, $o, $ei);
753 $ei->includeStaticScreen(
'workflow');
754 $wf = paintInlineWorkflow($parent, $o, $ei);
756 $ei->includeStaticScreen(
'metadataSchemas');
757 $ms = paintInlineMetadataSchemas($parent, $o, $ei);
759 $ei->includeStaticScreen(
'tagging');
760 $ta = paintInlineTagging($parent, $o, $ei);
762 $ei->includeStaticScreen(
'roles');
763 $ro = paintInlineRoles($parent, $o, $ei);
765 $o->addHiddenField(
'form_submitted', 1);
769 $o->openSection(translate(
'cascade'));
770 $o->openField(
'',
'cascade');
771 echo ($pe) ? translate(
'permissions').
' '.check_box(
'cascade[]',
'cascade_pe').
'<br />' :
'';
772 echo ($ms) ? translate(
'metadata_schemas').
' '.check_box(
'cascade[]',
'cascade_ms').
'<br />' :
'';
773 echo ($wf) ? translate(
'workflow').
' '.check_box(
'cascade[]',
'cascade_wf').
'<br />' :
'';
774 echo ($ta) ? translate(
'content_tags').
' '.check_box(
'cascade[]',
'cascade_ta').
'<br />' :
'';
775 echo ($ro) ? translate(
'roles').
' '.check_box(
'cascade[]',
'cascade_ro').
'<br />' :
'';
779 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($parent);
800 if ($step_data[
'percent_done'] > 0) {
801 $o->addOnLoad(
'if (window.opener.parent.frames["sq_sidenav"] && window.opener.parent.frames["sq_sidenav"].reload_asset) window.opener.parent.frames["sq_sidenav"].reload_asset("'.$this->_running_vars[
'to_parent_assetid'].
'");');
820 if ($step_data[
'percent_done'] == 0) {
821 $step_data[
'percent_done'] = 50;
823 $step_data[
'percent_done'] = 100;
824 $step_data[
'complete'] = TRUE;