8.5.x dblog.module dblog_cron()
8.0.x dblog.module dblog_cron()
8.1.x dblog.module dblog_cron()
8.2.x dblog.module dblog_cron()
8.3.x dblog.module dblog_cron()
8.4.x dblog.module dblog_cron()
8.6.x dblog.module dblog_cron()
6.x dblog.module dblog_cron()
7.x dblog.module dblog_cron()

Implements hook_cron().

Controls the size of the log table, paring it to 'dblog_row_limit' messages.

File

modules/dblog/dblog.module, line 101
System monitoring and logging for administrators.

Code

function dblog_cron() {

  // Cleanup the watchdog table.
  $row_limit = variable_get('dblog_row_limit', 1000);

  // For row limit n, get the wid of the nth row in descending wid order.
  // Counting the most recent n rows avoids issues with wid number sequences,
  // e.g. auto_increment value > 1 or rows deleted directly from the table.
  if ($row_limit > 0) {
    $min_row = db_select('watchdog', 'w')
      ->fields('w', array(
      'wid',
    ))
      ->orderBy('wid', 'DESC')
      ->range($row_limit - 1, 1)
      ->execute()
      ->fetchField();

    // Delete all table entries older than the nth row, if nth row was found.
    if ($min_row) {
      db_delete('watchdog')
        ->condition('wid', $min_row, '<')
        ->execute();
    }
  }
}