Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
cron_job_generate_log_reports.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/system/cron/cron_job/cron_job.inc';
19 require_once SQ_INCLUDE_PATH.'/workflow_manager.inc';
20 require_once SQ_FUDGE_PATH.'/general/datetime.inc';
21 
37 {
38 
39 
46  function __construct($assetid=0)
47  {
48  parent::__construct($assetid);
49 
50  }//end constructor
51 
52 
64  public function create(Array &$link)
65  {
66  require_once SQ_CORE_PACKAGE_PATH.'/system/system_asset_fns.inc';
67  if (!system_asset_fns_create_pre_check($this)) {
68  return FALSE;
69  }
70  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
71  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
72 
73  if ($linkid = parent::create($link)) {
74  if (!system_asset_fns_create_cleanup($this)) {
75  $linkid = FALSE;
76  }
77  }
78 
79  if ($linkid) {
80  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
81  } else {
82  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
83  }
84 
85  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
86  return $linkid;
87 
88  }//end create()
89 
90 
100  protected function _getName($short_name=FALSE)
101  {
102  return translate('cron_job_generate_log_reports');
103 
104  }//end _getName()
105 
106 
113  public function canClone()
114  {
115  return FALSE;
116 
117  }//end canClone()
118 
119 
128  public function canDelete()
129  {
130  return FALSE;
131 
132  }//end canDelete()
133 
134 
147  protected function _exec(&$msg)
148  {
149  // set the UMASK to u=rw,g=rw,o=r (0002), so that the system can write to the the logfiles the cronjob creates
150  if (substr(PHP_OS, 0, 3) != 'WIN') $old_mask = umask(0113);
151 
152  $lm = $GLOBALS['SQ_SYSTEM']->getLogManager();
153 
154  $rotated_logs = $lm->rotateLogs();
155 
156  // nothing was rotated, so don't generate any reports and end prematurely
157  if (empty($rotated_logs)) return SQ_CRON_JOB_COMPLETED;
158 
159  // get all the log_reports in the system before looping through, if they exist
160  $status = $this->generateReports($rotated_logs);
161 
162  if (isset($old_mask)) umask($old_mask);
163 
164  return SQ_CRON_JOB_COMPLETED;
165 
166  }//end _exec()
167 
168 
177  public function generateReports(Array $target_logs)
178  {
179  if (empty($target_logs)) return FALSE;
180 
181  if (!$GLOBALS['SQ_SYSTEM']->am->installed('log_report')) {
182  return FALSE;
183  }
184 
185  $log_reports = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('log_report', FALSE, TRUE);
186 
187  // a list of all the logs in the system
188  $lm = $GLOBALS['SQ_SYSTEM']->getLogManager();
189  $logs = $lm->getLogs();
190  foreach ($target_logs as $logname) {
191  if (isset($logs[$logname])) {
192  $this->generateReportFromLog($logname, $log_reports);
193  }
194  }
195 
196  return TRUE;
197 
198  }//end generateReports()
199 
200 
210  public function generateReportFromLog($logname, Array &$log_reports)
211  {
212  if (empty($log_reports)) return FALSE;
213 
214  // start up a hipo for each report
215  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
216 
217  foreach ($log_reports as $reportid => $info) {
218  $report_type = $info['type_code'];
219  $report = $GLOBALS['SQ_SYSTEM']->am->getAsset($reportid, $report_type);
220  if ($report->logname == $logname) {
221  $vars = Array(
222  'assetid' => $reportid,
223  'report' => $report,
224  );
225  $status = $hh->freestyleHIPO('hipo_job_generate_report', $vars);
226  }
227  }
228 
229  return TRUE;
230 
231  }//end generateReportFromLog()
232 
233 
244  public function run()
245  {
246  $res = parent::run();
247  if ($res & SQ_CRON_JOB_REMOVE) {
248  $res = $res & -SQ_CRON_JOB_REMOVE;
249  }
250  return $res;
251 
252  }//end run()
253 
254 
255 }//end class
256 
257 
258 
259 ?>