25 error_reporting(E_ALL);
26 if ((php_sapi_name() !=
'cli')) {
27 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 $MAP_ASSETID = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'0';
45 $map_asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($MAP_ASSETID),
'asset',FALSE);
47 if (empty($MAP_ASSETID) || empty($map_asset_info)) {
48 echo
"ERROR: You need to supply the assetid of a valid asset that orphaned assets will be mapped to as the second argument\n";
51 $map_asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($MAP_ASSETID);
54 $ROOT_ASSETID = (isset($_SERVER[
'argv'][3])) ? $_SERVER[
'argv'][3] :
'1';
55 if ($ROOT_ASSETID == 1) {
56 echo
"\nWARNING: You are running this integrity checker on the whole system.\nThis is fine, but it may take a long time\n\n";
60 echo
'Enter the root password for "'.SQ_CONF_SYSTEM_NAME.
'": ';
62 $root_password = rtrim(fgets(STDIN, 4094));
66 $root_user =& $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
67 if (!$root_user->comparePassword($root_password)) {
68 echo
"ERROR: The root password entered was incorrect\n";
73 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
74 echo
"ERROR: Failed login in as root user\n";
78 $db =& $GLOBALS[
'SQ_SYSTEM']->db;
80 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
83 $assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($ROOT_ASSETID,
'asset', FALSE);
84 foreach ($assets as $assetid => $type_code_data) {
85 $type_code = $type_code_data[0][
'type_code'];
87 printAssetName($assetid);
99 link_type <> :link_type';
109 foreach (array_keys($links) as $linkid) {
110 $link =& $links[$linkid];
111 if ($link[
'linkid'] == 1)
continue;
113 $major_asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($link[
'majorid']),
'asset',FALSE);
115 if (empty($major_asset_info)) {
122 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
123 $db =& $GLOBALS[
'SQ_SYSTEM']->db;
126 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
129 if ($link[
'link_type'] & SQ_SC_LINK_SIGNIFICANT) {
135 SUBSTR(t.treeid, 1, (LENGTH(t.treeid) - '.SQ_CONF_ASSET_TREE_SIZE.
'))
144 num_kids = num_kids - 1
146 treeid in ('.$sub_sql.
')';
162 AND ct.treeid LIKE pt.treeid || '.MatrixDAL::quote(
'%').
'
163 AND ct.treeid > pt.treeid';
168 treeid in ('.$sub_sql.
')';
184 linkid = :old_linkid';
198 sort_order = sort_order - 1
202 sort_order > :sort_order';
219 $asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $type_code);
220 $asset->linksUpdated();
222 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
223 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
224 unset($links[$linkid]);
229 printUpdateStatus(
'FAILED');
234 $asset =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $type_code);
235 if (!$GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($map_asset, $asset, SQ_LINK_TYPE_2,
'Orphaned Asset')) {
236 printUpdateStatus(
'FAILED');
243 printUpdateStatus(
'OK');
245 printUpdateStatus(
'--');
247 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
251 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
264 function printAssetName($assetid)
266 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($assetid);
267 $str =
'[ #'.$assetid.
' ]'.$asset_info[$assetid][
'name'];
268 if (strlen($str) > 66) {
269 $str = substr($str, 0, 66).
'...';
271 printf (
'%s%'.(70 - strlen($str)).
's', $str,
'');
284 function printUpdateStatus($status)
286 echo
"[ $status ]\n";