27 error_reporting(E_ALL);
28 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
30 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
31 if (empty($SYSTEM_ROOT)) {
32 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
36 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
37 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
41 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
43 $ROOT_ASSETID = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'1';
44 if ($ROOT_ASSETID == 1) {
45 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";
48 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
51 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
52 echo
"ERROR: Failed login in as root user\n";
57 $assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($ROOT_ASSETID,
'user',
false);
58 foreach ($assets as $assetid => $type_code_data) {
59 $type_code = $type_code_data[0][
'type_code'];
60 $asset = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $type_code);
61 printAssetName($asset);
64 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($asset->id,
'permissions')) {
65 printUpdateStatus(
'LOCK');
66 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
71 if (!$GLOBALS[
'SQ_SYSTEM']->am->setPermission($asset->id, $asset->id, SQ_PERMISSION_READ, 1)) {
72 printUpdateStatus(
'FAILED');
73 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
77 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'asset',
false,
'major',
'', 1);
78 foreach ($links as $link) {
79 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($link[
'minorid'],
'permissions')) {
80 printUpdateStatus(
'SUB LOCK');
81 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
85 if (!$GLOBALS[
'SQ_SYSTEM']->am->setPermission($link[
'minorid'], $asset->id, SQ_PERMISSION_READ, 1)) {
86 printUpdateStatus(
'SUB FAILED');
87 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
92 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($link[
'minorid'],
'permissions')) {
93 printUpdateStatus(
'SUB !!');
94 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
100 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($asset->id,
'permissions')) {
101 printUpdateStatus(
'!!');
102 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
106 printUpdateStatus(
'OK');
107 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
122 function printAssetName(&$asset)
124 $str = $asset->name .
' [ # '. $asset->id.
' ]';
125 printf (
'%s%'.(40 - strlen($str)).
's', $str,
'');
138 function printUpdateStatus($status)
140 echo
"[ $status ]\n";