Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
step_02.php
1 <?php
28 ini_set('memory_limit', -1);
29 error_reporting(E_ALL);
30 
31 $SYSTEM_ROOT = '';
32 
33 if ((php_sapi_name() == 'cli')) {
34  if (isset($_SERVER['argv'][1])) {
35  $SYSTEM_ROOT = $_SERVER['argv'][1];
36  }
37 
38  $err_msg = "ERROR: You need to supply the path to the System Root as the first argument.\n";
39 
40 } else {
41  if (isset($_GET['SYSTEM_ROOT'])) {
42  $SYSTEM_ROOT = $_GET['SYSTEM_ROOT'];
43  }
44 
45  $err_msg = '
46  <div style="background-color: red; color: white; font-weight: bold;">
47  You need to supply the path to the System Root as a query string variable called SYSTEM_ROOT
48  </div>
49  ';
50 }
51 
52 if (empty($SYSTEM_ROOT)) {
53  $err_msg .= "Usage: php install/step_02.php <PATH_TO_MATRIX>\n";
54  echo $err_msg;
55  exit();
56 }
57 
58 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
59  $err_msg = "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
60  $err_msg .= "Usage: php install/step_02.php <PATH_TO_MATRIX>\n";
61  echo $err_msg;
62  exit();
63 }
64 
65 define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
66 require_once $SYSTEM_ROOT.'/core/include/init.inc';
67 require_once $SYSTEM_ROOT.'/install/install.inc';
68 require_once SQ_LIB_PATH.'/db_install/db_install.inc';
69 require_once SQ_INCLUDE_PATH.'/system_config.inc';
70 require_once SQ_LIB_PATH.'/file_versioning/file_versioning.inc';
71 
72 
73 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
74 
75 // Re-generate the Config to make sure that we get any new defines that may have been issued
76 
77 $cfg = new System_Config();
78 $cfg->save(Array(), FALSE);
79 
80 // check that we have valid DEFAULT and TECH email addresses - warn if missing
81 if (!(SQ_CONF_TECH_EMAIL) && !(SQ_CONF_DEFAULT_EMAIL)) {
82  trigger_error('Neither the System Default nor Tech email addresses have been set', E_USER_WARNING);
83 } else {
84  if (!SQ_CONF_TECH_EMAIL) {
85  trigger_error('The System Tech email address has not been set', E_USER_WARNING);
86  }
87  if (!SQ_CONF_DEFAULT_EMAIL) {
88  trigger_error('The System Default email address has not been set', E_USER_WARNING);
89  }
90 }
91 
92 if (DAL::getDbType() === 'oci') {
93  $query = "SELECT value FROM nls_session_parameters WHERE parameter='NLS_DATE_FORMAT'";
94  $value = DAL::executeSqlAssoc($query, 0);
95  $nls_format = $value[0];
96  $expected = 'YYYY-MM-DD HH24:MI:SS';
97  if ($nls_format !== $expected) {
98  trigger_error('NLS_DATE_FORMAT has not been set correctly. It needs to be '.$expected, E_USER_ERROR);
99  }
100 }
101 
102 $cached_table_columns = Array();
103 
104 // we need to do this before starting the transaction because the
105 // set_timestamp for postgres is required to start a transaction
106 $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
107 $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
108 $db =& $GLOBALS['SQ_SYSTEM']->db;
109 
110 install_stored_relations('functions');
111 
112 if (file_exists(SQ_DATA_PATH.'/private/db/table_columns.inc')) {
113  unlink(SQ_DATA_PATH.'/private/db/table_columns.inc');
114 }
115 
116 if (!db_install(SQ_CORE_PACKAGE_PATH.'/tables.xml')) {
117  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
118  trigger_error('TABLE INSTALL FAILURE', E_USER_ERROR);
119 }
120 
121 // install any tables needed by the packages
122 $packages = get_package_list();
123 
124 foreach ($packages as $package) {
125  $xml_file = SQ_PACKAGES_PATH.'/'.$package.'/tables.xml';
126  if (file_exists($xml_file)) {
127  echo "\n".'*** Package: '.$package."\n";
128  if (!db_install($xml_file)) {
129  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
130  trigger_error('TABLE INSTALL FAILURE', E_USER_ERROR);
131  }
132  install_stored_relations('functions', $package);
133  }
134 }
135 
136 // Install all views except for Roles-related views which are handled further below
137 install_stored_relations('views');
138 
139 $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
140 
141 if (!$fv->initRepository()) {
142  trigger_error('Unable to initialise File Versioning Repository', E_USER_ERROR);
143 }
144 
145 $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
146 
147 /*
148 * Verify that Roles views are all cool as determined by the system-wide config settings.
149 * This is especially important if we have upgraded from a previous version where Roles were
150 * disabled as at this point Matrix will have the default definitions.
151 */
152 
153 // With respect to #4440 Feature Request : Spliting System Roles into System Permission Roles and System Workflow Roles
154 // lets split up the constants and regenerate the config file. Also in this block decide if we have to re-create views
155 if (!defined('SQ_CONF_ENABLE_ROLES_PERM_SYSTEM') && !defined('SQ_CONF_ENABLE_ROLES_WF_SYSTEM')) {
156  if(defined('SQ_CONF_ENABLE_ROLES_SYSTEM') && SQ_CONF_ENABLE_ROLES_SYSTEM == '1' ) {
157  $vars['SQ_CONF_ENABLE_ROLES_PERM_SYSTEM'] = '1';
158  $vars['SQ_CONF_ENABLE_ROLES_WF_SYSTEM'] = '1';
159  $enabled = TRUE;
160  } else {
161  $vars['SQ_CONF_ENABLE_ROLES_PERM_SYSTEM'] = '0';
162  $vars['SQ_CONF_ENABLE_ROLES_WF_SYSTEM'] = '0';
163  $enabled = FALSE;
164  }
165  $cfg->save($vars, FALSE);
166 } else {
167  $enabled = ((SQ_CONF_ENABLE_ROLES_PERM_SYSTEM == '1' ) || (SQ_CONF_ENABLE_ROLES_WF_SYSTEM == '1'));
168 }
169 
170 
171 if (!defined('SQ_CONF_COOKIE_OPTION_HTTP_ONLY') || !defined('SQ_CONF_COOKIE_OPTION_SECURE')) {
172  if (!defined('SQ_CONF_COOKIE_OPTION_HTTP_ONLY')) {
173  $vars['SQ_CONF_COOKIE_OPTION_HTTP_ONLY'] = FALSE;
174  }
175  if (!defined('SQ_CONF_COOKIE_OPTION_SECURE')) {
176  $vars['SQ_CONF_COOKIE_OPTION_SECURE'] = FALSE;
177  }
178  $cfg->save($vars);
179 }
180 // Install the applicable views from the common_views_roles.xml file
181 echo "\n".'Configuring Roles Views... ';
182 $roles_configured = $cfg->configureRoleTables($enabled, SQ_CONF_ENABLE_GLOBAL_ROLES);
183 if ($roles_configured) {
184  echo "done\n\n";
185 } else {
186  echo "FAILED! Existing definition retained\n\n";
187 }
188 
189 // grant permissions to the tables for the secondary user
190 grant_secondary_user_perms();
191 
192 $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
193 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
194 
195 ?>