24 error_reporting(E_ALL);
25 if ((php_sapi_name() !=
'cli')) {
26 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
29 $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 echo
"\nWarning: Please make sure you have the correct permission to remove cache files.\n";
43 echo
'SQ_CACHE_PATH is \''.SQ_CACHE_PATH.
"'\n\n";
45 echo
'Enter the root password for "'.SQ_CONF_SYSTEM_NAME.
'": ';
47 $root_password = rtrim(fgets(STDIN, 4094));
51 $root_user = & $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
52 if (!$root_user->comparePassword($root_password)) {
53 echo
"ERROR: The root password entered was incorrect\n";
58 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
59 echo
"ERROR: Failed login in as root user\n";
63 $cache_path_len = strlen(SQ_CACHE_PATH) + 1;
66 $cache_manager =& $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
67 $valid_files = $cache_manager->getAllFilePaths(
'col');
70 exec(
'find '.SQ_CACHE_PATH.
" -type d -name '[0-9]*'", $current_dirs);
74 foreach ($current_dirs as $dir) {
76 $current_files = Array();
78 exec(
"find $dir -type f -name '[a-z0-9]*'", $current_files);
79 foreach ($current_files as $file) {
80 $file_name = substr($file, $cache_path_len);
81 if (!in_array($file_name, $valid_files)) {
83 printFileName($file_name);
84 $status = @unlink(SQ_CACHE_PATH.
'/'.$file_name);
85 $ok = ($status) ?
'OK' :
'FAILED';
87 if ($status) $count++;
93 echo
"\nSummary: $count/$total cache file(s) removed.\n";
94 if ($count != $total) {
95 $problematic = $total - $count;
96 trigger_error(
"$problematic file(s) cannot be removed, please check file permission.", E_USER_WARNING);
108 function printFileName($file_name)
110 $str =
"\tRemoving ".$file_name;
111 printf (
'%s%'.(50 - strlen($str)).
's', $str,
'');
124 function printStatus($status)
126 echo
"[ $status ]\n";