vendor/shapecode/cron-bundle/src/EventListener/ResultAutoPruneListener.php line 40

Open in your IDE?
  1. <?php
  2. namespace Shapecode\Bundle\CronBundle\EventListener;
  3. use Shapecode\Bundle\CronBundle\Event\GenericCleanUpEvent;
  4. use Shapecode\Bundle\CronBundle\Service\CronJobResultServiceInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. /**
  7.  * Class ResultAutoPruneListener
  8.  *
  9.  * @package Shapecode\Bundle\CronBundle\EventListener
  10.  * @author  Nikita Loges
  11.  */
  12. class ResultAutoPruneListener implements EventSubscriberInterface
  13. {
  14.     /** @var CronJobResultServiceInterface */
  15.     protected $cronjobService;
  16.     /** @var boolean */
  17.     protected $autoPrune;
  18.     /**
  19.      * @param CronJobResultServiceInterface $cronjobService
  20.      * @param bool                          $autoPrune
  21.      */
  22.     public function __construct(CronJobResultServiceInterface $cronjobServicebool $autoPrune)
  23.     {
  24.         $this->cronjobService $cronjobService;
  25.         $this->autoPrune $autoPrune;
  26.     }
  27.     /**
  28.      * @inheritDoc
  29.      */
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             GenericCleanUpEvent::HOURLY_PROCESS => 'onHourlyProcess'
  34.         ];
  35.     }
  36.     /**
  37.      * @param GenericCleanUpEvent $genericCleanUpEvent
  38.      */
  39.     public function onHourlyProcess(GenericCleanUpEvent $genericCleanUpEvent): void
  40.     {
  41.         if ($this->autoPrune) {
  42.             $this->cronjobService->prune();
  43.         }
  44.     }
  45. }