17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
39 public $import_action_outputs = Array();
48 $this->uses_trans = FALSE;
62 return 'HIPO_Job_Export_Assets_To_Xml-'.md5($this->_running_vars[
'root_node_mapping'].$this->_running_vars[
'export_path']);
75 return translate(
'tool_export_assets_to_xml_hipo_name');
91 'name' => translate(
'tool_export_assets_to_xml_hipo_name'),
92 'function_call' => Array(
93 'process_function' =>
'processExportAsset',
95 'running_mode' =>
'server',
97 'allow_cancel' => TRUE,
101 'header_set' => FALSE,
116 $step_data[
'complete'] = FALSE;
117 while(!$step_data[
'complete']) {
137 $this->_running_vars[
'sections'] = Array(
'create',
'attribute',
'metadata',
'link',
'permission');
139 $this->_running_vars[
'asset_id_map'] = Array();
141 return parent::prepare();
157 $path = $this->_running_vars[
'export_path'];
158 $asset_infos = $this->_running_vars[
'root_node_mapping'];
159 $initial_link_type = SQ_LINK_TYPE_1;
160 $action = array_shift($this->_running_vars[
'sections']);
162 if (!$step_data[
'header_set']) {
163 echo
"<?xml version=\"1.0\" encoding=\"".SQ_CONF_DEFAULT_CHARACTER_SET.
"\"?>\n";
164 $step_data[
'header_set'] = TRUE;
169 foreach($asset_infos as $asset_info) {
170 $asset_from_to_id = explode(
':',$asset_info);
171 if(!isset($asset_from_to_id[0]) || !isset($asset_from_to_id[1])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
172 $this->
printCreateXML($asset_from_to_id[0], $asset_from_to_id[1], $initial_link_type);
174 $step_data[
'percent_done'] = 20;
175 $step_data[
'complete'] = FALSE;
178 foreach($asset_infos as $asset_info) {
179 $asset_from_to_id = explode(
':',$asset_info);
180 if(!isset($asset_from_to_id[0])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
183 $step_data[
'percent_done'] = 40;
184 $step_data[
'complete'] = FALSE;
187 foreach($asset_infos as $asset_info) {
188 $asset_from_to_id = explode(
':',$asset_info);
189 if(!isset($asset_from_to_id[0])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
192 $step_data[
'percent_done'] = 60;
193 $step_data[
'complete'] = FALSE;
196 foreach($asset_infos as $asset_info) {
197 $asset_from_to_id = explode(
':',$asset_info);
198 if(!isset($asset_from_to_id[0])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
201 $step_data[
'percent_done'] = 80;
202 $step_data[
'complete'] = FALSE;
205 foreach($asset_infos as $asset_info) {
206 $asset_from_to_id = explode(
':',$asset_info);
207 if(!isset($asset_from_to_id[0])) trigger_error(
"Failed to parse second argument\n", E_USER_ERROR);
210 echo
"</actions>\n\n";
211 $step_data[
'percent_done'] = 100;
212 $step_data[
'complete'] = TRUE;
216 $output = ob_get_clean();
218 file_put_contents($path.
'/export.xml', $output, FILE_APPEND | LOCK_EX);
242 function printCreateXML($asset_id, $parent, $link_type, $value=
'', $is_dependant=0, $is_exclusive=0) {
245 $asset = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_id);
246 if (is_null($asset)) exit();
249 if ($this->
replace_system_assetid($asset->id) != NULL) trigger_error(
"Can not export system asset!\n", E_USER_ERROR);
252 $action_code = $this->
getAssetType($asset).
'_'.$asset->id;
254 $this->_running_vars[
'asset_id_map'][$asset->id] = $action_code;
257 echo
" <action_id>create_".$action_code.
"</action_id>\n";
259 if ($GLOBALS[
'SQ_SYSTEM']->am->isTypeDecendant($this->getAssetType($asset),
'file')) {
260 $file_path = $this->_saveFileAsset($asset);
261 echo
" <action_type>create_file_asset</action_type>\n";
262 echo
" <file_path>".$file_path.
"</file_path>\n";
264 echo
" <action_type>create_asset</action_type>\n";
267 echo
" <type_code>".$this->getAssetType($asset).
"</type_code>\n";
268 echo
" <link_type>".$link_type.
"</link_type>\n";
269 echo
" <parentid>".$parent.
"</parentid>\n";
270 echo
" <value>".$value.
"</value>\n";
271 echo
" <is_dependant>".$is_dependant.
"</is_dependant>\n";
272 echo
" <is_exclusive>".$is_exclusive.
"</is_exclusive>\n";
273 echo
"</action>\n\n";
277 $paths = $asset->getWebPaths();
278 foreach ($paths as $path) {
281 echo
" <action_id>add_".$action_code.
"_path</action_id>\n";
282 echo
" <action_type>add_web_path</action_type>\n";
283 echo
" <asset>[[output://create_".$action_code.
".assetid]]</asset>\n";
284 echo
" <path>".$path.
"</path>\n";
285 echo
"</action>\n\n";
290 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
291 foreach ($dependants as $link_info) {
292 if (!strpos($link_info[
'minorid'],
':')) {
293 $parent =
'[[output://create_'.$action_code.
'.assetid]]';
296 if (array_key_exists($link_info[
'minorid'], $this->_running_vars[
'asset_id_map'])) {
299 $this->
printCreateXML($link_info[
'minorid'], $parent, $link_info[
'link_type'], $link_info[
'value'], $link_info[
'is_dependant'], $link_info[
'is_exclusive']);
306 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
307 foreach ($children as $link_info) {
308 if (!strpos($link_info[
'minorid'],
':')) {
309 $parent =
'[[output://create_'.$action_code.
'.assetid]]';
311 if (array_key_exists($link_info[
'minorid'], $this->_running_vars[
'asset_id_map'])) {
314 $this->
printCreateXML($link_info[
'minorid'], $parent, $link_info[
'link_type'], $link_info[
'value'], $link_info[
'is_dependant'], $link_info[
'is_exclusive']);
321 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
338 if (isset($this->_running_vars[
'asset_id_map'][$link_info[
'minorid']])){
339 $remap_id =
"[[output://create_".$this->_running_vars[
'asset_id_map'][$link_info[
'minorid']].
".assetid]]";
345 $system_asset_name == NULL ? $remap_id = $link_info[
'minorid'] : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
349 echo
" <action_id>link_".$action_code.
"</action_id>\n";
350 echo
" <action_type>create_link</action_type>\n";
351 echo
" <asset>".$remap_id.
"</asset>\n";
352 echo
" <assetid>".$parent.
"</assetid>\n";
353 echo
" <is_major>0</is_major>\n";
354 echo
" <link_type>".$link_info[
'link_type'].
"</link_type>\n";
355 echo
" <value>".$link_info[
'value'].
"</value>\n";
356 echo
" <is_dependant>".$link_info[
'is_dependant'].
"</is_dependant>\n";
357 echo
" <is_exclusive>".$link_info[
'is_exclusive'].
"</is_exclusive>\n";
358 echo
"</action>\n\n";
373 $assets_done = Array();
375 $asset = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_id);
376 if (is_null($asset)) exit();
379 foreach ($asset->vars as $attr_name => $attr_info) {
380 $attr = $asset->getAttribute($attr_name);
381 $value = $attr->getContent();
384 $value = var_export(unserialize($value),TRUE);
387 if (preg_match(
"/assetid/",$attr_name) && isset($this->_running_vars[
'asset_id_map'][$value])){
388 $value =
"[[output://create_".$this->_running_vars[
'asset_id_map'][$value].
".assetid]]";
390 $assets_done[$asset->id] = TRUE;
392 if (!empty($value)) {
394 echo
" <action_id>set_".$this->_running_vars[
'asset_id_map'][$asset_id].
'_'.$attr_name.
"</action_id>\n";
395 echo
" <action_type>set_attribute_value</action_type>\n";
396 echo
" <asset>[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]</asset>\n";
397 echo
" <attribute>".$attr_name.
"</attribute>\n";
398 if ($attr_name ==
'html') { $value = $this->
_parseValue($value); }
399 echo
" <value><![CDATA[".$value.
"]]></value>\n";
400 echo
"</action>\n\n";
405 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
406 foreach ($dependants as $link_info) {
407 if (!strpos($link_info[
'minorid'],
':')) {
408 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
415 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
416 foreach ($children as $link_info) {
417 if (!strpos($link_info[
'minorid'],
':')) {
418 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
424 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
439 $assets_done = Array();
441 $notice_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset_id, SQ_LINK_NOTICE,
'', FALSE,
'major');
443 foreach ($notice_links as $notice_link) {
445 if (isset($this->_running_vars[
'asset_id_map'][$asset_id])){
446 $remap_id =
"[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]" ;
452 $system_asset_name == NULL ? $remap_id = $asset_id : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
454 $this->
printLinkXML($remap_id, $notice_link,
'notice_'.$asset_id.
'_to_'.$notice_link[
'minorid']);
458 $assets_done[$asset_id] = TRUE;
461 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
462 foreach ($dependants as $link_info) {
463 if (!strpos($link_info[
'minorid'],
':')) {
464 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
471 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
472 foreach ($children as $link_info) {
473 if (!strpos($link_info[
'minorid'],
':')) {
474 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
481 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
497 $assets_done = Array();
500 $read_permissions = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($asset_id, SQ_PERMISSION_READ, NULL, FALSE, FALSE, TRUE, TRUE);
501 foreach ($read_permissions as $permission_id => $permission_granted) {
503 if (isset($this->_running_vars[
'asset_id_map'][$permission_id])){
504 $remap_id =
"[[output://create_".$this->_running_vars[
'asset_id_map'][$permission_id].
".assetid]]" ;
510 $system_asset_name == NULL ? $remap_id = $permission_id : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
517 if($permission_granted == 0) {
519 echo
" <action_id>set_permission_".$asset_id.
"_read_".$permission_id.
"</action_id>\n";
520 echo
" <action_type>set_permission</action_type>\n";
521 echo
" <asset>[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]</asset>\n";
522 echo
" <permission>1</permission>\n";
523 echo
" <mute_error>1</mute_error>\n";
524 echo
" <granted>-1</granted>\n";
525 echo
" <userid>".$remap_id.
"</userid>\n";
529 echo
" <action_id>set_permission_".$asset_id.
"_read_".$permission_id.
"</action_id>\n";
530 echo
" <action_type>set_permission</action_type>\n";
531 echo
" <asset>[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]</asset>\n";
532 echo
" <permission>1</permission>\n";
533 echo
" <granted>".$permission_granted.
"</granted>\n";
534 echo
" <userid>".$remap_id.
"</userid>\n";
539 $write_permissions = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($asset_id, SQ_PERMISSION_WRITE, NULL, FALSE, FALSE, TRUE, TRUE);
540 foreach ($write_permissions as $permission_id => $permission_granted) {
543 if (isset($this->_running_vars[
'asset_id_map'][$permission_id])){
544 $remap_id =
"[[output://create_".$this->_running_vars[
'asset_id_map'][$permission_id].
".assetid]]" ;
550 $system_asset_name == NULL ? $remap_id = $permission_id : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
555 if($permission_granted == 0) {
557 echo
" <action_id>set_permission_".$asset_id.
"_write_".$permission_id.
"</action_id>\n";
558 echo
" <action_type>set_permission</action_type>\n";
559 echo
" <asset>[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]</asset>\n";
560 echo
" <mute_error>1</mute_error>\n";
561 echo
" <permission>2</permission>\n";
562 echo
" <granted>-1</granted>\n";
563 echo
" <userid>".$remap_id.
"</userid>\n";
567 echo
" <action_id>set_permission_".$asset_id.
"_write_".$permission_id.
"</action_id>\n";
568 echo
" <action_type>set_permission</action_type>\n";
569 echo
" <asset>[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]</asset>\n";
570 echo
" <permission>2</permission>\n";
571 echo
" <granted>".$permission_granted.
"</granted>\n";
572 echo
" <userid>".$remap_id.
"</userid>\n";
577 $admin_permissions = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($asset_id, SQ_PERMISSION_ADMIN, NULL, FALSE, FALSE, TRUE, TRUE);
578 foreach ($admin_permissions as $permission_id => $permission_granted) {
580 if (isset($this->_running_vars[
'asset_id_map'][$permission_id])){
581 $remap_id =
"[[output://create_".$this->_running_vars[
'asset_id_map'][$permission_id].
".assetid]]" ;
585 $system_asset_name == NULL ? $remap_id = $permission_id : $remap_id =
"[[system://".$system_asset_name.
"]]" ;
590 if($permission_granted == 0) {
592 echo
" <action_id>set_permission_".$asset_id.
"_admin_".$permission_id.
"</action_id>\n";
593 echo
" <action_type>set_permission</action_type>\n";
594 echo
" <asset>[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]</asset>\n";
595 echo
" <mute_error>1</mute_error>\n";
596 echo
" <permission>3</permission>\n";
597 echo
" <granted>-1</granted>\n";
598 echo
" <userid>".$remap_id.
"</userid>\n";
602 echo
" <action_id>set_permission_".$asset_id.
"_admin_".$permission_id.
"</action_id>\n";
603 echo
" <action_type>set_permission</action_type>\n";
604 echo
" <asset>[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]</asset>\n";
605 echo
" <permission>3</permission>\n";
606 echo
" <granted>".$permission_granted.
"</granted>\n";
607 echo
" <userid>".$remap_id.
"</userid>\n";
612 $assets_done[$asset_id] = TRUE;
615 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
616 foreach ($dependants as $link_info) {
617 if (!strpos($link_info[
'minorid'],
':')) {
618 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
625 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset_id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
626 foreach ($children as $link_info) {
627 if (!strpos($link_info[
'minorid'],
':')) {
628 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
648 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
649 $assets_done = Array();
651 $asset = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_id);
652 if (is_null($asset)) exit();
654 foreach($mm->getSchemas($asset_id) as $schema_id => $granted) {
655 $schema_info = $mm->getAssetSchemaInfo($asset_id, $schema_id);
657 echo
" <action_id>set_".$this->_running_vars[
'asset_id_map'][$asset_id].
"_metadata_schema_".$schema_id.
"</action_id>\n";
658 echo
" <action_type>set_metadata_schema</action_type>\n";
659 echo
" <asset>[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]</asset>\n";
660 echo
" <schemaid>".(isset($this->_running_vars[
'asset_id_map'][$schema_id]) ?
"[[output://create_".$this->_running_vars[
'asset_id_map'][$schema_id].
".assetid]]" : $schema_id).
"</schemaid>\n";
661 echo
" <granted>".$schema_info[
'granted'].
"</granted>\n";
662 echo
" <cascades>".$schema_info[
'cascades'].
"</cascades>\n";
663 echo
"</action>\n\n";
665 $metadata = $mm->getMetadata($asset_id, $schema_id);
666 foreach ($metadata as $field_id => $field_info) {
668 echo
" <action_id>set_".$this->_running_vars[
'asset_id_map'][$asset_id].
"_metadata_field_".$field_id.
"</action_id>\n";
669 echo
" <action_type>set_metadata_value</action_type>\n";
670 echo
" <asset>[[output://create_".$this->_running_vars[
'asset_id_map'][$asset_id].
".assetid]]</asset>\n";
671 echo
" <fieldid>".(isset($this->_running_vars[
'asset_id_map'][$field_id]) ?
"[[output://create_".$this->_running_vars[
'asset_id_map'][$field_id].
".assetid]]" : $field_id).
"</fieldid>\n";
672 echo
" <value><![CDATA[".$field_info[0][
'value'].
"]]></value>\n";
673 echo
"</action>\n\n";
678 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, TRUE);
679 foreach ($dependants as $link_info) {
680 if (!strpos($link_info[
'minorid'],
':')) {
681 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
688 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', FALSE,
'major', NULL, 0);
689 foreach ($children as $link_info) {
690 if (!strpos($link_info[
'minorid'],
':')) {
691 if (!array_key_exists($link_info[
'minorid'], $assets_done)) {
697 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
710 private function _saveFileAsset(&$asset) {
712 $path = $this->_running_vars[
'export_path'];
713 $file_info = $asset->getExistingFile();
715 $export_path = $path.
'/export/'.$file_type.
'/'.$file_info[
'filename'];
718 if (!file_exists($path.
'/export/')) {
719 mkdir($path.
'/export', 0775);
723 if (!file_exists($path.
'/export/'.$file_type.
'/')) {
724 mkdir($path.
'/export/'.$file_type, 0775);
727 if (copy($file_info[
'path'], $export_path)) {
728 return 'export/'.$file_type.
'/'.$file_info[
'filename'];
730 die(
'Could not copy file');
746 $shadow_reg =
'|.\/?a=(\d+:\w*)|';
747 $normal_reg =
'|.\/?a=(\d+)|';
748 $shadow_matches = Array();
749 $normal_matches = Array();
751 preg_match_all($shadow_reg, $value, $shadow_matche);
752 preg_match_all($normal_reg, $value, $normal_matches);
754 if(isset($shadow_matches[1])) $shadow_matches = $shadow_matches[1];
755 if(isset($normal_matches[1])) $normal_matches = $normal_matches[1];
756 $replace_assetids = Array();
757 foreach ($shadow_matches as $data) {
758 $replace_assetids[] = $data;
760 foreach ($normal_matches as $data) {
761 $replace_assetids[] = $data;
763 $replace_assetids = array_unique($replace_assetids);
765 foreach ($replace_assetids as $replace_assetid) {
766 if (isset($this->_running_vars[
'asset_id_map'][$replace_assetid])) {
767 $value = preg_replace(
'|.\/?a='.$replace_assetid.
'|',
'?a=[[output://create_'.$this->_running_vars[
'asset_id_map'][$replace_assetid].
'.assetid]]', $value);
785 $class = get_class($asset);
800 foreach($GLOBALS[
'SQ_SYSTEM']->am->_system_assetids as $asset_name => $asset_id){
801 if($assetid == $asset_id) {
818 return ($str == serialize(
false) || @unserialize($str) !==
false);