17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
39 $this->uses_trans = FALSE;
54 public static function paintConfig(&$o, $class, $write_access)
56 $o->openField(
'File Import Threshold');
58 text_box($class.
'[SQ_HIPO_BULK_FILE_IMPORT_THRESHOLD]', SQ_HIPO_BULK_FILE_IMPORT_THRESHOLD, 5);
59 echo
' '.translate(
'assets');
61 echo SQ_HIPO_BULK_FILE_IMPORT_THRESHOLD;
62 echo
' '.translate(
'assets');
79 'SQ_HIPO_BULK_FILE_IMPORT_THRESHOLD' => Array(
'editable' => 1,
'default' => 5),
94 if (!empty($this->_running_vars[
'server_file_import'])) {
95 $dir_names = implode(
'_', array_keys($this->_running_vars[
'server_file_import']));
99 if (!empty($this->_running_vars[
'local_file_import'])) {
100 foreach ($this->_running_vars[
'local_file_import'][
'files'] as $data) {
101 $file_names .= $data[
'name'];
105 return 'HIPO_Job_File_Import-'.md5($dir_names.$file_names);
118 return translate(
'file_import_tools_bulk_file_import_hipo_name');
134 'name' =>
'Import Files',
135 'function_call' => Array(
136 'process_function' =>
'importServerFiles',
138 'running_mode' =>
'server',
140 'allow_cancel' => TRUE,
146 'name' =>
'Import Files',
147 'function_call' => Array(
148 'process_function' =>
'importLocalFiles',
150 'running_mode' =>
'server',
152 'allow_cancel' => TRUE,
171 if (empty($this->_running_vars[
'server_file_import']) && empty($this->_running_vars[
'local_file_import'])) {
175 $this->_running_vars[
'server_todo_counts'] = Array();
176 $this->_running_vars[
'local_todo_counts'] = Array();
179 if (!empty($this->_running_vars[
'server_file_import'])) {
180 foreach ($this->_running_vars[
'server_file_import'] as $key => $data) {
181 foreach ($data[
'file_list'] as $file_name) {
182 $this->_running_vars[
'server_todo_counts'][] = Array(
183 'file_name' => $file_name,
184 'full_path' => $key.
'/'.$file_name,
185 'root_id' => $data[
'root_id'],
189 $this->_running_vars[
'server_done_counts'] = Array();
193 if (!empty($this->_running_vars[
'local_file_import'])) {
194 foreach ($this->_running_vars[
'local_file_import'][
'files'] as $data) {
196 'file_name' => $data[
'name'],
197 'full_path' => $this->_running_vars[
'local_file_import'][
'location'].
'/'.$data[
'name'],
198 'root_id' => $this->_running_vars[
'local_file_import'][
'rootid'],
199 'type' => $data[
'file_type'],
200 'title' => $data[
'title'],
202 if ($file_info[
'type'] ==
'image') {
203 $file_info[
'alt'] = $data[
'alt'];
204 $file_info[
'caption'] = $data[
'caption'];
206 $this->_running_vars[
'local_todo_counts'][] = $file_info;
208 $this->_running_vars[
'local_done_counts'] = Array();
212 if (!isset($this->_running_vars[
'allow_unrestricted'])) {
213 $this->_running_vars[
'allow_unrestricted'] = TRUE;
215 if (!isset($this->_running_vars[
'link_type'])) {
216 $this->_running_vars[
'link_type'] = SQ_LINK_TYPE_1;
219 return parent::prepare();
234 if (SQ_HIPO_BULK_FILE_IMPORT_THRESHOLD == 0)
return 0;
235 $server_files = count($this->_running_vars[
'server_todo_counts']);
236 $local_files = count($this->_running_vars[
'local_todo_counts']);
237 $total = $server_files + $local_files;
238 if ($total == 0)
return 0;
240 return ($total / SQ_HIPO_BULK_FILE_IMPORT_THRESHOLD) * 100;
253 while (!empty($this->_running_vars[
'server_todo_counts'])) {
259 while (!empty($this->_running_vars[
'local_todo_counts'])) {
280 if (!empty($this->_running_vars[
'server_todo_counts'])) {
282 $todo = array_shift($this->_running_vars[
'server_todo_counts']);
283 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($todo[
'root_id']);
284 $import_link = Array(
'asset' => &$parent_asset,
'link_type' => $this->_running_vars[
'link_type']);
285 $file_type = get_file_type($todo[
'file_name']);
286 switch ($file_type) {
289 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'word_doc');
290 $new_asset_type =
'word_doc';
293 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'pdf_file');
294 $new_asset_type =
'pdf_file';
302 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'excel_doc');
303 $new_asset_type =
'excel_doc';
314 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'powerpoint_doc');
315 $new_asset_type =
'powerpoint_doc';
318 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'rtf_file');
319 $new_asset_type =
'rtf_file';
322 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'text_file');
323 $new_asset_type =
'text_file';
326 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'js_file');
327 $new_asset_type =
'js_file';
330 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'css_file');
331 $new_asset_type =
'css_file';
337 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'image');
338 $new_asset_type =
'image';
341 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'mp3_file');
342 $new_asset_type =
'mp3_file';
353 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'video_file');
354 $new_asset_type =
'video_file';
357 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'file');
358 $new_asset_type =
'file';
363 $temp_info = Array(
'name' => $todo[
'file_name'],
'tmp_name' => $todo[
'full_path'],
'non_uploaded_file' => TRUE);
364 $new_file =
new $new_asset_type();
365 $new_file->_tmp[
'uploading_file'] = TRUE;
366 $new_file->setAttrValue(
'name', $todo[
'file_name']);
367 $new_file->setAttrValue(
'allow_unrestricted', $this->_running_vars[
'allow_unrestricted']);
369 if (!$new_file->create($import_link, $temp_info)) {
370 $this->
_addError(translate(
'file_import_tools_hipo_can_not_create_file', $todo[
'file_name'], $parent->id), TRUE);
372 $this->_running_vars[
'server_done_counts'][] = $todo;
376 if (empty($this->_running_vars[
'server_todo_counts'])) {
377 $step_data[
'percent_done'] = 100;
378 $step_data[
'complete'] = TRUE;
379 unset($this->_running_vars[
'server_done_counts']);
381 $total = count($this->_running_vars[
'server_todo_counts']) + count($this->_running_vars[
'server_done_counts']);
382 $step_data[
'percent_done'] = (count($this->_running_vars[
'server_done_counts']) / $total) * 100;
383 $step_data[
'complete'] = FALSE;
402 if (!empty($this->_running_vars[
'local_todo_counts'])) {
404 $todo = array_shift($this->_running_vars[
'local_todo_counts']);
405 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($todo[
'root_id']);
406 $import_link = Array(
'asset' => &$parent_asset,
'link_type' => $this->_running_vars[
'link_type']);
407 switch ($todo[
'type']) {
409 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'word_doc');
410 $new_asset_type =
'word_doc';
413 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'pdf_file');
414 $new_asset_type =
'pdf_file';
417 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'powerpoint_doc');
418 $new_asset_type =
'powerpoint_doc';
421 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'excel_doc');
422 $new_asset_type =
'excel_doc';
425 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'rtf_file');
426 $new_asset_type =
'rtf_file';
429 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'text_file');
430 $new_asset_type =
'text_file';
433 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'css_file');
434 $new_asset_type =
'css_file';
437 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'js_file');
438 $new_asset_type =
'js_file';
441 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'image');
442 $new_asset_type =
'image';
445 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'mp3_file');
446 $new_asset_type =
'mp3_file';
449 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'video_file');
450 $new_asset_type =
'video_file';
453 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'file');
454 $new_asset_type =
'file';
459 $temp_info = Array(
'name' => $todo[
'file_name'],
'tmp_name' => $todo[
'full_path'],
'non_uploaded_file' => TRUE);
460 $new_file =
new $new_asset_type();
461 $new_file->_tmp[
'uploading_file'] = TRUE;
462 $new_file->setAttrValue(
'name', $todo[
'file_name']);
463 $new_file->setAttrValue(
'title', $todo[
'title']);
464 $new_file->setAttrValue(
'allow_unrestricted', $this->_running_vars[
'allow_unrestricted']);
467 switch ($todo[
'type']) {
469 $new_file->setAttrValue(
'alt', $todo[
'alt']);
470 $new_file->setAttrValue(
'caption', $todo[
'caption']);
474 if (!$new_file->create($import_link, $temp_info)) {
475 $this->
_addError(translate(
'file_import_tools_hipo_can_not_create_file', $todo[
'file_name'], $parent->id), TRUE);
477 $this->_running_vars[
'local_done_counts'][] = $todo;
481 if (empty($this->_running_vars[
'local_todo_counts'])) {
482 $step_data[
'percent_done'] = 100;
483 $step_data[
'complete'] = TRUE;
484 unset($this->_running_vars[
'local_todo_counts']);
486 $total = count($this->_running_vars[
'local_todo_counts']) + count($this->_running_vars[
'local_done_counts']);
487 $step_data[
'percent_done'] = (count($this->_running_vars[
'local_done_counts']) / $total) * 100;
488 $step_data[
'complete'] = FALSE;