src/Core/System/SalesChannel/Context/Cleanup/CleanupSalesChannelContextTaskHandler.php line 36

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\System\SalesChannel\Context\Cleanup;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Defaults;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler;
  8. use Symfony\Component\Messenger\Attribute\AsMessageHandler;
  9. /**
  10.  * @internal
  11.  */
  12. #[AsMessageHandler(handlesCleanupSalesChannelContextTask::class)]
  13. #[Package('sales-channel')]
  14. final class CleanupSalesChannelContextTaskHandler extends ScheduledTaskHandler
  15. {
  16.     /**
  17.      * @internal
  18.      */
  19.     public function __construct(
  20.         EntityRepository $repository,
  21.         private readonly Connection $connection,
  22.         private readonly int $days
  23.     ) {
  24.         parent::__construct($repository);
  25.     }
  26.     public function run(): void
  27.     {
  28.         $time = new \DateTime();
  29.         $time->modify(sprintf('-%s day'$this->days));
  30.         $this->connection->executeStatement(
  31.             'DELETE FROM sales_channel_api_context WHERE updated_at <= :timestamp',
  32.             ['timestamp' => $time->format(Defaults::STORAGE_DATE_TIME_FORMAT)]
  33.         );
  34.     }
  35. }