17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
41 $this->uses_trans = FALSE;
43 $GLOBALS[
'SQ_SYSTEM']->lm->includePackageStrings(
'file');
44 $this->_hipo_vars[
'job_dir'] = SQ_PACKAGES_PATH.
'/filesystem/hipo_jobs';
58 public static function paintConfig(&$o, $class, $write_access)
60 $o->openField(translate(
'file_hipo_import_file_threshold'));
63 text_box($class.
'[SQ_HIPO_IMPORT_FILE_THRESHOLD]', SQ_HIPO_IMPORT_FILE_THRESHOLD, 5);
65 echo SQ_HIPO_IMPORT_FILE_THRESHOLD;
67 echo
' '.translate(
'assets');
83 'SQ_HIPO_IMPORT_FILE_THRESHOLD' => Array(
'editable' => 1,
'default' => 5),
100 if (SQ_HIPO_IMPORT_FILE_THRESHOLD == 0)
return 0;
101 if (!isset($this->_running_vars[
'todo_assetids'])) {
105 return ((count($this->_running_vars[
'todo_assetids']) / SQ_HIPO_IMPORT_FILE_THRESHOLD) * 100);
121 return parent::getCodeName().
'-'.uniqid();
134 return translate(
'file_hipo_name_import_file');
151 'function_call' => Array(
152 'process_function' =>
'processImport',
154 'running_mode' =>
'server',
159 'allow_cancel' => TRUE,
174 while (!empty($this->_running_vars[
'todo_assetids']) || !empty($this->_running_vars[
'dependant_hipo_job'])) {
175 if (!$this->
processImport($this->_steps[0], get_class_lower($this), TRUE)) {
192 $allowable_file_types = Array(
'physical_file',
'physical_folder');
193 $allowable_root_nodes = Array(
'physical_file',
'physical_folder',
'file_bridge');
195 if (empty($this->_running_vars[
'parent_assetid']) || is_null($GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'parent_assetid']))) {
196 trigger_localised_error(
'FIL0003', E_USER_WARNING);
201 if (is_null($this->_running_vars[
'root_assetid']) || empty($this->_running_vars[
'root_assetid'])) {
202 trigger_localised_error(
'FIL0001', E_USER_WARNING);
205 foreach ($this->_running_vars[
'root_assetid'] as $assetid) {
207 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
208 if (is_null($asset)) {
209 trigger_localised_error(
'FIL0001', E_USER_WARNING);
213 if (!in_array(strtolower($asset->type()), $allowable_root_nodes)) {
215 trigger_localised_error(
'FIL0002', E_USER_WARNING, $assetid);
219 if (strtolower($asset->type()) ==
'physical_file') {
220 $child_assets = Array(
223 'type_code' => $asset->type(),
228 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($asset->id);
230 $this->_running_vars[
'todo_assetids'] = $child_assets;
231 $this->_running_vars[
'done_assetids'] = Array();
233 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
237 return parent::prepare();
255 if (!empty($this->_running_vars[
'dependant_hipo_job'])) {
256 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
257 $hipo = $hh->getJob($this->_running_vars[
'dependant_hipo_job']);
260 if (is_null($hipo))
return FALSE;
262 if ($freestyle && $hipo->freestyle()) {
264 unset($this->_running_vars[
'dependant_hipo_job']);
266 }
else if ($hipo->process() && $hipo->complete()) {
268 unset($this->_running_vars[
'dependant_hipo_job']);
274 $allowable_file_types = Array(
'physical_file',
'physical_folder',
'file_bridge');
275 if (!empty($this->_running_vars[
'todo_assetids'])) {
278 $array_keys = array_keys($this->_running_vars[
'todo_assetids']);
279 $assetid = array_shift($array_keys);
280 unset($this->_running_vars[
'todo_assetids'][$assetid]);
281 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
282 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'parent_assetid']);
284 if (!is_null($parent) && !is_null($asset) && in_array(strtolower($asset->type()), $allowable_file_types) && (!$this->_running_vars[
'index_file'] || $asset->name !=
'index.html')) {
285 if (strtolower($asset->type()) ==
'physical_file') {
286 $step_data[
'message'] = translate(
'file_importing_file', htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
287 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
288 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
290 $file_path = $asset->getFilePath();
295 'name' => $asset->name,
296 'tmp_name' => $file_path,
297 'non_uploaded_file' => TRUE,
300 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($file_asset_type);
301 $new =
new $file_asset_type();
302 $new->_tmp[
'uploading_file'] = TRUE;
303 $new->setAttrValue(
'name', $asset->name);
304 $new->setAttrValue(
'allow_unrestricted', FALSE);
307 'link_type' => SQ_LINK_TYPE_1,
310 'is_exclusive' => FALSE,
311 'is_dependant' => FALSE,
313 $created = $new->create($link, $temp_info);
315 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
316 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
318 $step_data[
'message'] = translate(
'file_importing_folder', htmlentities($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
319 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
320 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
322 $folders_children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($asset->id);
327 if ($this->_running_vars[
'index_file']) {
328 $index_file_id = isset($folders_children[$asset->id.
'/index.html']) ? $asset->id.
'/index.html' : FALSE;
329 if ($index_file_id) {
330 $index_file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($index_file_id);
333 if ($index_file && $index_file->type() ==
'physical_file') {
334 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'page_standard');
336 $new->setAttrValue(
'name', $asset->name);
339 'link_type' => SQ_LINK_TYPE_1,
342 'is_exclusive' => FALSE,
343 'is_dependant' => FALSE,
345 $created = $new->create($link);
347 $file_path = $index_file->getFilePath();
348 $file_contents = file_get_contents($file_path);
349 if (!empty($file_contents)) {
351 $bodycopy_div = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($new->id+2);
352 $wysiwyg_content = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($new->id+3);
354 if (!is_null($bodycopy_div) && !is_null($wysiwyg_content)) {
355 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
356 $wysiwyg_content->setContent($file_contents);
357 $bodycopy_div_edit_fns = $bodycopy_div->getEditFns();
358 $bodycopy_div_edit_fns->generateContentFile($bodycopy_div);
359 $new->saveAttributes();
360 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
362 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($bodycopy_div, TRUE);
363 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($wysiwyg_content, TRUE);
364 unset($bodycopy_div);
365 unset($wysiwyg_contnet);
366 unset($bodycopy_div_edit_fns);
367 unset($file_contents);
369 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($bodycopy, TRUE);
373 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($index_file, TRUE);
377 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
379 $new->setAttrValue(
'name', $asset->name);
382 'link_type' => SQ_LINK_TYPE_1,
385 'is_exclusive' => FALSE,
386 'is_dependant' => FALSE,
388 $created = $new->create($link);
392 if (!empty($folders_children) && $created && $this->_running_vars[
'recursive']) {
394 $this->_running_vars[
'dependant_hipo_job'] = $code_name;
398 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
399 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
402 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
403 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($parent, TRUE);
409 $this->_running_vars[
'done_assetids'][] = $assetid;
412 if (empty($this->_running_vars[
'todo_assetids'])) {
413 $step_data[
'percent_done'] = 100;
414 $step_data[
'complete'] = TRUE;
416 $total = count($this->_running_vars[
'todo_assetids']) + count($this->_running_vars[
'done_assetids']);
417 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_assetids']) / $total) * 100;
418 $step_data[
'complete'] = FALSE;
437 $init_hipo =
new Hipo_Job_Import_File();
439 $options[
'auto_complete'] = TRUE;
441 $running_vars = Array(
442 'root_assetid' => Array($assetid),
443 'parent_assetid' => $parentid,
444 'process_dependants' => $assetid.
'-'.$parentid,
446 'index_file' => $this->_running_vars[
'index_file'],
449 $init_hipo->setRunningVars($running_vars);
450 foreach ($options as $k => $v) {
451 $init_hipo->setOption($k, $v);
456 $code_name = $init_hipo->initialise($this->source_code_name);
457 if ($code_name)
return $code_name;
473 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
474 $extension = get_file_type($filename);
507 $type =
'Powerpoint_Doc';
525 $type =
'Video_File';