Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
system_integrity_internal_links.php
1 <?php
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);
26 
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";
30  exit();
31 }
32 
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";
35  exit();
36 }
37 
38 require_once $SYSTEM_ROOT.'/core/include/init.inc';
39 
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";
43 }
44 
45 $root_user = &$GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
46 
47 // log in as root
48 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
49  echo "Failed loggin in as root user\n";
50  exit();
51 }
52 
53 // go trough each wysiwyg in the system, lock it, validate it, unlock it
54 $wysiwygids = $GLOBALS['SQ_SYSTEM']->am->getChildren($ROOT_ASSETID, 'content_type_wysiwyg', false);
55 foreach ($wysiwygids as $wysiwygid => $type_code_data) {
56  $type_code = $type_code_data[0]['type_code'];
57  $wysiwyg = &$GLOBALS['SQ_SYSTEM']->am->getAsset($wysiwygid, $type_code);
58  printWYSIWYGName('WYSIWYG #'.$wysiwyg->id);
59 
60  // try to lock the WYSIWYG
61  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($wysiwyg->id, 'attributes')) {
62  printUpdateStatus('LOCK');
63  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($wysiwyg);
64  continue;
65  }
66 
67  $old_html = $wysiwyg->attr('html');
68  $new_html = preg_replace('|http[s]?://[^\s]+(\?a=[0-9]+)|', './\\1', $old_html);
69  if (!$wysiwyg->setAttrValue('html', $new_html) || !$wysiwyg->saveAttributes()) {
70  printUpdateStatus('FAILED');
71  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($container);
72  continue;
73  }
74 
75  // try to unlock the WYSIWYG
76  if (!$GLOBALS['SQ_SYSTEM']->am->releaseLock($wysiwyg->id, 'attributes')) {
77  printUpdateStatus('!!');
78  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($wysiwyg);
79  continue;
80  }
81 
82  printUpdateStatus('OK');
83  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($wysiwyg);
84 
85 }//end foreach
86 
87 
98 function printWYSIWYGName($name)
99 {
100  printf ('%s%'.(30 - strlen($name)).'s', $name, '');
101 
102 }//end printWYSIWYGName()
103 
104 
113 function printUpdateStatus($status)
114 {
115  echo "[ $status ]\n";
116 
117 }//end printUpdateStatus()
118 
119 
120 ?>