Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
give_funnelback_permission.php
1 <?php
16 ini_set('mem_limit', '-1');
17 error_reporting(E_ALL);
18 if ((php_sapi_name() != 'cli')) {
19  trigger_error("You can only run this script from the command line", E_USER_ERROR);
20 }
21 
22 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
23 if (empty($SYSTEM_ROOT) || !is_dir($SYSTEM_ROOT)) {
24  trigger_error("You need to supply the path to the System Root as the first argument", E_USER_ERROR);
25  exit();
26 }
27 define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
28 require_once $SYSTEM_ROOT.'/core/include/init.inc';
29 
30 // Other options
31 $ROOT_NODE = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : '';
32 if (empty($ROOT_NODE)) {
33  trigger_error("You need to supply a root node as the second argument", E_USER_ERROR);
34  exit();
35 }
36 
37 // ask for the root password for the system
38 echo 'Enter the root password for "'.SQ_CONF_SYSTEM_NAME.'": ';
39 $root_password = rtrim(fgets(STDIN, 4094));
40 
41 // check that the correct root password was entered
42 $root_user =& $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
43 if (!$root_user->comparePassword($root_password)) {
44  echo "ERROR: The root password entered was incorrect";
45  exit();
46 }
47 $GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user);
48 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
49 
50 // Load the funnelback manager
51 $fm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('funnelback_manager');
52 $user = NULL;
53 $user_id = $fm->attr('user');
54 if (!empty($user_id)) {
55  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($user_id, '', TRUE);
56 }//end if
57 if (is_null($user)) {
58  trigger_error("No user asset specified in Matrix", E_USER_ERROR);
59  exit();
60 }//end if
61 
62 // Start the process
63 echo 'APPLYING PERMISSIONS FOR '.$user->name."\n";
64 $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
65 $vars = Array(
66  'permission_changes' => Array(
67  Array(
68  'permission' => SQ_PERMISSION_WRITE,
69  'granted' => '1',
70  'assetids' => Array($ROOT_NODE),
71  'userid' => $user->id,
72  'previous_access' => NULL,
73  'cascades' => TRUE,
74  ),
75  ),
76  );
77 $errors = $hh->freestyleHipo('hipo_job_edit_permissions', $vars);
78 echo 'FINISHED';
79 if (!empty($errors)) {
80  echo "... But with errors!\n";
81  foreach ($errors as $error) {
82  echo "\t".
83  $line = array_get_index($error, 'message', '');
84  if (!empty($line)) {
85  echo "\t".$line."\n";
86  }//end if
87  }//end foreach
88 } else {
89  echo "\n";
90 }//end if
91 
92 $GLOBALS['SQ_SYSTEM']->restoreCurrentUser();
93 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
94 ?>