Skip to content
Snippets Groups Projects
Commit 0e8fe3be authored by Damien McKenna's avatar Damien McKenna
Browse files

Issue #1662752 by DamienMcKenna: Minor code cleanup.

parent 1d053f54
Branches
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ Maillog 8.x-1.x-dev, 2023-xx-xx ...@@ -8,6 +8,7 @@ Maillog 8.x-1.x-dev, 2023-xx-xx
Maillog->mail(). Maillog->mail().
#1662752 by Eduardo Morales Alberti, pluess, joe-b, miro_dietiker, seanr, #1662752 by Eduardo Morales Alberti, pluess, joe-b, miro_dietiker, seanr,
DamienMcKenna, Maedi: Maillog log table size escalation. DamienMcKenna, Maedi: Maillog log table size escalation.
#1662752 by DamienMcKenna: Minor code cleanup.
Maillog 8.x-1.1, 2023-06-01 Maillog 8.x-1.1, 2023-06-01
......
...@@ -31,29 +31,32 @@ function maillog_help($route_name, RouteMatchInterface $route_match) { ...@@ -31,29 +31,32 @@ function maillog_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_cron(). * Implements hook_cron().
*/ */
function maillog_cron() { function maillog_cron() {
$cron_enabled = \Drupal::config('maillog.settings')->get('cron_enabled'); $config = \Drupal::config('maillog.settings');
if ($cron_enabled) { $logger = \Drupal::logger('maillog');
$type = \Drupal::config('maillog.settings')->get('keep_limit_type') ?? '';
$limit = \Drupal::config('maillog.settings')->get($type) ?? 0; if ($config->get('cron_enabled')) {
$type = $config->get('keep_limit_type') ?? '';
$limit = $config->get($type) ?? 0;
$deleted_logs = 0; $deleted_logs = 0;
try { try {
$deleted_logs = \Drupal::service('maillog.cleaner')->clearMaillogs($type, (int) $limit); $deleted_logs = \Drupal::service('maillog.cleaner')
->clearMaillogs($type, (int) $limit);
} }
catch (\Exception $e) { 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(), '@reason' => $e->getMessage(),
])); ]));
} }
if (empty($deleted_logs)) { 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 { 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,
]));
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment