24 error_reporting(E_ALL);
25 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
27 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
28 if (empty($SYSTEM_ROOT)) {
29 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
33 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
34 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
38 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
40 $ROOT_ASSETID = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'1';
41 if ($ROOT_ASSETID == 1) {
42 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";
45 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
48 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
49 echo
"ERROR: Failed loggin in as root user\n";
54 $containerids = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($ROOT_ASSETID,
'bodycopy_container',
false);
55 foreach ($containerids as $containerid => $type_code_data) {
56 $type_code = $type_code_data[0][
'type_code'];
57 $container = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($containerid, $type_code);
58 printContainerName(
'Container #'.$container->id);
61 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($container->id,
'links')) {
62 printUpdateStatus(
'LOCK');
63 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($container);
67 $edit_fns = $container->getEditFns();
68 if (!$edit_fns->generateContentFile($container)) {
69 printUpdateStatus(
'FAILED');
70 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($container);
75 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($container->id,
'links')) {
76 printUpdateStatus(
'!!');
77 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($container);
80 printUpdateStatus(
'OK');
81 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($container);
96 function printContainerName($name)
98 printf (
'%s%'.(30 - strlen($name)).
's', $name,
'');
111 function printUpdateStatus($status)
113 echo
"[ $status ]\n";