From 638f73d8d9dab032909667ed12f4d60dca4fbed0 Mon Sep 17 00:00:00 2001 From: Marvin Muxfeld Date: Tue, 3 Sep 2024 12:03:07 +0200 Subject: [PATCH] PISHPS-348: fixed memory issue of ExpireOrderTaskHandler; fixed stan error attribute not repeatable --- .../config/services/scheduled_tasks.xml | 6 ++ .../OrderStatus/ExpireOrderTaskHandler.php | 3 + .../AbstractRenewalReminderTaskHandler.php | 69 +++++++++++++++++++ .../RenewalReminderTaskDevHandler.php | 9 +++ .../RenewalReminderTaskHandler.php | 67 +----------------- 5 files changed, 90 insertions(+), 64 deletions(-) create mode 100755 src/ScheduledTask/Subscription/RenewalReminder/AbstractRenewalReminderTaskHandler.php create mode 100644 src/ScheduledTask/Subscription/RenewalReminder/RenewalReminderTaskDevHandler.php mode change 100755 => 100644 src/ScheduledTask/Subscription/RenewalReminder/RenewalReminderTaskHandler.php diff --git a/src/Resources/config/services/scheduled_tasks.xml b/src/Resources/config/services/scheduled_tasks.xml index 5ab26627a..062ac68c2 100755 --- a/src/Resources/config/services/scheduled_tasks.xml +++ b/src/Resources/config/services/scheduled_tasks.xml @@ -22,6 +22,12 @@ + + + + + + diff --git a/src/ScheduledTask/OrderStatus/ExpireOrderTaskHandler.php b/src/ScheduledTask/OrderStatus/ExpireOrderTaskHandler.php index 0db5eb32a..cd2f5b387 100644 --- a/src/ScheduledTask/OrderStatus/ExpireOrderTaskHandler.php +++ b/src/ScheduledTask/OrderStatus/ExpireOrderTaskHandler.php @@ -13,6 +13,7 @@ use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; +use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting; use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler; #[\Symfony\Component\Messenger\Attribute\AsMessageHandler(handles: ExpireOrderTask::class)] @@ -40,6 +41,8 @@ public function run(): void $criteria = new Criteria(); $criteria->addAssociation('transactions.stateMachineState'); $criteria->getAssociation('transactions.stateMachineState')->addFilter(new EqualsFilter('technicalName', OrderStates::STATE_IN_PROGRESS)); + $criteria->addSorting(new FieldSorting('orderDateTime', FieldSorting::DESCENDING)); + $criteria->setLimit(10); $this->logger->debug('Search for orders which are in progress state'); diff --git a/src/ScheduledTask/Subscription/RenewalReminder/AbstractRenewalReminderTaskHandler.php b/src/ScheduledTask/Subscription/RenewalReminder/AbstractRenewalReminderTaskHandler.php new file mode 100755 index 000000000..ac07f126c --- /dev/null +++ b/src/ScheduledTask/Subscription/RenewalReminder/AbstractRenewalReminderTaskHandler.php @@ -0,0 +1,69 @@ +getRepository(), $logger); + + $this->subscriptionManager = $subscriptionManager; + $this->logger = $logger; + } + + /** + * @return iterable + */ + public static function getHandledMessages(): iterable + { + return [ + RenewalReminderTask::class, + RenewalReminderTaskDev::class, + ]; + } + + /** + * + */ + public function run(): void + { + try { + $this->logger->info('Starting Subscription Renewal Reminder from Scheduled Tasks.'); + + $context = new Context(new SystemSource()); + + $remindedCount = $this->subscriptionManager->remindSubscriptionRenewal($context); + + $this->logger->debug($remindedCount . ' subscriptions renewal reminders have been processed successfully!'); + } catch (\Throwable $ex) { + $this->logger->error( + 'Error when running Scheduled Task for Subscription Renewal Reminders. ' . $ex->getMessage() + ); + } + } +} diff --git a/src/ScheduledTask/Subscription/RenewalReminder/RenewalReminderTaskDevHandler.php b/src/ScheduledTask/Subscription/RenewalReminder/RenewalReminderTaskDevHandler.php new file mode 100644 index 000000000..693fa35f1 --- /dev/null +++ b/src/ScheduledTask/Subscription/RenewalReminder/RenewalReminderTaskDevHandler.php @@ -0,0 +1,9 @@ +getRepository(), $logger); - - $this->subscriptionManager = $subscriptionManager; - $this->logger = $logger; - } - - /** - * @return iterable - */ - public static function getHandledMessages(): iterable - { - return [ - RenewalReminderTask::class, - RenewalReminderTaskDev::class, - ]; - } - - /** - * - */ - public function run(): void - { - try { - $this->logger->info('Starting Subscription Renewal Reminder from Scheduled Tasks.'); - - $context = Context::createDefaultContext(); - - $remindedCount = $this->subscriptionManager->remindSubscriptionRenewal($context); - - $this->logger->debug($remindedCount . ' subscriptions renewal reminders have been processed successfully!'); - } catch (\Throwable $ex) { - $this->logger->error( - 'Error when running Scheduled Task for Subscription Renewal Reminders. ' . $ex->getMessage() - ); - } - } }