Skip to content

Commit

Permalink
Merge pull request #399 from UN-OCHA/cafuego/ops-9523-ses-updates
Browse files Browse the repository at this point in the history
chore: Replace the amazon_ses patch link with a set that actually applies to 3.0.1 instead of 3.0.x-dev only.
  • Loading branch information
cafuego authored Jan 26, 2024
2 parents 9f5dba4 + 45c6079 commit 2fab842
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 1 deletion.
17 changes: 17 additions & 0 deletions PATCHES/3416368-error-not-caught-extra.patch
Original file line number Diff line number Diff line change
@@ -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);
18 changes: 18 additions & 0 deletions PATCHES/3416368-error-not-caught-queue.patch
Original file line number Diff line number Diff line change
@@ -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;
}
90 changes: 90 additions & 0 deletions PATCHES/3416368-error-not-caught.patch
Original file line number Diff line number Diff line change
@@ -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('<strong>Quota:</strong> @max_send', [
- '@max_send' => $quota['Max24HourSend'],
- ]) . '<br />',
- ],
- 'sent_mail' => [
- '#markup' => $this->t('<strong>Sent:</strong> @sent_last', [
- '@sent_last' => $quota['SentLast24Hours'],
- ]) . '<br />',
- ],
- 'send_rate' => [
- '#markup' => $this->t('<strong>Maximum Send Rate:</strong> @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('<strong>Quota:</strong> @max_send', [
+ '@max_send' => $result['Max24HourSend'],
+ ]) . '<br />',
+ ],
+ 'sent_mail' => [
+ '#markup' => $this->t('<strong>Sent:</strong> @sent_last', [
+ '@sent_last' => $result['SentLast24Hours'],
+ ]) . '<br />',
+ ],
+ 'send_rate' => [
+ '#markup' => $this->t('<strong>Maximum Send Rate:</strong> @send_rate
+ emails/second', ['@send_rate' => $result['MaxSendRate']]),
+ ],
],
- ],
- ];
- }
+ ];
+ }

+ return $statistics;
+ }
}
4 changes: 3 additions & 1 deletion composer.patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2fab842

Please sign in to comment.