From e8d5fd1552725689a59127bae20b0b7cee71e350 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Fri, 14 Feb 2025 13:43:16 +0100 Subject: [PATCH] [EPC-9597] Update crontab schedule and use constants for DB table alias --- Api/Data/NotificationInterface.php | 2 ++ Model/Config/Backend/ProcessedWebhookRemoval.php | 2 +- Model/ResourceModel/Notification.php | 14 +++++++++++--- .../Config/Backend/ProcessedWebhookRemovalTest.php | 2 +- etc/crontab.xml | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Api/Data/NotificationInterface.php b/Api/Data/NotificationInterface.php index b354acf9a..646a83ac6 100755 --- a/Api/Data/NotificationInterface.php +++ b/Api/Data/NotificationInterface.php @@ -16,6 +16,8 @@ interface NotificationInterface /** * Constants for keys of data array. Identical to the name of the getter in snake case. */ + const TABLE_NAME = 'adyen_notification'; + const TABLE_NAME_ALIAS = 'notification'; const ENTITY_ID = 'entity_id'; const PSPREFRENCE = 'pspreference'; const ORIGINAL_REFERENCE = 'original_reference'; diff --git a/Model/Config/Backend/ProcessedWebhookRemoval.php b/Model/Config/Backend/ProcessedWebhookRemoval.php index f81feb566..0bc347eeb 100644 --- a/Model/Config/Backend/ProcessedWebhookRemoval.php +++ b/Model/Config/Backend/ProcessedWebhookRemoval.php @@ -49,7 +49,7 @@ public function afterSave(): ProcessedWebhookRemoval if ($this->isValueChanged() && $this->getValue() === '1') { $numberOfDays = $this->getFieldsetDataValue('processed_webhook_removal_time'); $message = __( - 'You enabled the automatic removal of Adyen's processed webhooks. Processed webhooks older than %1 days will be removed.', + 'You enabled the automatic removal of Adyen\'s processed webhooks. Processed webhooks older than %1 days will be removed.', $numberOfDays ); diff --git a/Model/ResourceModel/Notification.php b/Model/ResourceModel/Notification.php index d90e20e8f..3c252d816 100755 --- a/Model/ResourceModel/Notification.php +++ b/Model/ResourceModel/Notification.php @@ -11,6 +11,7 @@ namespace Adyen\Payment\Model\ResourceModel; +use Adyen\Payment\Api\Data\NotificationInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; @@ -70,9 +71,16 @@ public function deleteByIds(array $entityIds): void $connection = $this->getConnection(); $select = $connection->select() - ->from(['notification' => $tableName]) - ->where('notification.entity_id IN (?)', $entityIds); + ->from([NotificationInterface::TABLE_NAME_ALIAS => $tableName]) + ->where( + sprintf( + "%s.%s IN (?)", + NotificationInterface::TABLE_NAME_ALIAS, + NotificationInterface::ENTITY_ID + ), + $entityIds + ); - $connection->query($select->deleteFromSelect('notification')); + $connection->query($select->deleteFromSelect(NotificationInterface::TABLE_NAME_ALIAS)); } } diff --git a/Test/Unit/Model/Config/Backend/ProcessedWebhookRemovalTest.php b/Test/Unit/Model/Config/Backend/ProcessedWebhookRemovalTest.php index 3313927ef..f50be5543 100644 --- a/Test/Unit/Model/Config/Backend/ProcessedWebhookRemovalTest.php +++ b/Test/Unit/Model/Config/Backend/ProcessedWebhookRemovalTest.php @@ -82,7 +82,7 @@ public function testAfterSave() // Set old value as `0` to mimic the disabled feature $this->configMock->method('getValue')->willReturn('0'); $expectedMessage = - 'You enabled processed webhook removal cronjob. Processed webhooks older than 45 days will be removed.'; + 'You enabled the automatic removal of Adyen\'s processed webhooks. Processed webhooks older than 45 days will be removed.'; $this->messageManagerMock->expects($this->once()) ->method('addWarningMessage') diff --git a/etc/crontab.xml b/etc/crontab.xml index 468e53d0a..6e37957b1 100755 --- a/etc/crontab.xml +++ b/etc/crontab.xml @@ -25,7 +25,7 @@ 0 0 * * * - 0 0 * * * + */5 0 * * *