25 error_reporting(E_ALL);
26 if ((php_sapi_name() !=
'cli')) 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] :
'';
29 if (empty($SYSTEM_ROOT)) {
30 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
34 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
35 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
39 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
41 $ROOT_ASSETID = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'1';
42 if ($ROOT_ASSETID == 1) {
43 echo
"\nWARNING: You are running this integrity checker on the whole system.\nThis is fine but:\n\tit may take a long time; and\n\tit will acquire locks on many of your assets (meaning you wont be able to edit content for a while)\n\n";
46 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
49 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
50 echo
"ERROR: Failed login in as root user\n";
54 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
55 $db =& $GLOBALS[
'SQ_SYSTEM']->db;
58 echo
'Cleaning up permissions...'.
"\n";
66 foreach ($user_ids as $user_id) {
68 $id_parts = explode(
':', $user_id);
69 if (isset($id_parts[1])) {
70 $real_assetid = $id_parts[0];
71 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($real_assetid,
'', TRUE);
72 if (is_null($bridge)) {
76 $asset = $bridge->getAsset($user_id,
'', TRUE, TRUE);
78 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($bridge);
81 $asset = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($user_id,
'', TRUE);
83 if (!is_null($asset)) {
85 printAssetName($asset);
86 printUpdateStatus(
'OK');
89 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
94 $dummy_asset->id = $user_id;
95 $dummy_asset->name =
'Unknown Asset';
97 printAssetName($dummy_asset);
100 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
103 $sql =
'DELETE FROM sq_ast_perm WHERE userid = :userid';
109 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
110 printUpdateStatus(
'FIXED');
113 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
114 printUpdateStatus(
'FAILED');
122 echo
'Cleaning up roles...'.
"\n";
131 foreach ($user_ids as $user_id) {
133 $id_parts = explode(
':', $user_id);
134 if (isset($id_parts[1])) {
135 $real_assetid = $id_parts[0];
136 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($real_assetid,
'', TRUE);
137 if (is_null($bridge)) {
141 $asset = $bridge->getAsset($user_id,
'', TRUE, TRUE);
143 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($bridge);
146 $asset = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($user_id,
'', TRUE);
148 if (!is_null($asset)) {
150 printAssetName($asset);
151 printUpdateStatus(
'OK');
154 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
159 $dummy_asset->id = $user_id;
160 $dummy_asset->name =
'Unknown Asset';
162 printAssetName($dummy_asset);
165 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
168 $sql =
'DELETE FROM sq_ast_role WHERE userid = :userid';
174 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
175 printUpdateStatus(
'FIXED');
178 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
179 printUpdateStatus(
'FAILED');
195 function printAssetName(&$asset)
197 $str = $asset->name .
' [ # '. $asset->id.
' ]';
198 printf (
'%s%'.(80 - strlen($str)).
's', $str,
'');
211 function printUpdateStatus($status)
213 echo
"[ $status ]\n";