Verified Commit abfccffb authored by Arne Jørgensen's avatar Arne Jørgensen
Browse files

Make sure configured cache lifetime option is an integer

In 2bee363d we made sure the configured
cache lifetime _must_ be an integer (using `is_int()`).

Unfortunately the form submits a string even if the value was an
integer and that git stored in the config system as string.

This change:

* converts the submitted value to an integer before storing it
  in the config system
* ensures the configured value is a numeric instead of an integer before
  converting it to integer and using it
* updates already stored numeric strings to integers in the config system
parent 2bee363d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -43,3 +43,14 @@ function apsis_mail_update_8201() {
    \Drupal::configFactory()->getEditable('apsis_mail.admin')->set('cache_lifetime', $options[$cache_lifetime])->save();
  }
}

/**
 * Make sure configured cache lifetime option is an integer.
 */
function apsis_mail_update_8202() {
  $cache_lifetime = \Drupal::config('apsis_mail.admin')->get('cache_lifetime');

  if (!is_int($cache_lifetime) && is_numeric($cache_lifetime)) {
      \Drupal::configFactory()->getEditable('apsis_mail.admin')->set('cache_lifetime', intval($cache_lifetime))->save();
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ class Apsis {
   */
  protected function cachableRequest($method, $path, array $args = []) {
    $cid = 'apsis_mail:api:' . hash('sha256', var_export(func_get_args(), TRUE));
    $cache_lifetime = is_int($this->config->get('cache_lifetime')) ? $this->config->get('cache_lifetime') : 30;
    $cache_lifetime = is_numeric($this->config->get('cache_lifetime')) ? intval($this->config->get('cache_lifetime')) : 30;

    // First check static cache, to avoid unnecessary queries to cache backend.
    $response = drupal_static($cid, NULL);
+1 −1
Original line number Diff line number Diff line
@@ -301,7 +301,7 @@ class ApsisMailSettings extends ConfigFormBase {
      ->set('user_roles', $form_state->getValue('user_roles'))
      ->set('gdpr_enabled', $form_state->getValue('gdpr_enabled'))
      ->set('gdpr_title', $form_state->getValue('gdpr_title'))
      ->set('cache_lifetime', $form_state->getValue('cache_lifetime'))
      ->set('cache_lifetime', intval($form_state->getValue('cache_lifetime')))
      ->save();

    $this->messenger()->addStatus($this->t('Settings saved.'));