-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PISHPS-348: fixed memory issue of ExpireOrderTaskHandler; fixed stan …
…error attribute not repeatable (#822)
- Loading branch information
1 parent
3c0faa6
commit 73546cd
Showing
5 changed files
with
90 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/ScheduledTask/Subscription/RenewalReminder/AbstractRenewalReminderTaskHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\ScheduledTask\Subscription\RenewalReminder; | ||
|
||
use Kiener\MolliePayments\Components\Subscription\SubscriptionManager; | ||
use Kiener\MolliePayments\Repository\ScheduledTask\ScheduledTaskRepositoryInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Shopware\Core\Framework\Api\Context\SystemSource; | ||
use Shopware\Core\Framework\Context; | ||
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler; | ||
|
||
abstract class AbstractRenewalReminderTaskHandler extends ScheduledTaskHandler | ||
{ | ||
/** | ||
* @var SubscriptionManager | ||
*/ | ||
private $subscriptionManager; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
|
||
/** | ||
* @param ScheduledTaskRepositoryInterface $scheduledTaskRepository | ||
* @param SubscriptionManager $subscriptionManager | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct(ScheduledTaskRepositoryInterface $scheduledTaskRepository, SubscriptionManager $subscriptionManager, LoggerInterface $logger) | ||
{ | ||
/** @phpstan-ignore-next-line */ | ||
parent::__construct($scheduledTaskRepository->getRepository(), $logger); | ||
|
||
$this->subscriptionManager = $subscriptionManager; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @return iterable<mixed> | ||
*/ | ||
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() | ||
); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/ScheduledTask/Subscription/RenewalReminder/RenewalReminderTaskDevHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\ScheduledTask\Subscription\RenewalReminder; | ||
|
||
#[\Symfony\Component\Messenger\Attribute\AsMessageHandler(handles: RenewalReminderTaskDev::class)] | ||
class RenewalReminderTaskDevHandler extends AbstractRenewalReminderTaskHandler | ||
{ | ||
} |
67 changes: 3 additions & 64 deletions
67
src/ScheduledTask/Subscription/RenewalReminder/RenewalReminderTaskHandler.php
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,9 @@ | ||
<?php declare(strict_types=1); | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\ScheduledTask\Subscription\RenewalReminder; | ||
|
||
use Kiener\MolliePayments\Components\Subscription\SubscriptionManager; | ||
use Kiener\MolliePayments\Repository\ScheduledTask\ScheduledTaskRepositoryInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Shopware\Core\Framework\Context; | ||
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler; | ||
|
||
#[\Symfony\Component\Messenger\Attribute\AsMessageHandler(handles: RenewalReminderTask::class)] | ||
#[\Symfony\Component\Messenger\Attribute\AsMessageHandler(handles: RenewalReminderTaskDev::class)] | ||
class RenewalReminderTaskHandler extends ScheduledTaskHandler | ||
class RenewalReminderTaskHandler extends AbstractRenewalReminderTaskHandler | ||
{ | ||
/** | ||
* @var SubscriptionManager | ||
*/ | ||
private $subscriptionManager; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
|
||
/** | ||
* @param ScheduledTaskRepositoryInterface $scheduledTaskRepository | ||
* @param SubscriptionManager $subscriptionManager | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct(ScheduledTaskRepositoryInterface $scheduledTaskRepository, SubscriptionManager $subscriptionManager, LoggerInterface $logger) | ||
{ | ||
/** @phpstan-ignore-next-line */ | ||
parent::__construct($scheduledTaskRepository->getRepository(), $logger); | ||
|
||
$this->subscriptionManager = $subscriptionManager; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @return iterable<mixed> | ||
*/ | ||
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() | ||
); | ||
} | ||
} | ||
} |