Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
funnelback_reindex.php
1 <?php
17 error_reporting(E_ALL);
18 if ((php_sapi_name() != 'cli')) {
19  trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
20 }
21 
22 // Get the arguments
23 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
24 if (empty($SYSTEM_ROOT) || !is_dir($SYSTEM_ROOT)) {
25  trigger_error("You need to supply the path to the System Root as the first argument\n", E_USER_ERROR);
26 }
27 $root_collection = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : '';
28 
29 define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
30 require_once $SYSTEM_ROOT.'/core/include/init.inc';
31 
32 $root_user =& $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
33 $GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user);
34 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
35 
36 // THE INDEXING STATUS SHOULD BE TURNED ON
37 $fm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('funnelback_manager');
38 $collections = $fm->attr('collections');
39 if (is_null($fm)) {
40  trigger_localised_error('FNB0020', E_USER_WARNING);
41  exit();
42 }//end if
43 if (!$fm->attr('indexing')) {
44  echo "\n\nBEFORE RUNNING THE SCRIPT, PLEASE CHECK THAT THE INDEXING STATUS IS TURNED ON\n";
45  echo 'Note: You can change this option from the backend "System Management" > "Funnelback Manager" > "Details"'."\n\n";
46  exit();
47 }
48 
49 // stop the script if the root collection is not specified or the collection that is specified isn't set
50 if (!empty($root_collection) && !isset($collections[$root_collection])) {
51  echo "\n\nInvalid Collection ID passed in\n";
52  exit();
53 }//end if
54 
55 // Check for a lock file
56 if (file_exists(SQ_TEMP_PATH.'/funnelback.indexer')) {
57  trigger_localised_error('FNB0019', E_USER_WARNING);
58  exit();
59 }//end if
60 
61 // Create a lock file
62 touch(SQ_TEMP_PATH.'/funnelback.indexer');
63 
64 // Start indexing
65 $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
66 $vars = Array(
67  'collections'=> ((empty($root_collection)) ? Array() : $root_collection),
68  );
69 $errors = $hh->freestyleHipo('hipo_job_funnelback_reindex', $vars, SQ_PACKAGES_PATH.'/funnelback/hipo_jobs');
70 if (!empty($errors)) {
71  echo 'Funnelback Reindexing FAILED'."\n";
72  foreach ($errors as $error) {
73  $line = array_get_index($error, 'message', '');
74  if (!empty($line)) {
75  echo $line."\n";
76  }//end if
77  }//end foreach
78 }//end if
79 
80 // Remove if finished AND failed
81 if (file_exists(SQ_TEMP_PATH.'/funnelback.indexer')) {
82  unlink(SQ_TEMP_PATH.'/funnelback.indexer');
83 }//end if
84 
85 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
86 ?>