From 17e7b68c86174bf14033d527c6152851ce2f6db9 Mon Sep 17 00:00:00 2001 From: Hoja Mustaffa Abdul Latheef Date: Fri, 26 Apr 2024 14:23:00 +0200 Subject: [PATCH] [TASK] Remove persistenceManager usage inside Command --- .../Command/RemoveInactiveOrdersCommand.php | 8 +---- Classes/Domain/Repository/OrderRepository.php | 1 + Classes/Service/CancellationService.php | 34 +++++++------------ 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/Classes/Command/RemoveInactiveOrdersCommand.php b/Classes/Command/RemoveInactiveOrdersCommand.php index cda41585..a37b0df2 100644 --- a/Classes/Command/RemoveInactiveOrdersCommand.php +++ b/Classes/Command/RemoveInactiveOrdersCommand.php @@ -19,7 +19,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Command to remove inactive orders after a given expiration time @@ -81,13 +80,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $inactiveOrder, CancellationService::REASON_INACTIVE, ['expirationTime' => $input->getOption('expiration-time')], - true, - false + true ); } catch (\Throwable $exception) { $output->writeln('Could not cancel the order ' . $inactiveOrder->getUid() . ' using cancellation service!'); - // Anyway make sure to remove the order! - $this->cancellationService->getPersistenceManager()->remove($inactiveOrder); } $progressBar->advance(); @@ -95,8 +91,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $progressBar->finish(); - $this->cancellationService->getPersistenceManager()->persistAll(); - $output->writeln('Clear caches for affected facilities list views...'); foreach ($affectedFacilities as $facilityUid => $_) { diff --git a/Classes/Domain/Repository/OrderRepository.php b/Classes/Domain/Repository/OrderRepository.php index 68cf99f7..e0dd397e 100644 --- a/Classes/Domain/Repository/OrderRepository.php +++ b/Classes/Domain/Repository/OrderRepository.php @@ -12,6 +12,7 @@ namespace JWeiland\Reserve\Domain\Repository; use JWeiland\Reserve\Domain\Model\Order; +use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Utility\GeneralUtility; diff --git a/Classes/Service/CancellationService.php b/Classes/Service/CancellationService.php index be34c261..a5f51355 100644 --- a/Classes/Service/CancellationService.php +++ b/Classes/Service/CancellationService.php @@ -14,9 +14,9 @@ use JWeiland\Reserve\Domain\Model\Order; use JWeiland\Reserve\Utility\CacheUtility; use JWeiland\Reserve\Utility\OrderSessionUtility; +use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3\CMS\Fluid\View\StandaloneView; @@ -33,28 +33,26 @@ class CancellationService implements SingletonInterface protected FluidService $fluidService; - protected PersistenceManager $persistenceManager; + protected DataHandler $dataHandler; - public function __construct(FluidService $fluidService, PersistenceManager $persistenceManager) + public function __construct(FluidService $fluidService, DataHandler $dataHandler) { $this->fluidService = $fluidService; - $this->persistenceManager = $persistenceManager; + $this->dataHandler = $dataHandler; } /** * @param string $reason use CancellationService::REASON_ constants or add your own reason * @param array $vars additional variables that will be assigned to the fluid template * @param bool $sendMailToCustomer set false to cancel the order without sending a mail to the customer - * @param bool $persist set false to persist the order by yourself using $cancellationService->getPersistenceManager()->persistAll() */ public function cancel( Order $order, string $reason = self::REASON_CUSTOMER, array $vars = [], - bool $sendMailToCustomer = true, - bool $persist = true + bool $sendMailToCustomer = true ): void { - $this->persistenceManager->remove($order); + debug($this->dataHandler); if ($sendMailToCustomer) { $view = $this->getStandaloneView(); @@ -73,10 +71,12 @@ public function cancel( ); } - if ($persist) { - $this->persistenceManager->persistAll(); - CacheUtility::clearPageCachesForPagesWithCurrentFacility($order->getBookedPeriod()->getFacility()->getUid()); - } + // Remove with DataHandler + $this->dataHandler->start([], []); + $this->dataHandler->deleteRecord('tx_yourext_domain_model_order', $order->getUid()); + $this->dataHandler->process_datamap(); + + CacheUtility::clearPageCachesForPagesWithCurrentFacility($order->getBookedPeriod()->getFacility()->getUid()); OrderSessionUtility::unblockNewOrdersForFacilityInCurrentSession( $order->getBookedPeriod()->getFacility()->getUid() @@ -88,16 +88,6 @@ public function getStandaloneView(): StandaloneView return GeneralUtility::makeInstance(StandaloneView::class); } - /** - * ToDo: SF: This should not be public. - * Currently used from RemoveInactiveOrdersCommand - * Should be set to private or migrated to Command - */ - public function getPersistenceManager(): PersistenceManager - { - return $this->persistenceManager; - } - protected function getMailService(): MailService { return GeneralUtility::makeInstance(MailService::class);