From 0e8fe3be69431681aaee6fb641c047bdcd37c24f Mon Sep 17 00:00:00 2001 From: Damien McKenna <damien@mc-kenna.com> Date: Sat, 9 Mar 2024 08:15:17 -0500 Subject: [PATCH] Issue #1662752 by DamienMcKenna: Minor code cleanup. --- CHANGELOG.txt | 1 + maillog.module | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 02c6def..7f9ffbc 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -8,6 +8,7 @@ Maillog 8.x-1.x-dev, 2023-xx-xx Maillog->mail(). #1662752 by Eduardo Morales Alberti, pluess, joe-b, miro_dietiker, seanr, DamienMcKenna, Maedi: Maillog log table size escalation. +#1662752 by DamienMcKenna: Minor code cleanup. Maillog 8.x-1.1, 2023-06-01 diff --git a/maillog.module b/maillog.module index 8a6106a..22c6e7c 100644 --- a/maillog.module +++ b/maillog.module @@ -31,29 +31,32 @@ function maillog_help($route_name, RouteMatchInterface $route_match) { * Implements hook_cron(). */ function maillog_cron() { - $cron_enabled = \Drupal::config('maillog.settings')->get('cron_enabled'); - if ($cron_enabled) { - $type = \Drupal::config('maillog.settings')->get('keep_limit_type') ?? ''; - $limit = \Drupal::config('maillog.settings')->get($type) ?? 0; + $config = \Drupal::config('maillog.settings'); + $logger = \Drupal::logger('maillog'); + + if ($config->get('cron_enabled')) { + $type = $config->get('keep_limit_type') ?? ''; + $limit = $config->get($type) ?? 0; $deleted_logs = 0; try { - $deleted_logs = \Drupal::service('maillog.cleaner')->clearMaillogs($type, (int) $limit); + $deleted_logs = \Drupal::service('maillog.cleaner') + ->clearMaillogs($type, (int) $limit); } catch (\Exception $e) { - \Drupal::logger('maillog')->error(t('Exception when tried to delete the mail logs, reason: @reason', [ + $logger->error(t('Exception when tried to delete the mail logs, reason: @reason', [ '@reason' => $e->getMessage(), ])); } if (empty($deleted_logs)) { - \Drupal::logger('maillog')->info(t('Any log deleted because any log meet the conditions')); + $logger->info(t('Any log deleted because any log meet the conditions')); } else { - \Drupal::logger('maillog')->info(t('Deleted @count mail logs from database', ['@count' => $deleted_logs])); - + $logger->info(t('Deleted @count mail logs from database', [ + '@count' => $deleted_logs, + ])); } - } } -- GitLab