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";
19 echo
'Are you sure you want to continue? (y/N): ';
20 $force_denied = rtrim(fgets(STDIN, 4094));
21 if (strtoupper($force_denied) !=
'Y') {
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);
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";
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";
42 define(
'SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
43 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
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";
51 $USER = (isset($_SERVER[
'argv'][3])) ? $_SERVER[
'argv'][3] :
'';
53 echo
"ERROR: You need to supply a user as the third argument\n";
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";
62 $GRANTED = (isset($_SERVER[
'argv'][5]) && $_SERVER[
'argv'][5] ==
'y') ?
'1' :
'0';
63 $CHILDREN = (isset($_SERVER[
'argv'][6]) && $_SERVER[
'argv'][6] ==
'y') ? TRUE : FALSE;
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);
70 echo
'START PERMISSION CHANGE'.
"\n";
71 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
73 'permission_changes' => Array(
75 'permission' => $available_permissions[$PERMISSION],
76 'granted' => $GRANTED,
77 'assetids' => Array($ROOT_NODE),
79 'previous_access' => NULL,
80 'cascades' => $CHILDREN,
84 $errors = $hh->freestyleHipo(
'hipo_job_edit_permissions', $vars);
86 if (!empty($errors)) {
87 echo
"... But with errors!\n";
88 foreach ($errors as $error) {
90 $line = array_get_index($error,
'message',
'');
99 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();