src/EventListener/VehicleStatusListener.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\Vehicle;
  4. use App\Event\VehicleChangedEvent;
  5. use Symfony\Component\Process\Process;
  6. /**
  7.  * Listener acting on "VehicleChangedEvents".
  8.  */
  9. class VehicleStatusListener
  10. {
  11.     public function __construct(private readonly string $projectDir)
  12.     {
  13.     }
  14.     /**
  15.      * Called when a lot is closed but not sold.
  16.      */
  17.     public function onUnsold(VehicleChangedEvent $args): void
  18.     {
  19.         $vehicle $args->getEntity();
  20.         $this->sendAlertSms($vehicle);
  21.         if (Vehicle::SALING_STATE_RETIRE === $vehicle->getSalingState() || null !== $vehicle->getWinner()) {
  22.             $this->generateFile($vehicle'Live');
  23.         }
  24.     }
  25.     /**
  26.      * Called when a lot is closed and sold.
  27.      */
  28.     public function onSold(VehicleChangedEvent $args): void
  29.     {
  30.         $vehicle $args->getEntity();
  31.         $this->sendAlertSms($vehicle);
  32.         if (Vehicle::SALING_STATE_RETIRE === $vehicle->getSalingState() || null !== $vehicle->getWinner()) {
  33.             $this->generateFile($vehicle'Live');
  34.         }
  35.     }
  36.     /**
  37.      * Called when a lot is reassigned.
  38.      */
  39.     public function onReassign(VehicleChangedEvent $args): void
  40.     {
  41.         $vehicle $args->getEntity();
  42.         $this->generateFile($vehicle'Affectation');
  43.     }
  44.     protected function sendAlertSms(Vehicle $vehicle)
  45.     {
  46.         $process Process::fromShellCommandline('nohup php '.$this->projectDir.'/bin/console vpauto:live:sms:prealert '.$vehicle->getId().' --env=prod > /dev/null 2>&1 &');
  47.         $process->run();
  48.     }
  49.     protected function generateFile(Vehicle $vehicle$prefix)
  50.     {
  51.         $process Process::fromShellCommandline(sprintf('nohup php %s/bin/console vpauto:sap:adjudication:file vehicle %s %s --env=prod > /dev/null 2>&1 &'$this->projectDir$vehicle->getId(), $prefix));
  52.         $process->run();
  53.     }
  54. }