You are here

public function UltimateCronDatabaseLogger::loadLatestLogEntries in Ultimate Cron 7.2

Load latest log entry.

Overrides UltimateCronLogger::loadLatestLogEntries

File

plugins/ultimate_cron/logger/database.class.php, line 314
Database logger for Ultimate Cron.

Class

UltimateCronDatabaseLogger
Class for using database as log storage.

Code

public function loadLatestLogEntries($jobs, $log_types) {
  if (Database::getConnection()
    ->databaseType() !== 'mysql') {
    return parent::loadLatestLogEntries($jobs, $log_types);
  }
  $subquery = db_select('ultimate_cron_log', 'l3')
    ->fields('l3', array(
    'name',
    'log_type',
  ))
    ->groupBy('name')
    ->groupBy('log_type');
  $subquery
    ->addExpression('MAX(l3.start_time)', 'start_time');
  $query = db_select('ultimate_cron_log', 'l1')
    ->fields('l1');
  $query
    ->join($subquery, 'l2', 'l1.name = l2.name AND l1.start_time = l2.start_time AND l1.log_type = l2.log_type');
  $query
    ->condition('l2.log_type', $log_types, 'IN');
  $result = $query
    ->execute();
  $log_entries = array();
  while ($object = $result
    ->fetchObject()) {
    if (isset($jobs[$object->name])) {
      $log_entries[$object->name] = new $this->log_entry_class($object->name, $this);
      $log_entries[$object->name]
        ->setData((array) $object);
    }
  }
  foreach ($jobs as $name => $job) {
    if (!isset($log_entries[$name])) {
      $log_entries[$name] = new $this->log_entry_class($name, $this);
    }
  }
  return $log_entries;
}