refs #723. Added new entity CommandTask

feature/actions
Manuel Aranda Rosales 2024-09-17 08:50:17 +02:00
parent d4101cda80
commit 0f0b047c85
6 changed files with 313 additions and 0 deletions

View File

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240917064754 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE command_task (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, datetime DATETIME NOT NULL, notes VARCHAR(255) DEFAULT NULL, status VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_F3D475A8D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE command_task_command (command_task_id INT NOT NULL, command_id INT NOT NULL, INDEX IDX_BB417CA862DC5265 (command_task_id), INDEX IDX_BB417CA833E1689A (command_id), PRIMARY KEY(command_task_id, command_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE command_task_command_group (command_task_id INT NOT NULL, command_group_id INT NOT NULL, INDEX IDX_C43618BD62DC5265 (command_task_id), INDEX IDX_C43618BDC7B800D6 (command_group_id), PRIMARY KEY(command_task_id, command_group_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE command_task_command ADD CONSTRAINT FK_BB417CA862DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE command_task_command ADD CONSTRAINT FK_BB417CA833E1689A FOREIGN KEY (command_id) REFERENCES command (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE command_task_command_group ADD CONSTRAINT FK_C43618BD62DC5265 FOREIGN KEY (command_task_id) REFERENCES command_task (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE command_task_command_group ADD CONSTRAINT FK_C43618BDC7B800D6 FOREIGN KEY (command_group_id) REFERENCES command_group (id) ON DELETE CASCADE');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE command_task_command DROP FOREIGN KEY FK_BB417CA862DC5265');
$this->addSql('ALTER TABLE command_task_command DROP FOREIGN KEY FK_BB417CA833E1689A');
$this->addSql('ALTER TABLE command_task_command_group DROP FOREIGN KEY FK_C43618BD62DC5265');
$this->addSql('ALTER TABLE command_task_command_group DROP FOREIGN KEY FK_C43618BDC7B800D6');
$this->addSql('DROP TABLE command_task');
$this->addSql('DROP TABLE command_task_command');
$this->addSql('DROP TABLE command_task_command_group');
}
}

View File

@ -28,10 +28,17 @@ class Command extends AbstractEntity
#[ORM\ManyToMany(targetEntity: CommandGroup::class, mappedBy: 'commands')]
private Collection $commandGroups;
/**
* @var Collection<int, CommandTask>
*/
#[ORM\ManyToMany(targetEntity: CommandTask::class, mappedBy: 'command')]
private Collection $commandTasks;
public function __construct()
{
parent::__construct();
$this->commandGroups = new ArrayCollection();
$this->commandTasks = new ArrayCollection();
}
public function getScript(): ?string
@ -96,4 +103,31 @@ class Command extends AbstractEntity
return $this;
}
/**
* @return Collection<int, CommandTask>
*/
public function getCommandTasks(): Collection
{
return $this->commandTasks;
}
public function addCommandTask(CommandTask $commandTask): static
{
if (!$this->commandTasks->contains($commandTask)) {
$this->commandTasks->add($commandTask);
$commandTask->addCommand($this);
}
return $this;
}
public function removeCommandTask(CommandTask $commandTask): static
{
if ($this->commandTasks->removeElement($commandTask)) {
$commandTask->removeCommand($this);
}
return $this;
}
}

View File

@ -22,10 +22,17 @@ class CommandGroup extends AbstractEntity
#[ORM\Column]
private ?int $position = null;
/**
* @var Collection<int, CommandTask>
*/
#[ORM\ManyToMany(targetEntity: CommandTask::class, mappedBy: 'commandGroup')]
private Collection $commandTasks;
public function __construct()
{
parent::__construct();
$this->commands = new ArrayCollection();
$this->commandTasks = new ArrayCollection();
}
/**
@ -75,4 +82,31 @@ class CommandGroup extends AbstractEntity
return $this;
}
/**
* @return Collection<int, CommandTask>
*/
public function getCommandTasks(): Collection
{
return $this->commandTasks;
}
public function addCommandTask(CommandTask $commandTask): static
{
if (!$this->commandTasks->contains($commandTask)) {
$this->commandTasks->add($commandTask);
$commandTask->addCommandGroup($this);
}
return $this;
}
public function removeCommandTask(CommandTask $commandTask): static
{
if ($this->commandTasks->removeElement($commandTask)) {
$commandTask->removeCommandGroup($this);
}
return $this;
}
}

View File

@ -0,0 +1,126 @@
<?php
namespace App\Entity;
use App\Repository\CommandTaskRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CommandTaskRepository::class)]
class CommandTask extends AbstractEntity
{
/**
* @var Collection<int, Command>
*/
#[ORM\ManyToMany(targetEntity: Command::class, inversedBy: 'commandTasks')]
private Collection $commands;
/**
* @var Collection<int, CommandGroup>
*/
#[ORM\ManyToMany(targetEntity: CommandGroup::class, inversedBy: 'commandTasks')]
private Collection $commandGroups;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $datetime = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $notes = null;
#[ORM\Column(length: 255)]
private ?string $status = null;
public function __construct()
{
parent::__construct();
$this->commands = new ArrayCollection();
$this->commandGroups = new ArrayCollection();
}
/**
* @return Collection<int, Command>
*/
public function getCommands(): Collection
{
return $this->commands;
}
public function addCommand(Command $command): static
{
if (!$this->commands->contains($command)) {
$this->commands->add($command);
}
return $this;
}
public function removeCommand(Command $command): static
{
$this->commands->removeElement($command);
return $this;
}
/**
* @return Collection<int, CommandGroup>
*/
public function getCommandGroups(): Collection
{
return $this->commandGroups;
}
public function addCommandGroup(CommandGroup $commandGroup): static
{
if (!$this->commandGroups->contains($commandGroup)) {
$this->commandGroups->add($commandGroup);
}
return $this;
}
public function removeCommandGroup(CommandGroup $commandGroup): static
{
$this->commandGroups->removeElement($commandGroup);
return $this;
}
public function getDatetime(): ?\DateTimeInterface
{
return $this->datetime;
}
public function setDatetime(\DateTimeInterface $datetime): static
{
$this->datetime = $datetime;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): static
{
$this->notes = $notes;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Model;
final class CommandTaskStatus
{
public const string PENDING = 'pending';
public const string IN_PROGRESS = 'in-progress';
public const string COMPLETED = 'completed';
public const string FAILED = 'failed';
private const array STATUS = [
self::PENDING => 'Pendiente',
self::IN_PROGRESS => 'En progreso',
self::COMPLETED => 'Completado',
self::FAILED => 'Fallido',
];
public static function getStatus(): array
{
return self::STATUS;
}
public static function getCommandTaskStatus(string $status): ?string
{
return self::STATUS[$status] ?? null;
}
public static function getStatusKeys(): array
{
return array_keys(self::STATUS);
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\CommandTask;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<CommandTask>
*/
class CommandTaskRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, CommandTask::class);
}
// /**
// * @return CommandTask[] Returns an array of CommandTask objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('c.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?CommandTask
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}