24 error_reporting(E_ALL);
25 if (ini_get(
'memory_limit') !=
'-1') ini_set(
'memory_limit',
'-1');
27 if ((php_sapi_name() !=
'cli')) {
28 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
31 if (count($_SERVER[
'argv']) < 2) {
32 echo
"USAGE : php hipo_management.php MATRIX_ROOT [-remove_all_jobs]\n";
36 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
37 if (empty($SYSTEM_ROOT)) {
38 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
42 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
43 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
47 $truncate_table = FALSE;
48 if (isset($_SERVER[
'argv'][2]) && $_SERVER[
'argv'][2] ==
'-remove_all_jobs') {
49 $truncate_table = TRUE;
50 }
else if (isset($_SERVER[
'argv'][2]) && $_SERVER[
'argv'][2] !=
'-remove_all_jobs') {
51 echo
"USAGE : php hipo_management.php MATRIX_ROOT [-remove_all_jobs]\n";
55 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
56 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
58 $am = $GLOBALS[
'SQ_SYSTEM']->am;
59 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
61 $root_user = $am->getSystemAsset(
'root_user');
62 $GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user);
64 $source_jobs = Array();
67 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db3');
69 $sql =
'SELECT source_code_name, code_name, job_type
74 }
catch (Exception $e) {
75 throw new Exception(
'Unable to get HIPO jobs due to database error: '.$e->getMessage());
77 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
79 if ($truncate_table) {
80 echo
"Found ".count($results).
" jobs.";
81 if (count($results) > 0) {
82 echo
"\nMake sure no HIPO jobs are running currently. Selecting 'yes' will remove those HIPO jobs too.\n";
83 echo
"Are you sure you want to continue removing all HIPO jobs? (y/n)\n";
84 $wish = rtrim(fgets(STDIN, 4094));
86 if (strtolower($wish) ==
'y') {
87 echo
"Now truncating Hipo job table\t";
88 $sql =
'TRUNCATE TABLE sq_hipo_job';
96 }
catch (Exception $e) {
97 throw new Exception(
'Unable to truncate table due to : '.$e->getMessage());
106 foreach ($results as $result) {
107 $source_name = array_get_index($result,
'source_code_name',
'');
108 $job_name = array_get_index($result,
'code_name',
'');
110 if (!empty($job_name) && $job_name == $source_name) {
111 $source_jobs[] = $result;
115 if (empty($source_jobs)) {
116 echo translate(
'hipo_currently_no_jobs').
"\n";
120 foreach ($source_jobs as $index => $job) {
121 $source_code_name = array_get_index($job,
'source_code_name',
'');
122 $source_job_type = array_get_index($job,
'job_type',
'');
123 if (empty($source_code_name))
continue;
124 $source_job = $hh->getJob($source_code_name);
125 if (is_null($source_job))
continue;
126 echo ($index+1).
': ';
127 echo ucwords(str_replace(
'_',
' ', $source_job_type));
128 echo
'( '.$source_job->percentDone().
'% )';
129 echo
"\tLast Updated: ".easy_time_total($source_job->last_updated - $now, TRUE).
"\n";
133 echo
'Enter the number of the job to change: (Press q to quit)';
134 $choice = rtrim(fgets(STDIN, 4094));
136 if (strtolower($choice) ==
'q') exit;
137 $actual_choice = ($choice-1);
138 if (!isset($source_jobs[$actual_choice])) {
139 echo
"Incorrect entry\n";
143 echo
"Options\n\tr - resume\n\tk - kill\n\tq - quit\nChoice:";
144 $action = rtrim(fgets(STDIN, 4094));
145 $action = strtolower($action);
147 $action = (string) $action;
151 $source_code_name = array_get_index($source_jobs[$actual_choice],
'source_code_name',
'');
152 $source_job_type = array_get_index($source_jobs[$actual_choice],
'job_type',
'');
153 if (empty($source_code_name)) exit;
154 $source_job = $hh->getJob($source_code_name);
155 if (is_null($source_job)) exit;
157 echo
'Resuming HIPO Job ';
158 echo ucwords(str_replace(
'_',
' ', $source_job_type)).
"\t";
161 $status = $source_job->process();
172 $source_code_name = array_get_index($source_jobs[$actual_choice],
'source_code_name',
'');
173 $source_job_type = array_get_index($source_jobs[$actual_choice],
'job_type',
'');
174 if (empty($source_code_name)) exit;
175 $source_job = $hh->getJob($source_code_name);
176 if (is_null($source_job)) exit;
178 echo
'Aborting HIPO Job ';
179 echo ucwords(str_replace(
'_',
' ', $source_job_type)).
"\n";
180 $source_job->abort();