Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
tool_import_file.inc
1 <?php
17 require_once SQ_SYSTEM_ROOT.'/core/assets/system/tool/tool.inc';
18 
32 class Tool_Import_File extends Tool
33 {
34 
35 
42  function __construct($assetid=0)
43  {
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
58  static function paintTool(&$o, $type_code)
59  {
60  $tool_info = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_code);
61  $o->openSection($tool_info['name']);
62  $o->openField(translate('file_root_node'));
63  $root_nodes = Array(
64  'physical_file' => 'I',
65  'physical_folder' => 'I',
66  'file_bridge' => 'I',
67  );
68  asset_finder($type_code.'_importing_root_assetid', '', $root_nodes);
69  $o->note(translate('file_root_node_note'));
70  $o->closeField();
71  $o->openField(translate('file_parent_node'));
72  asset_finder($type_code.'_importing_parent_assetid', '');
73  $o->closeField();
74  $o->openField(translate('file_recursive'));
75  check_box($type_code.'_recursive', '1');
76  $o->note(translate('file_recursive_note'));
77  $o->closeField();
78  $o->openField(translate('file_index_file'));
79  check_box($type_code.'_index_file', '1');
80  $o->note(translate('file_index_file_note'));
81  $o->closeField();
82  $o->closeSection();
83 
84  }//end paintTool()
85 
86 
96  static function processTool(&$o, $type_code)
97  {
98  $importr = 0;
99  $importp = 0;
100  $recursive = FALSE;
101 
102  if (isset($_REQUEST[$type_code.'_importing_root_assetid']['assetid'])) {
103  $importr = $_REQUEST[$type_code.'_importing_root_assetid']['assetid'];
104  }
105 
106  if (isset($_REQUEST[$type_code.'_importing_parent_assetid']['assetid'])) {
107  $importp = $_REQUEST[$type_code.'_importing_parent_assetid']['assetid'];
108  }
109 
110  $recursive = (array_get_index($_REQUEST, $type_code.'_recursive', FALSE)) ? TRUE : FALSE;
111  $index_file = (array_get_index($_REQUEST, $type_code.'_index_file', FALSE)) ? TRUE : FALSE;
112 
113  $sanity_check = TRUE;
114  $allowable_root_nodes = Array('physical_file', 'physical_folder', 'file_bridge');
115  $root_node = $GLOBALS['SQ_SYSTEM']->am->getAsset($importr);
116  if (is_null($root_node) || !in_array(strtolower($root_node->type()), $allowable_root_nodes)) {
117  $sanity_check = FALSE;
118  if (!is_null($root_node)) {
119  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($root_node, TRUE);
120  }//end if
121  }//end if
122 
123  if (!empty($importr) && !empty($importp) && $sanity_check) {
124  $vars = Array(
125  'root_assetid' => Array($importr),
126  'parent_assetid' => $importp,
127  'recursive' => $recursive,
128  'index_file' => $index_file,
129  );
130 
131  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
132  $hh->queueHipo('hipo_job_import_file', $vars, '', SQ_PACKAGES_PATH.'/filesystem/hipo_jobs');
133  $url = $hh->runQueuedJobs();
134  if (!empty($url)) $o->setRedirect($url);
135  return TRUE;
136  } else {
137  // Fail
138  if (empty($importr) && $sanity_check) {
139  trigger_localised_error('FIL0001', E_USER_ERROR);
140  } else {
141  trigger_localised_error('FIL0003', E_USER_ERROR);
142  }//end if
143  return FALSE;
144  }//end if
145 
146  }//end processTool()
147 
148 
149 }//end class
150 
151 
152 ?>