Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
import_files_from_bridge.php
1 <?php
25 error_reporting(E_ALL);
26 ini_set('display_errors', 1);
27 if (ini_get('memory_limit') != '-1') ini_set('memory_limit', '-1');
28 
29 if ((php_sapi_name() != 'cli')) {
30  trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
31  exit;
32 }//end if
33 
34 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
35 if (empty($SYSTEM_ROOT) || !is_dir($SYSTEM_ROOT)) {
36  trigger_error("You need to supply the path to the System Root as the first argument\n", E_USER_ERROR);
37  exit;
38 }//end if
39 
40 define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
41 require_once $SYSTEM_ROOT.'/core/include/init.inc';
42 
43 $root_node = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : '';
44 if (empty($root_node) || !$GLOBALS['SQ_SYSTEM']->am->assetExists($root_node)) {
45  trigger_error("You need to supply a root node to the import files from as the second argument\n", E_USER_ERROR);
46  exit;
47 }//end if
48 
49 $parent_id = (isset($_SERVER['argv'][3])) ? $_SERVER['argv'][3] : '';
50 if (empty($parent_id) || !$GLOBALS['SQ_SYSTEM']->am->assetExists($parent_id)) {
51  trigger_error("You need to supply the parent id to the import files to as the third argument\n", E_USER_ERROR);
52  exit;
53 }//end if
54 
55 $recursive = (isset($_SERVER['argv'][4]) && strtolower($_SERVER['argv'][4]) == 'y') ? TRUE : FALSE;
56 
57 // Whether to import "index.html" file as a Standard Page asset
58 $index_file = (isset($_SERVER['argv'][5]) && strtolower($_SERVER['argv'][5]) == 'y') ? TRUE : FALSE;
59 
60 echo 'START IMPORTING'."\n";
61 $GLOBALS['SQ_SYSTEM']->setCurrentUser($GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user'));
62 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
63 $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
64 $vars = Array (
65  'root_assetid' => Array($root_node),
66  'parent_assetid' => $parent_id,
67  'recursive' => $recursive,
68  'index_file' => $index_file,
69  );
70 $errors = $hh->freestyleHipo('hipo_job_import_file', $vars, SQ_PACKAGES_PATH.'/filesystem/hipo_jobs');
71 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
72 $GLOBALS['SQ_SYSTEM']->restoreCurrentUser();
73 echo 'FINISHED';
74 if (!empty($errors)) {
75  echo '... with errors'."\n";
76  foreach ($errors as $error) {
77  echo is_array($error) ? implode($error,"\n")."\n" : $error."\n";
78  }//end foreach
79 }//end if
80 echo "\n";
81 ?>