From 50c5b750677a318a227bee0e6a15f5b044d8225b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Sun, 28 Jul 2024 23:39:38 +0200 Subject: [PATCH] feat: add Connector to WatchListTrigger --- migrations/Version20240728212316.php | 36 ---------------------------- migrations/Version20240728213336.php | 36 ++++++++++++++++++++++++++++ src/Config/ConnectorInterface.php | 8 +++++++ src/Entity/Connector.php | 30 +++++++++++------------ src/Entity/OVHConnector.php | 4 +++- src/Entity/WatchList.php | 15 ------------ src/Entity/WatchListTrigger.php | 15 ++++++++++++ 7 files changed, 77 insertions(+), 67 deletions(-) delete mode 100644 migrations/Version20240728212316.php create mode 100644 migrations/Version20240728213336.php create mode 100644 src/Config/ConnectorInterface.php diff --git a/migrations/Version20240728212316.php b/migrations/Version20240728212316.php deleted file mode 100644 index 1d738c0..0000000 --- a/migrations/Version20240728212316.php +++ /dev/null @@ -1,36 +0,0 @@ -addSql('ALTER TABLE watch_list ADD connector_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE watch_list ADD CONSTRAINT FK_152B584B4D085745 FOREIGN KEY (connector_id) REFERENCES connector (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_152B584B4D085745 ON watch_list (connector_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE watch_list DROP CONSTRAINT FK_152B584B4D085745'); - $this->addSql('DROP INDEX IDX_152B584B4D085745'); - $this->addSql('ALTER TABLE watch_list DROP connector_id'); - } -} diff --git a/migrations/Version20240728213336.php b/migrations/Version20240728213336.php new file mode 100644 index 0000000..021d06c --- /dev/null +++ b/migrations/Version20240728213336.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE watch_list_trigger ADD connector_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE watch_list_trigger ADD CONSTRAINT FK_CF857A4C4D085745 FOREIGN KEY (connector_id) REFERENCES connector (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_CF857A4C4D085745 ON watch_list_trigger (connector_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE watch_list_trigger DROP CONSTRAINT FK_CF857A4C4D085745'); + $this->addSql('DROP INDEX IDX_CF857A4C4D085745'); + $this->addSql('ALTER TABLE watch_list_trigger DROP connector_id'); + } +} diff --git a/src/Config/ConnectorInterface.php b/src/Config/ConnectorInterface.php new file mode 100644 index 0000000..3458e2b --- /dev/null +++ b/src/Config/ConnectorInterface.php @@ -0,0 +1,8 @@ + + * @var Collection */ - #[ORM\OneToMany(targetEntity: WatchList::class, mappedBy: 'connector')] - private Collection $watchLists; + #[ORM\OneToMany(targetEntity: WatchListTrigger::class, mappedBy: 'connector')] + private Collection $watchListTriggers; public function __construct() { - $this->watchLists = new ArrayCollection(); + $this->watchListTriggers = new ArrayCollection(); } public function getId(): ?int @@ -84,29 +84,29 @@ class Connector } /** - * @return Collection + * @return Collection */ - public function getWatchLists(): Collection + public function getWatchListTriggers(): Collection { - return $this->watchLists; + return $this->watchListTriggers; } - public function addWatchList(WatchList $watchList): static + public function addWatchListTrigger(WatchListTrigger $watchListTrigger): static { - if (!$this->watchLists->contains($watchList)) { - $this->watchLists->add($watchList); - $watchList->setConnector($this); + if (!$this->watchListTriggers->contains($watchListTrigger)) { + $this->watchListTriggers->add($watchListTrigger); + $watchListTrigger->setConnector($this); } return $this; } - public function removeWatchList(WatchList $watchList): static + public function removeWatchListTrigger(WatchListTrigger $watchListTrigger): static { - if ($this->watchLists->removeElement($watchList)) { + if ($this->watchListTriggers->removeElement($watchListTrigger)) { // set the owning side to null (unless already changed) - if ($watchList->getConnector() === $this) { - $watchList->setConnector(null); + if ($watchListTrigger->getConnector() === $this) { + $watchListTrigger->setConnector(null); } } diff --git a/src/Entity/OVHConnector.php b/src/Entity/OVHConnector.php index e6add0d..f63eee6 100644 --- a/src/Entity/OVHConnector.php +++ b/src/Entity/OVHConnector.php @@ -2,9 +2,11 @@ namespace App\Entity; +use App\Config\ConnectorInterface; use Doctrine\ORM\Mapping\Entity; #[Entity] -class OVHConnector extends Connector +class OVHConnector extends Connector implements ConnectorInterface { + } \ No newline at end of file diff --git a/src/Entity/WatchList.php b/src/Entity/WatchList.php index 922e665..d5be416 100644 --- a/src/Entity/WatchList.php +++ b/src/Entity/WatchList.php @@ -69,9 +69,6 @@ class WatchList #[SerializedName("triggers")] private Collection $watchListTriggers; - #[ORM\ManyToOne(inversedBy: 'watchLists')] - private ?Connector $connector = null; - public function __construct() { $this->token = Uuid::v4(); @@ -149,16 +146,4 @@ class WatchList return $this; } - - public function getConnector(): ?Connector - { - return $this->connector; - } - - public function setConnector(?Connector $connector): static - { - $this->connector = $connector; - - return $this; - } } diff --git a/src/Entity/WatchListTrigger.php b/src/Entity/WatchListTrigger.php index a9b9746..d85f247 100644 --- a/src/Entity/WatchListTrigger.php +++ b/src/Entity/WatchListTrigger.php @@ -26,6 +26,9 @@ class WatchListTrigger #[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])] private ?TriggerAction $action = null; + #[ORM\ManyToOne(inversedBy: 'watchListTriggers')] + private ?Connector $connector = null; + public function getEvent(): ?string { return $this->event; @@ -61,4 +64,16 @@ class WatchListTrigger return $this; } + + public function getConnector(): ?Connector + { + return $this->connector; + } + + public function setConnector(?Connector $connector): static + { + $this->connector = $connector; + + return $this; + } }