23 error_reporting(E_ALL);
24 if ((php_sapi_name() !=
'cli')) {
25 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
28 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
30 if (empty($SYSTEM_ROOT)) {
31 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
35 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
36 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
40 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
42 $root_user = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
45 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
46 echo
"ERROR: Failed logging in as root user\n";
50 $am = $GLOBALS[
'SQ_SYSTEM']->am;
54 echo
'Updating global preferences ... ';
55 $global_prefs_file = SQ_DATA_PATH.
'/private/conf/preferences.inc';
56 if (!_upgrade($global_prefs_file)) $count++;
59 $groupids = $am->getTypeAssetids(
'user_group');
60 foreach ($groupids as $groupid) {
61 $asset = $am->getAsset($groupid);
62 echo
'Updating preferences for '.$asset->name.
' ('.$asset->id.
')... ';
63 $current_prefs_file = $asset->data_path.
'/.preferences.inc';
64 if (!_upgrade($current_prefs_file)) $count++;
69 echo
"There were $count errors in upgrading the preferences.\nThese files may need to be reviewed manually.\n";
81 function _upgrade($prefs_file)
84 if (!file_exists($prefs_file)) {
85 echo
"No Preferences found\n";
88 include_once($prefs_file);
90 if (isset($preferences[
'user'][
'SQ_USER_SESSION_PREFS'][
'default'])) {
91 $current = $preferences[
'user'][
'SQ_USER_SESSION_PREFS'][
'default'];
92 $test = array_pop($preferences[
'user'][
'SQ_USER_SESSION_PREFS'][
'default']);
93 if (!is_array($test)) {
94 unset($preferences[
'user'][
'SQ_USER_SESSION_PREFS'][
'default']);
95 $preferences[
'user'][
'SQ_USER_SESSION_PREFS'][
'default'] = Array($current);
97 if (!_savePreferences($preferences, $prefs_file)) {
98 echo
"Error saving file\n";
123 function _savePreferences($preferences, $prefs_file)
125 if (empty($preferences))
return FALSE;
127 $str =
'<'.
'?php $preferences = '.var_export($preferences, TRUE).
'; ?'.
'>';
130 if (file_exists($prefs_file)) {
135 $old_version = $prefs_file.
'.'.$i;
136 }
while (file_exists($old_version));
138 if (!copy($prefs_file, $old_version)) {
144 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
146 if (!create_directory(dirname($prefs_file))) {
151 if (!string_to_file($str, $prefs_file)) {