You are here

public function UltimateCronDatabaseLogger::load in Ultimate Cron 7.2

Load log entry.

Overrides UltimateCronLogger::load

File

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

Class

UltimateCronDatabaseLogger
Class for using database as log storage.

Code

public function load($name, $lock_id = NULL, $log_types = array(
  ULTIMATE_CRON_LOG_TYPE_NORMAL,
)) {
  if ($lock_id) {
    $log_entry = db_select('ultimate_cron_log', 'l')
      ->fields('l')
      ->condition('l.lid', $lock_id)
      ->execute()
      ->fetchObject($this->log_entry_class, array(
      $name,
      $this,
    ));
  }
  else {
    $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.name', $name);
    $query
      ->condition('l2.log_type', $log_types, 'IN');
    $log_entry = $query
      ->execute()
      ->fetchObject($this->log_entry_class, array(
      $name,
      $this,
    ));
  }
  if ($log_entry) {
    $log_entry->finished = TRUE;
  }
  else {
    $log_entry = new $this->log_entry_class($name, $this);
  }
  return $log_entry;
}