From ee0b02535943c0084ba7df764a6bdecf8f6883c5 Mon Sep 17 00:00:00 2001 From: Brian Gilbert <34508-realityloop@users.noreply.drupalcode.org> Date: Wed, 29 Jan 2025 16:38:08 +0000 Subject: [PATCH] Issue #3502661 by realityloop: handle null integer --- config/schema/simple_oauth.schema.yml | 2 +- simple_oauth.module | 6 +++--- src/Form/Oauth2TokenSettingsForm.php | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/config/schema/simple_oauth.schema.yml b/config/schema/simple_oauth.schema.yml index b6244ae3..70b889cc 100644 --- a/config/schema/simple_oauth.schema.yml +++ b/config/schema/simple_oauth.schema.yml @@ -107,7 +107,7 @@ simple_oauth.settings: token_cron_batch_size: type: integer label: 'Token batch size' - description: 'The number of expired token to delete per batch during cron cron' + description: 'The number of expired token to delete per batch during cron. Use 0 for no limit.' public_key: type: path label: 'Public Key' diff --git a/simple_oauth.module b/simple_oauth.module index ebf71458..f13e874b 100644 --- a/simple_oauth.module +++ b/simple_oauth.module @@ -25,12 +25,12 @@ function simple_oauth_cron() { $collector = \Drupal::service('simple_oauth.expired_collector'); $config = \Drupal::config('simple_oauth.settings'); $logger = \Drupal::logger('simple_oauth'); - $token_cron_batch_size = $config->get('token_cron_batch_size'); + $token_cron_batch_size = $config->get('token_cron_batch_size') ?? 0; // Deleting one batch of expired tokens. if (!empty($expired_tokens = $collector->collect($token_cron_batch_size))) { $collector->deleteMultipleTokens($expired_tokens); - $logger->notice('Deleted @limit expired tokens in cron.', [ - '@limit' => $token_cron_batch_size, + $logger->notice('Deleted @count expired tokens in cron.', [ + '@count' => count($expired_tokens), ]); } } diff --git a/src/Form/Oauth2TokenSettingsForm.php b/src/Form/Oauth2TokenSettingsForm.php index 2c5a41fd..3b42add2 100644 --- a/src/Form/Oauth2TokenSettingsForm.php +++ b/src/Form/Oauth2TokenSettingsForm.php @@ -113,7 +113,8 @@ class Oauth2TokenSettingsForm extends ConfigFormBase { $form['token_cron_batch_size'] = [ '#type' => 'number', '#title' => $this->t('Token batch size.'), - '#description' => $this->t('The number of expired token to delete per batch during cron cron.'), + '#description' => $this->t('The number of expired token to delete per batch during cron. Use 0 for no limit.'), + '#required' => TRUE, '#config_target' => 'simple_oauth.settings:token_cron_batch_size', ]; $form['public_key'] = [ -- GitLab