From 2c5d46daa709b21630b020d16b26f8a236a1f5db Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Mon, 6 Mar 2023 12:52:09 +0100 Subject: [PATCH] Add purgeQueue and deleteMessageBatch methods which would be mostly used in tests. --- Client/Aws/SqsClient.php | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Client/Aws/SqsClient.php b/Client/Aws/SqsClient.php index 3c01258..50c1622 100644 --- a/Client/Aws/SqsClient.php +++ b/Client/Aws/SqsClient.php @@ -256,6 +256,53 @@ public function deleteMessageBatchAsync(array $args = []): Promise return parent::deleteMessageBatchAsync($args); } + /** + * @param array $args + * + * @return Result + */ + public function deleteMessageBatch(array $args = []): Result + { + if ($this->largePayloadMessageExtension === null) { + /** @noinspection PhpUndefinedMethodInspection */ + return parent::deleteMessageBatch($args); + } + + $originalReceipts = []; + + foreach ($args[self::ENTRIES] as $receipt) { + if (!$this->largePayloadMessageExtension->isS3ReceiptHandle($receipt[self::RECEIPT_HANDLE])) { + $originalReceipts[] = $receipt; + continue; + } + + $this->largePayloadMessageExtension->deleteMessageFromS3($receipt[self::RECEIPT_HANDLE]); + + $originalReceiptHandle = $this->largePayloadMessageExtension->getOriginalReceiptHandle( + $receipt[self::RECEIPT_HANDLE] + ); + + $originalReceipt = $receipt; + $originalReceipt[self::RECEIPT_HANDLE] = $originalReceiptHandle; + $originalReceipts[] = $originalReceipt; + } + + $args[self::ENTRIES] = $originalReceipts; + + /** @noinspection PhpUndefinedMethodInspection */ + return parent::deleteMessageBatch($args); + } + + /** + * @param array $args + * + * @return Result + */ + public function purgeQueue(array $args = []): Result + { + return parent::purgeQueue($args); + } + /** * @param array $body *