src/Core/Framework/Webhook/Service/WebhookCleanup.php line 41

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Webhook\Service;
  3. use Doctrine\DBAL\Connection;
  4. use Psr\Clock\ClockInterface;
  5. use Shopware\Core\Defaults;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Shopware\Core\System\SystemConfig\SystemConfigService;
  8. use Symfony\Component\Clock\NativeClock;
  9. /**
  10.  * @internal
  11.  */
  12. #[Package('core')]
  13. class WebhookCleanup
  14. {
  15.     /**
  16.      * @internal
  17.      */
  18.     public function __construct(
  19.         private readonly SystemConfigService $systemConfigService,
  20.         private readonly Connection $connection,
  21.         private readonly ClockInterface $clock = new NativeClock(),
  22.     ) {
  23.     }
  24.     public function removeOldLogs(): void
  25.     {
  26.         $entryLifetimeSeconds $this->systemConfigService->getInt('core.webhook.entryLifetimeSeconds');
  27.         if ($entryLifetimeSeconds === -1) {
  28.             return;
  29.         }
  30.         $deleteBefore $this->clock
  31.             ->now()
  32.             ->modify("- $entryLifetimeSeconds seconds")
  33.             ->format(Defaults::STORAGE_DATE_TIME_FORMAT);
  34.         $this->connection->executeStatement(
  35.             'DELETE FROM `webhook_event_log` WHERE `created_at` < :before',
  36.             ['before' => $deleteBefore]
  37.         );
  38.     }
  39. }