Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
permission_change.php
1 <?php
17 echo 'This script is deprecated because it has memory issue when used on large amount of assets. Use system_apply_permission.php instead.'."\n";
18 // ask for the root password for the system
19 echo 'Are you sure you want to continue? (y/N): ';
20 $force_denied = rtrim(fgets(STDIN, 4094));
21 if (strtoupper($force_denied) != 'Y') {
22  exit;
23 }
24 
25 if (ini_get('memory_limit') != '-1') ini_set('memory_limit', '-1');
26 error_reporting(E_ALL);
27 if ((php_sapi_name() != 'cli')) {
28  trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
29 }
30 
31 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
32 if (empty($SYSTEM_ROOT)) {
33  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
34  exit();
35 }
36 
37 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
38  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
39  exit();
40 }
41 
42 define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
43 require_once $SYSTEM_ROOT.'/core/include/init.inc';
44 
45 // Other options
46 $ROOT_NODE = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : '';
47 if (empty($ROOT_NODE)) {
48  echo "ERROR: You need to supply a root node as the second argument\n";
49  exit();
50 }
51 $USER = (isset($_SERVER['argv'][3])) ? $_SERVER['argv'][3] : '';
52 if (empty($USER)) {
53  echo "ERROR: You need to supply a user as the third argument\n";
54  exit();
55 }
56 $available_permissions = Array('read'=>SQ_PERMISSION_READ, 'write'=>SQ_PERMISSION_WRITE, 'admin'=>SQ_PERMISSION_ADMIN);
57 $PERMISSION = (isset($_SERVER['argv'][4])) ? $_SERVER['argv'][4] : '';
58 if (empty($PERMISSION) || !array_key_exists($PERMISSION, $available_permissions)) {
59  echo "ERROR: You need to supply a permission as the fourth argument\n";
60  exit();
61 }
62 $GRANTED = (isset($_SERVER['argv'][5]) && $_SERVER['argv'][5] == 'y') ? '1' : '0';
63 $CHILDREN = (isset($_SERVER['argv'][6]) && $_SERVER['argv'][6] == 'y') ? TRUE : FALSE;
64 
65 // Start the process
66 $root_user =& $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
67 $GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user);
68 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
69 
70 echo 'START PERMISSION CHANGE'."\n";
71 $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
72 $vars = Array(
73  'permission_changes' => Array(
74  Array(
75  'permission' => $available_permissions[$PERMISSION],
76  'granted' => $GRANTED,
77  'assetids' => Array($ROOT_NODE),
78  'userid' => $USER,
79  'previous_access' => NULL,
80  'cascades' => $CHILDREN,
81  ),
82  ),
83  );
84 $errors = $hh->freestyleHipo('hipo_job_edit_permissions', $vars);
85 echo 'FINISHED';
86 if (!empty($errors)) {
87  echo "... But with errors!\n";
88  foreach ($errors as $error) {
89  echo "\t".
90  $line = array_get_index($error, 'message', '');
91  if (!empty($line)) {
92  echo "\t".$line."\n";
93  }//end if
94  }//end foreach
95 } else {
96  echo "\n";
97 }//end if
98 
99 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
100 ?>