27 error_reporting(E_ALL);
28 if ((php_sapi_name() !=
'cli')) {
29 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
32 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
33 if (empty($SYSTEM_ROOT)) {
34 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
38 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
39 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
43 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
45 $root_user = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
46 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
47 echo
"ERROR: Failed logging in as root user\n";
52 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
54 $am = $GLOBALS[
'SQ_SYSTEM']->am;
57 echo
'Moving Squid Cache preferences to External Tools Config'.
"\n";
60 echo
'Moving global preferences... ';
61 $global_prefs_file = SQ_DATA_PATH.
'/private/conf/preferences.inc';
62 if (!_movePreference($global_prefs_file)) $count++;
65 echo
'Updating global preferences... ';
66 if (!_upgrade($global_prefs_file)) $count++;
69 $groupids = $am->getTypeAssetids(
'user_group');
70 foreach ($groupids as $groupid) {
71 $asset = $am->getAsset($groupid);
72 echo
'Updating preferences for '.$asset->name.
' ('.$asset->id.
')... ';
73 $current_prefs_file = $asset->data_path.
'/.preferences.inc';
74 if (!_upgrade($current_prefs_file)) $count++;
79 echo
"There were $count errors in upgrading the Squid Cache preferences.\nThese files may need to be reviewed manually.\n";
82 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
94 function _movePreference($prefs_file)
97 if (!file_exists($prefs_file)) {
98 echo
"Preference file not found\n";
101 include_once($prefs_file);
103 if (isset($preferences[
'tool_clear_squid_cache'])) {
104 $vars[
'SQ_TOOL_SQUID_CACHE_HOSTNAMES'] = $preferences[
'tool_clear_squid_cache'][
'SQ_SQUID_CACHE_HOSTNAMES'][
'default'];
105 $vars[
'SQ_TOOL_SQUID_CACHE_PATH'] = $preferences[
'tool_clear_squid_cache'][
'SQ_SQUID_CACHE_PATH'][
'default'];
106 $vars[
'SQ_TOOL_SQUID_CACHE_PORT'] = $preferences[
'tool_clear_squid_cache'][
'SQ_SQUID_CACHE_PORT'][
'default'];
107 $vars[
'SQ_TOOL_SQUID_CACHE_OPTION'] = $preferences[
'tool_clear_squid_cache'][
'SQ_SQUID_CACHE_OPTION'][
'default'];
108 $vars[
'SQ_TOOL_SQUID_CACHE_SLASH'] = $preferences[
'tool_clear_squid_cache'][
'SQ_SQUID_CACHE_SLASH'][
'default'];
109 $vars[
'SQ_TOOL_SQUID_URL_PORT'] = $preferences[
'tool_clear_squid_cache'][
'SQ_SQUID_URL_PORT'][
'default'];
112 require_once SQ_INCLUDE_PATH.
'/external_tools_config.inc';
114 if (!$cfg->save($vars, FALSE, TRUE)) {
115 echo
"Preference tool_clear_squid_cache can not be saved\n";
121 echo
"Preference not found\n";
146 function _upgrade($prefs_file)
149 if (!file_exists($prefs_file)) {
153 include($prefs_file);
154 if (isset($preferences[
'tool_clear_squid_cache'])) {
155 unset($preferences[
'tool_clear_squid_cache']);
157 if (!_savePreferences($preferences, $prefs_file)) {
158 echo
"Error saving file\n";
187 function _savePreferences($preferences, $prefs_file)
189 if (empty($preferences))
return FALSE;
191 $str =
'<'.
'?php $preferences = '.var_export($preferences, TRUE).
'; ?'.
'>';
194 if (file_exists($prefs_file)) {
199 $old_version = $prefs_file.
'.'.$i;
200 }
while (file_exists($old_version));
202 if (!copy($prefs_file, $old_version)) {
208 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
210 if (!create_directory(dirname($prefs_file))) {
215 if (!string_to_file($str, $prefs_file)) {