src/Entity/CronTask.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CronTaskRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClassCronTaskRepository::class)]
  7. #[ORM\Table(name'cron_task')]
  8. class CronTask
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length100uniquetrue)]
  15.     private ?string $name null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $description null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $command null;
  20.     #[ORM\Column]
  21.     private ?bool $enabled true;
  22.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  23.     private ?\DateTimeInterface $lastRun null;
  24.     #[ORM\Column(nullabletrue)]
  25.     private ?int $lastDuration null;
  26.     #[ORM\Column(length50nullabletrue)]
  27.     private ?string $lastStatus null;
  28.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  29.     private ?string $lastOutput null;
  30.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  31.     private ?\DateTimeInterface $createdAt null;
  32.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  33.     private ?\DateTimeInterface $updatedAt null;
  34.     public function __construct()
  35.     {
  36.         $this->createdAt = new \DateTime();
  37.         $this->updatedAt = new \DateTime();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getName(): ?string
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function setName(string $name): static
  48.     {
  49.         $this->name $name;
  50.         $this->updatedAt = new \DateTime();
  51.         return $this;
  52.     }
  53.     public function getDescription(): ?string
  54.     {
  55.         return $this->description;
  56.     }
  57.     public function setDescription(string $description): static
  58.     {
  59.         $this->description $description;
  60.         $this->updatedAt = new \DateTime();
  61.         return $this;
  62.     }
  63.     public function getCommand(): ?string
  64.     {
  65.         return $this->command;
  66.     }
  67.     public function setCommand(string $command): static
  68.     {
  69.         $this->command $command;
  70.         $this->updatedAt = new \DateTime();
  71.         return $this;
  72.     }
  73.     public function isEnabled(): ?bool
  74.     {
  75.         return $this->enabled;
  76.     }
  77.     public function setEnabled(bool $enabled): static
  78.     {
  79.         $this->enabled $enabled;
  80.         $this->updatedAt = new \DateTime();
  81.         return $this;
  82.     }
  83.     public function getLastRun(): ?\DateTimeInterface
  84.     {
  85.         return $this->lastRun;
  86.     }
  87.     public function setLastRun(?\DateTimeInterface $lastRun): static
  88.     {
  89.         $this->lastRun $lastRun;
  90.         $this->updatedAt = new \DateTime();
  91.         return $this;
  92.     }
  93.     public function getLastDuration(): ?int
  94.     {
  95.         return $this->lastDuration;
  96.     }
  97.     public function setLastDuration(?int $lastDuration): static
  98.     {
  99.         $this->lastDuration $lastDuration;
  100.         $this->updatedAt = new \DateTime();
  101.         return $this;
  102.     }
  103.     public function getLastStatus(): ?string
  104.     {
  105.         return $this->lastStatus;
  106.     }
  107.     public function setLastStatus(?string $lastStatus): static
  108.     {
  109.         $this->lastStatus $lastStatus;
  110.         $this->updatedAt = new \DateTime();
  111.         return $this;
  112.     }
  113.     public function getLastOutput(): ?string
  114.     {
  115.         return $this->lastOutput;
  116.     }
  117.     public function setLastOutput(?string $lastOutput): static
  118.     {
  119.         $this->lastOutput $lastOutput;
  120.         $this->updatedAt = new \DateTime();
  121.         return $this;
  122.     }
  123.     public function getCreatedAt(): ?\DateTimeInterface
  124.     {
  125.         return $this->createdAt;
  126.     }
  127.     public function setCreatedAt(\DateTimeInterface $createdAt): static
  128.     {
  129.         $this->createdAt $createdAt;
  130.         return $this;
  131.     }
  132.     public function getUpdatedAt(): ?\DateTimeInterface
  133.     {
  134.         return $this->updatedAt;
  135.     }
  136.     public function setUpdatedAt(\DateTimeInterface $updatedAt): static
  137.     {
  138.         $this->updatedAt $updatedAt;
  139.         return $this;
  140.     }
  141.     /**
  142.      * Retourne le statut formaté pour l'affichage
  143.      */
  144.     public function getFormattedStatus(): string
  145.     {
  146.         return match($this->lastStatus) {
  147.             'success' => '✅ Succès',
  148.             'error' => '❌ Erreur',
  149.             default => '⏳ En attente'
  150.         };
  151.     }
  152.     /**
  153.      * Retourne la durée formatée
  154.      */
  155.     public function getFormattedDuration(): string
  156.     {
  157.         if (!$this->lastDuration) {
  158.             return 'N/A';
  159.         }
  160.         if ($this->lastDuration 60) {
  161.             return $this->lastDuration 's';
  162.         }
  163.         $minutes floor($this->lastDuration 60);
  164.         $seconds $this->lastDuration 60;
  165.         
  166.         return $minutes 'm ' $seconds 's';
  167.     }
  168. }