Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
rebake.php
1 <?php
35 if (ini_get('memory_limit') != '-1') ini_set('memory_limit', '-1');
36 error_reporting(E_ALL);
37 $SYSTEM_ROOT = '';
38 
39 $cli = TRUE;
40 
41 // from cmd line
42 if ((php_sapi_name() == 'cli')) {
43  if (isset($_SERVER['argv'][1])) {
44  $SYSTEM_ROOT = $_SERVER['argv'][1];
45  }
46  $err_msg = "You need to supply the path to the System Root as the first argument\n";
47 
48 } else {
49  $cli = FALSE;
50  if (isset($_GET['SYSTEM_ROOT'])) {
51  $SYSTEM_ROOT = $_GET['SYSTEM_ROOT'];
52  }
53  $err_msg = '
54  <div style="background-color: red; color: white; font-weight: bold;">
55  You need to supply the path to the System Root as a query string variable called SYSTEM_ROOT
56  </div>
57  ';
58 }
59 
60 if (empty($SYSTEM_ROOT)) {
61  echo $err_msg;
62  exit();
63 }
64 
65 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
66  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
67  exit();
68 }
69 
70 // only use console stuff if we're running from the command line
71 if ($cli) {
72  require_once 'Console/Getopt.php';
73 
74  $shortopt = '';
75  $longopt = Array('package=');
76 
77  $con = new Console_Getopt;
78  $args = $con->readPHPArgv();
79  array_shift($args);
80  $options = $con->getopt($args, $shortopt, $longopt);
81 
82  if (is_array($options[0])) {
83  $package_list = get_console_list($options[0]);
84  }
85 }
86 
87 if (!defined('SQ_SYSTEM_ROOT')) {
88  define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
89 }
90 
91 require_once $SYSTEM_ROOT.'/core/include/init.inc';
92 
93 // get the list of functions used during install
94 require_once $SYSTEM_ROOT.'/install/install.inc';
95 
96 $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
97 $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
98 
99 // firstly let's check that we are OK for the version
100 if (version_compare(PHP_VERSION, SQ_REQUIRED_PHP_VERSION, '<')) {
101  trigger_error('<i>'.SQ_SYSTEM_LONG_NAME.'</i> requires PHP Version '.SQ_REQUIRED_PHP_VERSION.'.<br/> You may need to upgrade.<br/> Your current version is '.PHP_VERSION, E_USER_ERROR);
102 }
103 
104 $old_path = ini_get('include_path');
105 ini_set('include_path', SQ_LIB_PATH);
106 require_once SQ_LIB_PATH.'/MatrixDAL/MatrixDALBaker.inc';
107 
108 $packages = $GLOBALS['SQ_SYSTEM']->getInstalledPackages();
109 
110 $asset_sql = 'SELECT type_code FROM sq_ast_typ';
111 $asset_types = MatrixDAL::executeSqlAssoc($asset_sql, 0);
112 
113 print_status_name('Installing queries for MySource Matrix core...');
114 try {
117  print_status_result('OK');
118 } catch (Exception $e) {
119  print_status_result('FAILED');
120  echo '(Exception: '.$e->getMessage().')'."\n";
121  exit(1);
122 }
123 
124 if (count($packages) === 0) {
125  print_status_name('No packages currently installed...');
126  print_status_result('SKIPPED');
127 } else {
128  print_status_name('Installing queries for installed packages ('.count($packages).' packages)...');
129  try {
130  foreach ($packages as $package) {
131  $package_name = $package['code_name'];
132  if ($package_name == '__core__') {
133  $package_name = 'core';
134  }
135  MatrixDALBaker::addPackageQueries($package_name);
136  MatrixDALBaker::bakeQueriesFile($package_name.'_package');
137  }
138  print_status_result('OK');
139  } catch (Exception $e) {
140  print_status_result('FAILED');
141  echo '(Exception at '.$package_name.' package: '.$e->getMessage().')'."\n";
142  exit(1);
143  }
144 }
145 
146 if (count($asset_types) === 0) {
147  print_status_name('No assets currently installed...');
148  print_status_result('SKIPPED');
149 } else {
150  print_status_name('Installing queries for installed assets ('.count($asset_types).' assets)...');
151  try {
152  foreach ($asset_types as $type_code) {
155  }
156  print_status_result('OK');
157  } catch (Exception $e) {
158  print_status_result('FAILED');
159  echo '(Exception at '.$type_code.' asset: '.$e->getMessage().')'."\n";
160  exit(1);
161  }
162 }
163 
164 ini_set('include_path', $old_path);
165 pre_echo('Query Installation Complete');
166 exit(0);
167 
168 
169 
170 
181 function get_console_list($options)
182 {
183  $list = Array();
184 
185  foreach ($options as $option) {
186  // if nothing set, skip this entry
187  if (!isset($option[0]) || !isset($option[1])) {
188  continue;
189  }
190 
191  if ($option[0] != '--package') continue;
192 
193  // Now process the list
194  $parts = explode('-', $option[1]);
195 
196  $types = Array();
197  if (count($parts) == 2 && strlen($parts[1])) {
198  $types = explode(',', $parts[1]);
199  }
200 
201  $list[$parts[0]] = $types;
202  }
203 
204  return $list;
205 
206 }//end get_console_list()
207 
208 
217 function print_status_name($name)
218 {
219  printf ('%s%'.(60 - strlen($name)).'s', $name, '');
220 
221 }//end printWYSIWYGName()
222 
223 
232 function print_status_result($status)
233 {
234  echo "[ $status ]\n";
235 
236 }//end printUpdateStatus()
237 
238 
239 ?>