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