Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
upgrade_of_funnelback_binary_to_9_1.php
1 <?php
31 if (ini_get('memory_limit') != '-1') ini_set('memory_limit', -1);
32 error_reporting(E_ALL);
33 
34 if (php_sapi_name() != 'cli') {
35  trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
36 }
37 
38 if (count($argv) < 1) {
39  echo "USAGE : php scripts/upgrade_of_funnelback_binary_to_9_1.php <SYSTEM_ROOT>\n";
40  exit();
41 }//end if
42 
43 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
44 if (empty($SYSTEM_ROOT)) {
45  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
46  exit();
47 }
48 
49 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
50  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
51  exit();
52 }
53 
54 require_once $SYSTEM_ROOT.'/core/include/init.inc';
55 $root_user = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
56 
57 // log in as root
58 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
59  echo "ERROR: Failed logging in as root user\n";
60  exit(1);
61 }//end if
62 
63 $fbm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('funnelback_manager');
64 $collections = $fbm->getCollections();
65 
66 foreach($collections as $index => $collection ) {
67  $file_paths = Array();
68  $all_good = TRUE;
69  printCollection($index, $collection['name']);
70  $data_path = $fbm->getCollectionDataPath($index).'/conf/';
71  $file_paths['contextual_navigation.cfg'] = 'fluster.cfg';
72  $file_paths['query_expansion.cfg'] = 'synonyms.cfg';
73  $file_paths['best_bets.cfg'] = 'featured_pages.cfg';
74 
75  foreach ($file_paths as $new_path => $file_path) {
76  if(file_exists($data_path.$file_path)) {
77  if(!copy($data_path.$file_path, $data_path.$new_path)) {
78  bam($data_path.$file_path);
79  $all_good = FALSE;
80  }
81  }
82  }
83 
84  if ($all_good) {
85  printUpdateStatus('OK');
86  } else {
87  printUpdateStatus('FAILED');
88  }
89 }
90 
91 
92 
104 function printCollection($id, $name)
105 {
106  $str = '[ #'.$id.' ]'.$name;
107  if (strlen($str) > 66) {
108  $str = substr($str, 0, 66).'...';
109  }
110  printf ('%s%'.(70 - strlen($str)).'s', $str,'');
111 
112 }//end printCollection()
113 
114 
123 function printUpdateStatus($status)
124 {
125  echo "[ $status ]\n";
126 
127 }//end printUpdateStatus()
128 
129 ?>