17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
43 $this->uses_trans = FALSE;
44 parent::__construct($code_name);
45 $GLOBALS[
'SQ_SYSTEM']->lm->includePackageStrings(
'cms');
61 return parent::getCodeName().
'-'.$this->_running_vars[
'root_node'].
'-'.$this->_running_vars[
'save_name'];
74 return translate(
'cms_hipo_name_export_files');
90 'name' => translate(
'cms_hipo_exporting_files'),
91 'function_call' => Array(
92 'process_function' =>
'processExport',
94 'running_mode' =>
'server',
99 'allow_cancel' => TRUE,
114 while (!empty($this->_running_vars[
'todo_asset_users'])) {
115 if (!$this->
processExport($this->_steps[0], get_class($this))) {
134 $current_root_node = Array();
137 foreach ($this->_running_vars[
'root_node'] as $each_node_key => $each_node) {
138 foreach ($each_node as $node_key => $node_value) {
139 if ($node_key ==
'assetid') {
140 $current_root_node[$each_node_key] = $node_value;
145 foreach ($current_root_node as $current_node) {
146 $this->_running_vars[
'todo_asset_users'][$i][
'root_node'] = $current_node;
147 $this->_running_vars[
'todo_asset_users'][$i][
'save_name'] = $this->_running_vars[
'save_name'];
148 $this->_running_vars[
'todo_asset_users'][$i][
'save_location'] = $this->_running_vars[
'save_location'];
149 $this->_running_vars[
'todo_asset_users'][$i][
'keep_structure'] = $this->_running_vars[
'keep_structure'];
152 $this->_running_vars[
'done_asset_users'] = Array();
153 return parent::prepare();
169 if (!empty($this->_running_vars[
'todo_asset_users'])) {
172 $index = array_shift(array_keys($this->_running_vars[
'todo_asset_users']));
173 if (isset($this->_running_vars[
'todo_asset_users'][$index][
'root_node'])) {
174 $step_root_node = $this->_running_vars[
'todo_asset_users'][$index][
'root_node'];
178 $root_node = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($step_root_node);
179 $save_name = $this->_running_vars[
'todo_asset_users'][$index][
'save_name'];
180 $save_location = $this->_running_vars[
'todo_asset_users'][$index][
'save_location'];
181 $structure = $this->_running_vars[
'todo_asset_users'][$index][
'keep_structure'];
184 $filename = $save_name;
185 if (!preg_match(
'/(\.tar\.gz|\.tgz|\.tar)$/i', $filename)) {
186 $filename = $filename.
'.tar.gz';
190 $result_node = $this->
processExportNode($step_root_node, $filename, $save_location, $structure);
192 trigger_error(
"Could not process root node: ".$root_node->id);
195 unset($this->_running_vars[
'todo_asset_users'][$index]);
201 if (empty($this->_running_vars[
'todo_asset_users'])) {
202 $step_data[
'percent_done'] = 100;
203 $step_data[
'complete'] = TRUE;
205 $total = count($this->_running_vars[
'todo_asset_users']) + count($this->_running_vars[
'done_asset_users']);
206 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_asset_users']) / $total) * 100;
207 $step_data[
'complete'] = FALSE;
230 $allowed_filetypes = Array(
235 $export_date = date(
'hisdmY');
236 $structure = $keep_structure;
241 $files = $this->
_getFiles($root_node, $allowed_filetypes, $depth);
243 $tmpdir = mkdir(SQ_TEMP_PATH.
'/export-'.$export_date, 0777);
245 trigger_localised_error(
'CMS0105', E_USER_NOTICE);
253 foreach($files as $key => $value) {
254 $filename = $value[
'name'];
255 $file_path = $value[
'path'];
257 if (strpos($filename,
'/') !== FALSE) {
258 $value[
'name'] = str_replace(
'/' ,
'_', $filename);
259 $value[
'path'] = substr($file_path, 0, strlen($file_path) - strlen($filename)).$value[
'name'];
261 $files[$key] = $value;
265 $files_count = count($files);
268 for($file_index = 1; $file_index <= $files_count; $file_index++) {
269 $file_val = $files[$file_index];
271 $recheck_dups = FALSE;
272 for($file_index_check = 1; $file_index_check <= $files_count; $file_index_check++) {
273 if ($file_index == $file_index_check) {
276 $file_val_check = $files[$file_index_check];
278 if ($file_val[
'root'] == $file_val_check[
'root'] && $file_val[
'name'] == $file_val_check[
'name']) {
280 $file_val_check[
'name'] .=
'_'.$file_val_check[
'webpath'];
281 $file_val_check[
'path'] .=
'_'.$file_val_check[
'webpath'];
283 $files[$file_index_check] = $file_val_check;
286 $recheck_dups = TRUE;
295 foreach ($files as $key => $value) {
300 $path_to = $this->
_findPath($files, $value, $path_to);
301 $path_to = $path_to.
'/';
305 $filetmp = SQ_TEMP_PATH.
'/export-'.$export_date.$path_to.$value[
'name'];
307 if ($structure && $value[
'root'] == 0) {
309 $filelist[] =
'.'.$path_to.$value[
'name'];
310 }
else if (!$structure) {
312 $filelist[] =
'./'.$value[
'name'];
315 if (isset($value[
'path']) && !empty($value[
'path']) && !$value[
'dir']) {
316 $to_tmp = copy($value[
'path'], $filetmp);
318 trigger_localised_error(
'CMS0105', E_USER_NOTICE);
319 trigger_error($filetmp);
323 $mkdir = mkdir($filetmp, 0777);
325 trigger_localised_error(
'CMS0105', E_USER_NOTICE);
326 trigger_error($filetmp);
336 chdir(SQ_TEMP_PATH.
'/export-'.$export_date);
338 require_once
'Archive/Tar.php';
340 $tar_ball =
new Archive_Tar($save_location.
'/'.$save_name,
'gz');
341 $result = $tar_ball->add($filelist);
342 if (PEAR::isError($result)) {
343 trigger_localised_error(
'CMS0105', E_USER_NOTICE);
352 $cleanup = $this->
_cleanup(SQ_TEMP_PATH.
'/export-'.$export_date);
354 trigger_localised_error(
'CMS0106', E_USER_NOTICE);
374 if (!is_array($list) || empty($list)) {
377 if (!is_array($file) || empty($file)) {
381 if (!isset($file[
'root']))
return $path;
383 $tmp = $file[
'root'];
385 if (isset($list[$tmp][
'name']) && !empty($list[$tmp][
'name'])) {
386 if (isset($list[$tmp][
'dir']) && $list[$tmp][
'dir']) {
387 $path =
'/'.$list[$tmp][
'name'].$path;
389 $path = $this->
_findPath($list, $list[$tmp], $path);
407 function _getFiles($root_node, $filetypes=Array(), &$depth)
410 $am = $GLOBALS[
'SQ_SYSTEM']->am;
413 if (empty($root_node))
return $files;
414 if (!is_array($filetypes))
return $files;
416 $child_links = $am->getLinks($root_node, SQ_SC_LINK_BACKEND_NAV, $filetypes, FALSE);
417 $files += $this->
_processFiles($child_links, $filetypes, $depth);
437 $am = $GLOBALS[
'SQ_SYSTEM']->am;
440 if (!is_array($links) || empty($links)) {
443 if (!is_array($filetypes))
return $files;
446 foreach ($links as $link) {
447 if (!isset($link[
'minorid']))
return $files;
449 $asset = $am->getAsset($link[
'minorid']);
450 $asset_webpaths = $asset->getWebPaths();
451 $asset_webpath = $asset_webpaths[0];
453 if (!is_null($asset)) {
454 if (is_a($asset,
'folder')) {
456 $files[$depth][
'name'] = $asset->name;
457 $files[$depth][
'path'] = $asset->data_path.
'/'.$asset->name;
458 $files[$depth][
'root'] = $parent;
459 $files[$depth][
'dir'] = 1;
460 $files[$depth][
'webpath'] = $asset_webpath;
461 $files += $this->
_getFiles($asset->id, $filetypes, $depth);
463 if (!empty($filetypes)) {
464 foreach ($filetypes as $type) {
465 if ($type !=
'folder') {
466 if (is_a($asset, $type)) {
468 $files[$depth][
'name'] = $asset->name;
469 $files[$depth][
'path'] = $asset->data_path.
'/'.$asset->name;
470 $files[$depth][
'root'] = $parent;
471 $files[$depth][
'dir'] = 0;
472 $files[$depth][
'webpath'] = $asset_webpath;
478 $files[$depth][
'name'] = $asset->name;
479 $files[$depth][
'path'] = $asset->data_path.
'/'.$asset->name;
480 $files[$depth][
'root'] = $parent;
481 $files[$depth][
'dir'] = 0;
482 $files[$depth][
'webpath'] = $asset_webpath;
504 if (!is_string($base) || empty($base)) {
508 $safe_to_remove = FALSE;
511 $base_dir = opendir($base);
512 while (FALSE !== ($file = readdir($base_dir))) {
513 if ($file ==
'.' || $file ==
'..') {
516 $current_file = $base.
'/'.$file;
517 if (is_dir($current_file)) {
518 $next = $this->
_cleanup($current_file);
520 trigger_localised_error(
'CMS0106', E_USER_NOTICE);
524 $delete_file = unlink($current_file);
526 trigger_localised_error(
'CMS0106', E_USER_NOTICE);
534 $check = opendir($base);
536 while (FALSE !== ($filename = readdir($check))) {
537 $files[] = $filename;
541 if ((count($files) == 2) && isset($files[1]) && $files[0] ==
'.' && $files[1] ==
'..') {
542 $safe_to_remove = TRUE;
546 if ($safe_to_remove) {
547 if (!rmdir($base))
return FALSE;