Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
dejavu_management.php
1 <?php
11 error_reporting(E_ALL);
12 if ((php_sapi_name() != 'cli')) {
13  trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
14 }
15 
16 require_once 'Console/Getopt.php';
17 
18 $shortopt = 's:';
19 $longopt = Array('enable', 'disable', 'forget', 'status', 'disable_force');
20 
21 $args = Console_Getopt::readPHPArgv();
22 array_shift($args);
23 $options = Console_Getopt::getopt($args, $shortopt, $longopt);
24 
25 if ($options instanceof PEAR_Error) {
26  usage();
27 }
28 
29 if (empty($options[0])) usage();
30 
31 $SYSTEM_ROOT = '';
32 $ACTION = '';
33 
34 foreach ($options[0] as $option) {
35  switch ($option[0]) {
36  case 's':
37  if (empty($option[1])) usage();
38  if (!is_dir($option[1])) usage();
39  $SYSTEM_ROOT = $option[1];
40  break;
41 
42  default:
43  $ACTION = $option[0];
44  break;
45  }
46 }
47 
48 if (empty($SYSTEM_ROOT)) {
49  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
50  usage();
51 }
52 
53 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
54  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
55  usage();
56 }
57 
58 if($ACTION === '--disable_force') {
59  // forcibly disable deja vu before even include init.inc
60  file_put_contents($SYSTEM_ROOT.'/data/private/conf/.dejavu', '0');
61  echo "Deja Vu is forcibly disabled.\n";
62  exit();
63 }
64 
65 require_once $SYSTEM_ROOT.'/core/include/init.inc';
66 require_once $SYSTEM_ROOT.'/core/include/deja_vu.inc';
67 
68 $deja_vu = new Deja_Vu();
69 switch ($ACTION) {
70  case '--status':
71  if ($deja_vu->enabled() == FALSE) {
72  echo "Deja Vu is currently disabled.\n";
73  } else {
74  echo "Deja Vu is currently enabled.\n";
75  }
76  break;
77  case '--enable':
78  if ($deja_vu->enabled() == TRUE) {
79  echo "Deja Vu is already enabled.\n";
80  } else {
81  // Make sure memcache is setup properly before enable deja vu.
82  assert_true(extension_loaded('memcache'), 'Cannot use Deja Vu; it requires the memcache PECL extension installed within , which is not installed');
83  assert_true(is_file(SQ_DATA_PATH.'/private/conf/memcache.inc'), 'Cannot use Deja Vu; the Memcache configuration file is not set');
84 
85  $memcache_conf = require(SQ_DATA_PATH.'/private/conf/memcache.inc');
86  $hosts =& $memcache_conf['hosts'];
87  $services =& $memcache_conf['services'];
88 
89  assert_true(count($hosts) > 0, 'Cannot use Deja Vu; no hosts are defined in the Memcache configuration file');
90  assert_true(array_key_exists('deja_vu', $services) === TRUE, 'Cannot use Deja Vu; no Memcache hosts are assigned');
91  assert_true(count($services['deja_vu']) > 0, 'Cannot use Deja Vu; no Memcache hosts are assigned');
92 
93  echo "Enabling Deja Vu...\n";
94  if ($deja_vu->enable()) {
95  $d_vu = new Deja_Vu();
96  if ($d_vu) {
97  echo "Forgetting everything previously remembered...\n";
98  if ($d_vu->forgetAll()) {
99  echo "[DONE]\n";
100  break;
101  }
102  } else{
103  echo "what?\n";
104  }
105  }
106  echo "[FAILED]\n";
107  }
108  break;
109  case '--disable':
110  if ($deja_vu->enabled() == FALSE) {
111  echo "Deja Vu is already disabled.\n";
112  } else {
113  echo "Disabling Deja Vu...\n";
114  if ($deja_vu->disable()) {
115  echo "[DONE]\n";
116  } else {
117  echo "[FAILED]\n";
118  }
119  }
120  break;
121  case '--forget':
122  if ($deja_vu->enabled() == FALSE) {
123  echo "Deja Vu is currently disabled.\n";
124  } else {
125  echo "Forgetting everything in Deja Vu...\n";
126  if ($deja_vu->forgetAll()) {
127  echo "[DONE]\n";
128  } else {
129  echo "[FAILED]\n";
130  }
131  }
132  break;
133  default:
134  usage();
135  break;
136 }
137 
138 
145 function usage()
146 {
147  echo "\nUSAGE: dejavu_management.php -s <system_root> [--enable] [--disable] [--forget]\n".
148  "--enable Enables Deja Vu in MySource Matrix\n".
149  "--disable Disables Deja Vu in MySource Matrix\n".
150  "--disable_force Forcibly disables Deja Vu by editing control file\n".
151  "--forget Forgets all Deja Vu data in MySource Matrix\n".
152  "--status Checks the current Deja Vu status\n".
153  "\nNOTE: only one of [--enable --disable --forget] option is allowed to be specified\n";
154  exit();
155 
156 }//end usage()
157 ?>