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

fixup! Issue #3134174 by jjcarrion: Notice because of malformed value

Revert already configured cache lifetime option to match the change in 33d3eff1.

Also harden the lookup of the config value in case the update hook is
not executed or got corrupted in some other way.
parent e9fa9ad8
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -27,3 +27,19 @@ function apsis_mail_update_8101() {

  \Drupal::state()->setMultiple($states);
}

/**
 * Revert already configured cache lifetime option.
 *
 * The cache lifetime option config has the keys and value the other way
 * around. Update existing config to match current usage.
 */
function apsis_mail_update_8201() {
  $options = array_flip(\Drupal\apsis_mail\Form\ApsisMailSettings::CACHE_LIFETIME_OPTIONS);

  $cache_lifetime = \Drupal::config('apsis_mail.admin')->get('cache_lifetime');

  if (array_key_exists($cache_lifetime, $options)) {
    \Drupal::configFactory()->getEditable('apsis_mail.admin')->set('cache_lifetime', $options[$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 = $this->config->get('cache_lifetime') ? $this->config->get('cache_lifetime') : 30;
    $cache_lifetime = is_int($this->config->get('cache_lifetime')) ? $this->config->get('cache_lifetime') : 30;

    // First check static cache, to avoid unnecessary queries to cache backend.
    $response = drupal_static($cid, NULL);
+6 −4
Original line number Diff line number Diff line
@@ -18,6 +18,11 @@ class ApsisMailSettings extends ConfigFormBase {

  use MessengerTrait;

  const CACHE_LIFETIME_OPTIONS = [
    30 => '30 sec',
    43200 => '12 hours',
  ];

  /**
   * The state service.
   *
@@ -129,10 +134,7 @@ class ApsisMailSettings extends ConfigFormBase {
      '#type' => 'select',
      '#title' => $this->t('Cache lifetime'),
      '#description' => $this->t('Cache the result of requests for this long.'),
      '#options' => [
        30 => '30 sec',
        43200 => '12 hours',
      ],
      '#options' => self::CACHE_LIFETIME_OPTIONS,
      '#default_value' => $config->get('cache_lifetime'),
    ];