From 45c6079e15636238c9eb54736f2e2145b2a04268 Mon Sep 17 00:00:00 2001 From: Peter Lieverdink Date: Fri, 26 Jan 2024 11:47:33 +1100 Subject: [PATCH] chore: Replace the amazon_ses patch link with a set that actually applies to 3.0.1 instead of 3.0.x-dev only. Refs: OPS-9523 OPS-9992 --- PATCHES/3416368-error-not-caught-extra.patch | 17 ++++ PATCHES/3416368-error-not-caught-queue.patch | 18 ++++ PATCHES/3416368-error-not-caught.patch | 90 ++++++++++++++++++++ composer.patches.json | 4 +- 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 PATCHES/3416368-error-not-caught-extra.patch create mode 100644 PATCHES/3416368-error-not-caught-queue.patch create mode 100644 PATCHES/3416368-error-not-caught.patch diff --git a/PATCHES/3416368-error-not-caught-extra.patch b/PATCHES/3416368-error-not-caught-extra.patch new file mode 100644 index 00000000..2d191a2e --- /dev/null +++ b/PATCHES/3416368-error-not-caught-extra.patch @@ -0,0 +1,17 @@ +diff --git a/src/AmazonSesHandler.php b/src/AmazonSesHandler.php +index 28342d8..103829c 100644 +--- a/src/AmazonSesHandler.php ++++ b/src/AmazonSesHandler.php +@@ -126,6 +126,12 @@ class AmazonSesHandler implements AmazonSesHandlerInterface { + */ + protected function getSleepTime() { + $results = $this->getSendQuota(); ++ ++ // Avoid a division by zero if the quota call failed. ++ if (empty($results)) { ++ return 0; ++ } ++ + $per_second = ceil(1000000 / $results['MaxSendRate']); + + return intval($per_second); diff --git a/PATCHES/3416368-error-not-caught-queue.patch b/PATCHES/3416368-error-not-caught-queue.patch new file mode 100644 index 00000000..257546a5 --- /dev/null +++ b/PATCHES/3416368-error-not-caught-queue.patch @@ -0,0 +1,18 @@ +diff --git a/src/Plugin/QueueWorker/AmazonSesMailQueue.php b/src/Plugin/QueueWorker/AmazonSesMailQueue.php +index dc41050..fdc7af3 100644 +--- a/src/Plugin/QueueWorker/AmazonSesMailQueue.php ++++ b/src/Plugin/QueueWorker/AmazonSesMailQueue.php +@@ -29,7 +29,12 @@ class AmazonSesMailQueue extends QueueWorkerBase implements ContainerFactoryPlug + $plugin_definition + ); + +- $instance->setHandler($container->get('amazon_ses.handler')); ++ // Only set the handler if queueing is enabled to avoid an error when ++ // trying to run without config. ++ $enabled = \Drupal::config('amazon_ses.settings')->get('queue'); ++ if ($enabled) { ++ $instance->setHandler($container->get('amazon_ses.handler')); ++ } + + return $instance; + } diff --git a/PATCHES/3416368-error-not-caught.patch b/PATCHES/3416368-error-not-caught.patch new file mode 100644 index 00000000..ebd16fa8 --- /dev/null +++ b/PATCHES/3416368-error-not-caught.patch @@ -0,0 +1,90 @@ +diff --git a/src/AmazonSesHandler.php b/src/AmazonSesHandler.php +index ed8882c..cb2fb01 100644 +--- a/src/AmazonSesHandler.php ++++ b/src/AmazonSesHandler.php +@@ -194,9 +194,16 @@ class AmazonSesHandler implements AmazonSesHandlerInterface { + * {@inheritdoc} + */ + public function getSendQuota() { +- $result = $this->client->getAccount(); ++ $quota = []; + +- return array_map('number_format', $result['SendQuota']); ++ try { ++ $result = $this->client->getAccount(); ++ $quota = array_map('number_format', $result['SendQuota']); ++ } catch (SesV2Exception $e) { ++ $this->logger->error($e->getMessage()); ++ $this->messenger->addError($this->t('Unable to retrieve quota.')); ++ } ++ return $quota; + } + + /** +diff --git a/src/Controller/AmazonSesController.php b/src/Controller/AmazonSesController.php +index 541838c..831d38d 100644 +--- a/src/Controller/AmazonSesController.php ++++ b/src/Controller/AmazonSesController.php +@@ -29,33 +29,38 @@ class AmazonSesController extends ControllerBase { + * A render array to build the page. + */ + public function statistics() { ++ $statistics = []; ++ + if (!$this->verifyClient()) { +- return []; ++ return $statistics; + } + +- $quota = $this->handler->getSendQuota(); +- +- return [ +- 'quota' => [ +- '#type' => 'details', +- '#title' => $this->t('Daily sending limits'), +- '#open' => TRUE, +- 'sending_quota' => [ +- '#markup' => $this->t('Quota: @max_send', [ +- '@max_send' => $quota['Max24HourSend'], +- ]) . '
', +- ], +- 'sent_mail' => [ +- '#markup' => $this->t('Sent: @sent_last', [ +- '@sent_last' => $quota['SentLast24Hours'], +- ]) . '
', +- ], +- 'send_rate' => [ +- '#markup' => $this->t('Maximum Send Rate: @send_rate +- emails/second', ['@send_rate' => $quota['MaxSendRate']]), ++ $result = $this->handler->getSendQuota(); ++ ++ if (!empty($result)) { ++ $statistics = [ ++ 'quota' => [ ++ '#type' => 'details', ++ '#title' => $this->t('Daily sending limits'), ++ '#open' => TRUE, ++ 'sending_quota' => [ ++ '#markup' => $this->t('Quota: @max_send', [ ++ '@max_send' => $result['Max24HourSend'], ++ ]) . '
', ++ ], ++ 'sent_mail' => [ ++ '#markup' => $this->t('Sent: @sent_last', [ ++ '@sent_last' => $result['SentLast24Hours'], ++ ]) . '
', ++ ], ++ 'send_rate' => [ ++ '#markup' => $this->t('Maximum Send Rate: @send_rate ++ emails/second', ['@send_rate' => $result['MaxSendRate']]), ++ ], + ], +- ], +- ]; +- } ++ ]; ++ } + ++ return $statistics; ++ } + } diff --git a/composer.patches.json b/composer.patches.json index a1ff9219..576b4b54 100644 --- a/composer.patches.json +++ b/composer.patches.json @@ -5,7 +5,9 @@ "CSS dialog Design Issue": "PATCHES/anchorlink/anchor_link-styling_issue_in_link_dialog-2986268-11.patch" }, "drupal/amazon_ses": { - "Issue #3416368: Error not caught when AWS API returns 403": "https://git.drupalcode.org/project/amazon_ses/-/merge_requests/13.diff" + "Error not caught when AWS API returns 403": "PATCHES/3416368-error-not-caught.patch", + "Error not caught when AWS API returns 403 extra backport": "PATCHES/3416368-error-not-caught-extra.patch", + "Error not caught when AWS API returns 403 extra queue fix": "PATCHES/3416368-error-not-caught-queue.patch" }, "drupal/contact_storage": { "Error while field storage definition": "https://www.drupal.org/files/issues/2022-10-19/contact_storage.patch"