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
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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,
]));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment