17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
19 require_once SQ_LIB_PATH.
'/import_export/import.inc';
40 public $import_action_outputs = Array();
49 $this->uses_trans = FALSE;
63 return 'HIPO_Job_Import_Assets_From_Xml-'.md5($this->_running_vars[
'create_under_assetid'].$this->_running_vars[
'file_info']);
76 return translate(
'tool_import_assets_from_xml_hipo_name');
92 'name' => translate(
'tool_import_assets_from_xml_hipo_name'),
93 'function_call' => Array(
94 'process_function' =>
'processImportAsset',
96 'running_mode' =>
'server',
98 'allow_cancel' => TRUE,
116 $step_data[
'complete'] = FALSE;
117 while(!$step_data[
'complete']) {
136 $this->_running_vars[
'import_action_outputs'] = Array();
137 $this->_running_vars[
'nest_content_to_fix'] = Array();
138 $file_info = $this->_running_vars[
'file_info'];
139 $import_actions = get_import_actions($file_info);
142 if(isset($this->_running_vars[
'create_under_assetid']) && $this->_running_vars[
'create_under_assetid'] != 0) {
143 $import_actions[
'actions'][0][
'action'][0][
'parentid'][0] = $this->_running_vars[
'create_under_assetid'];
147 foreach ($import_actions[
'actions'][0][
'action'] as $id => $action) {
148 if($action[
'action_type'][0] ===
'create_file_asset') {
149 $action[
'file_path'][0] = dirname($file_info).
'/'.$action[
'file_path'][0];
150 $import_actions[
'actions'][0][
'action'][$id] = $action;
153 if($action[
'action_type'][0] ===
'create_asset' && $action[
'type_code'][0] ===
'Content_Type_Nest_Content') {
154 $this->_running_vars[
'nest_content_to_fix'] [] = $action[
'action_id'][0];
159 $this->
_addError(
'Action ID "'.$action[
'action_id'][0].
'" contains non-exist assetid reference. Action skipped.', E_USER_WARNING);
160 unset($import_actions[
'actions'][0][
'action'][$id]);
164 $this->_running_vars[
'import_actions'] = $import_actions;
165 $this->_running_vars[
'total_count'] = count($import_actions[
'actions'][0][
'action']);
168 if (empty($file_info)) {
169 trigger_localised_error(
'HIPO0095', E_USER_NOTICE);
173 $root_node_id = $this->_running_vars[
'create_under_assetid'];
176 if($root_node_id != 0) {
177 $root_node = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($root_node_id);
178 if (is_null($root_node)) {
179 trigger_localised_error(
'HIPO0096', E_USER_NOTICE);
184 return parent::prepare();
200 $import_actions = $this->_running_vars[
'import_actions'];
203 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
204 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_OPEN);
205 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
207 $action = array_shift($import_actions[
'actions'][0][
'action']);
209 if(!empty($action)) {
212 if (!execute_import_action($action, $this->_running_vars[
'import_action_outputs'])) {
213 trigger_error(
'Action ID "'.$action[
'action_id'][0].
'" could not be executed', E_USER_WARNING);
217 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
218 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
219 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
221 $this->_running_vars[
'import_actions'] = $import_actions;
224 if (count($import_actions[
'actions'][0][
'action']) == 0) {
225 $step_data[
'percent_done'] = 100;
226 $step_data[
'complete'] = TRUE;
229 foreach ($this->_running_vars[
'nest_content_to_fix'] as $actionid) {
230 if(isset($this->_running_vars[
'import_action_outputs'][$actionid])) {
231 $nest_content_id = $this->_running_vars[
'import_action_outputs'][$actionid][
'assetid'];
232 $nest_content = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($nest_content_id);
233 $nest_content->_tmp[
'edit_fns'] = NULL;
234 $nest_content->linksUpdated();
239 if ($this->_running_vars[
'delete_after_import']) {
241 $command =
"rm -rf ".dirname($this->_running_vars[
'file_info']);
246 $step_data[
'percent_done'] = (($this->_running_vars[
'total_count'] - count($import_actions[
'actions'][0][
'action'])) / $this->_running_vars[
'total_count']) * 100;
247 $step_data[
'complete'] = FALSE;
266 if(isset($action[$type][0]) && preg_match(
'/^[0-9]+$/', $action[$type][0])){
267 return ($GLOBALS[
'SQ_SYSTEM']->am->assetExists ($action[$type][0]));