You are here

class UltimateCronDatabaseLogEntry in Ultimate Cron 7.2

Class for Ultimate Cron log entries.

Hierarchy

Expanded class hierarchy of UltimateCronDatabaseLogEntry

File

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

View source
class UltimateCronDatabaseLogEntry extends UltimateCronLogEntry {

  /**
   * Save log entry.
   */
  public function save() {
    if (!$this->lid) {
      return;
    }
    static $retry = 0;
    try {
      db_insert('ultimate_cron_log')
        ->fields(array(
        'lid' => $this->lid,
        'name' => $this->name,
        'log_type' => $this->log_type,
        'start_time' => $this->start_time,
        'end_time' => $this->end_time,
        'uid' => $this->uid,
        'init_message' => $this->init_message,
        'message' => $this->message,
        'severity' => $this->severity,
      ))
        ->execute();
    } catch (PDOException $e) {

      // Row already exists. Let's update it, if we can.
      $updated = db_update('ultimate_cron_log')
        ->fields(array(
        'name' => $this->name,
        'log_type' => $this->log_type,
        'start_time' => $this->start_time,
        'end_time' => $this->end_time,
        'init_message' => $this->init_message,
        'message' => $this->message,
        'severity' => $this->severity,
      ))
        ->condition('lid', $this->lid)
        ->condition('end_time', 0)
        ->execute();
      if (!$updated) {

        // Row was not updated, someone must have beaten us to it.
        // Let's create a new log entry.
        $lid = $this->lid . '-' . uniqid('', TRUE);
        $this->message = t('Lock #@original_lid was already closed and logged. Creating a new log entry #@lid', array(
          '@original_lid' => $this->lid,
          '@lid' => $lid,
        )) . "\n" . $this->message;
        $this->severity = $this->severity >= 0 && $this->severity < WATCHDOG_ERROR ? $this->severity : WATCHDOG_ERROR;
        $this->lid = $lid;
        $retry++;
        if ($retry > 3) {
          $retry = 0;
          watchdog_exception('database_logger', $e, NULL, array(), WATCHDOG_CRITICAL);
          return;
        }
        $this
          ->save();
        $retry--;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UltimateCronDatabaseLogEntry::save public function Save log entry. Overrides UltimateCronLogEntry::save
UltimateCronLogEntry::$end_time public property
UltimateCronLogEntry::$finished public property
UltimateCronLogEntry::$init_message public property
UltimateCronLogEntry::$job public property
UltimateCronLogEntry::$lid public property
UltimateCronLogEntry::$logger public property
UltimateCronLogEntry::$log_entry_fields public property
UltimateCronLogEntry::$log_entry_size public property
UltimateCronLogEntry::$log_type public property
UltimateCronLogEntry::$message public property
UltimateCronLogEntry::$name public property
UltimateCronLogEntry::$severity public property
UltimateCronLogEntry::$start_time public property
UltimateCronLogEntry::$uid public property
UltimateCronLogEntry::catchMessages public function Start catching watchdog messages.
UltimateCronLogEntry::finish public function Finish a log and save it if applicable.
UltimateCronLogEntry::formatDuration public function Format duration.
UltimateCronLogEntry::formatEndTime public function Format end time.
UltimateCronLogEntry::formatInitMessage public function Format initial message.
UltimateCronLogEntry::formatSeverity public function Format severity.
UltimateCronLogEntry::formatStartTime public function Format start time.
UltimateCronLogEntry::formatUser public function Format user.
UltimateCronLogEntry::getData public function Get current log entry data as an associative array.
UltimateCronLogEntry::getDuration public function Get duration.
UltimateCronLogEntry::log public function Re-implementation of watchdog().
UltimateCronLogEntry::setData public function Set current log entry data from an associative array.
UltimateCronLogEntry::unCatchMessages public function Stop catching watchdog messages.
UltimateCronLogEntry::watchdog public function Implements hook_watchdog().
UltimateCronLogEntry::__construct public function Constructor.