Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
system_integrity_fix_public_files.php
1 <?php
25 if (ini_get('memory_limit') != '-1') ini_set('memory_limit', '-1');
26 
27 error_reporting(E_ALL);
28 if (count($_SERVER['argv']) < 3 || php_sapi_name() != 'cli') {
29  echo "This script needs to be run in the following format:\n\n";
30  echo "\tphp system_integrity_fix_public_files.php SYSTEM_ROOT ROOT_ID\n\n";
31  exit(1);
32 }
33 
34 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
35 if (empty($SYSTEM_ROOT)) {
36  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
37  exit();
38 }
39 
40 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
41  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
42  exit();
43 }
44 
45 require_once $SYSTEM_ROOT.'/core/include/init.inc';
46 
47 $ROOT_ID = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : '';
48 assert_valid_assetid($ROOT_ID, "The ROOT_ID '$ROOT_ID' specified is invalid");
49 
50 $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";
53  exit();
54 }
55 
56 //get children of the tree root asset which are file and its descendant types
57 $assetids = $GLOBALS['SQ_SYSTEM']->am->getChildren($ROOT_ID, 'file', FALSE);
58 //if the tree root asset is file type, include it
59 if ($ROOT_ID != '1') {
60  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($ROOT_ID);
61  if ($GLOBALS['SQ_SYSTEM']->am->isTypeDecendant($asset->type(), 'file')) {
62  $assetids[$asset->id] = Array(0 => Array('type_code' => $asset->type()));
63  }
64 }
65 
66 foreach ($assetids as $assetid => $asset_info) {
67  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
68  //Use this public function to access _checkFileState function which
69  //looks after the placing and removing of files in the public directory.
70  $asset->permissionsUpdated();
71  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
72 }
73 
74 $GLOBALS['SQ_SYSTEM']->restoreCurrentUser();
75 
76 ?>