Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
system_integrity_content_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 "ERROR: Failed loggin in as root user\n";
50  exit();
51 }
52 
53 // go trough each bodycopy_container in the system, lock it, validate it, unlock it
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);
59 
60  // try to lock the container
61  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($container->id, 'links')) {
62  printUpdateStatus('LOCK');
63  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($container);
64  continue;
65  }
66 
67  $edit_fns = $container->getEditFns();
68  if (!$edit_fns->generateContentFile($container)) {
69  printUpdateStatus('FAILED');
70  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($container);
71  continue;
72  }
73 
74  // try to unlock the container
75  if (!$GLOBALS['SQ_SYSTEM']->am->releaseLock($container->id, 'links')) {
76  printUpdateStatus('!!');
77  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($container);
78  continue;
79  }
80  printUpdateStatus('OK');
81  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($container);
82 
83 }//end foreach
84 
85 
96 function printContainerName($name)
97 {
98  printf ('%s%'.(30 - strlen($name)).'s', $name, '');
99 
100 }//end printContainerName()
101 
102 
111 function printUpdateStatus($status)
112 {
113  echo "[ $status ]\n";
114 
115 }//end printUpdateStatus()
116 
117 
118 ?>