Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
regenerate_treeids_for_triggers.php
1 <?php
26 error_reporting(E_ALL);
27 if (php_sapi_name() != 'cli') {
28  trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
29 }
30 
31 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
32 if (empty($SYSTEM_ROOT)) {
33  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
34  exit();
35 }
36 
37 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
38  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
39  exit();
40 }
41 
42 require_once $SYSTEM_ROOT.'/core/include/init.inc';
43 
44 error_reporting(E_ALL);
45 if (ini_get('memory_limit') != '-1') ini_set('memory_limit', '-1');
46 
47 $root_user = &$GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
48 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
49  echo "ERROR: Failed logging in as root user\n";
50  exit();
51 }
52 
53 //-- MAIN() --//
54 
55 
56 $script_start = time();
57 
58 echo_headline(' GETTING ALL THE TRIGGERS INSTALLED ON THE SYSTEM');
59 
60 // get trigger manager and all the triggers installed on the system
61 $tm =& $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('trigger_manager');
62 $trigger_list = MatrixDAL::executeAll('core', 'getTriggerList');
63 
64 foreach ($trigger_list as $index => $trigger_data) {
65  echo_headline( " REGENERATING TRIGGER ".$tm->id.":".$trigger_data['id']);
66  // load the trigger and regenerate it, same as clicking commit on the backend :)
67  $trigger = $tm->_loadTrigger($trigger_data['id']);
68  $result = $tm->_saveTrigger($trigger);
69 
70  if (!$result) echo_headline(' ERROR OCCURED WHILE TRYING TO SAVE TRIGGER '.$tm->id.':'.$trigger_data['id']);
71 }
72 
73 
74 
75 fwrite(STDERR, "\n");
76 
77 echo_headline(' TREE ENTRIES CREATED');
78 
79 $script_end = time();
80 $script_duration = $script_end - $script_start;
81 echo '-- Script Start : ', $script_start, ' Script End : ', $script_end, "\n";
82 echo '-- Script Duration: '.floor($script_duration / 60).' mins '.($script_duration % 60)." seconds\n";
83 fwrite(STDERR, '-- Script Duration: '.floor($script_duration / 60).' mins '.($script_duration % 60)." seconds\n");
84 
85 
86 //-- FUNCTIONS --//
87 
88 
97 function echo_headline($s , $echo_time = FALSE)
98 {
99  static $start = 0;
100 
101  if ($start && $echo_time) {
102  $end = time();
103  $duration = $end - $start;
104  fwrite(STDERR, '-- Duration: '.floor($duration / 60).'mins '.($duration % 60)."seconds\n");
105  }
106 
107  fwrite(STDERR, "--------------------------------------\n$s\n--------------------------------------\n");
108 
109  $start = time();
110 
111 }//end echo_headline()
112 
113 
114 ?>