Skip to content

Commit

Permalink
[TASK] Remove persistenceManager usage inside Command
Browse files Browse the repository at this point in the history
  • Loading branch information
hojalatheef committed Apr 26, 2024
1 parent 1c995b5 commit 17e7b68
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
8 changes: 1 addition & 7 deletions Classes/Command/RemoveInactiveOrdersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,22 +80,17 @@ 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();
}

$progressBar->finish();

$this->cancellationService->getPersistenceManager()->persistAll();

$output->writeln('Clear caches for affected facilities list views...');

foreach ($affectedFacilities as $facilityUid => $_) {
Expand Down
1 change: 1 addition & 0 deletions Classes/Domain/Repository/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 12 additions & 22 deletions Classes/Service/CancellationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand All @@ -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()
Expand All @@ -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);
Expand Down

0 comments on commit 17e7b68

Please sign in to comment.