mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add Connector to Watchlist
This commit is contained in:
36
migrations/Version20240728212316.php
Normal file
36
migrations/Version20240728212316.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?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 Version20240728212316 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('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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ namespace App\Entity;
|
|||||||
|
|
||||||
use App\Config\ConnectorProvider;
|
use App\Config\ConnectorProvider;
|
||||||
use App\Repository\ConnectorRepository;
|
use App\Repository\ConnectorRepository;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
||||||
use Doctrine\ORM\Mapping\DiscriminatorMap;
|
use Doctrine\ORM\Mapping\DiscriminatorMap;
|
||||||
@@ -29,6 +31,17 @@ class Connector
|
|||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
private array $authData = [];
|
private array $authData = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection<int, WatchList>
|
||||||
|
*/
|
||||||
|
#[ORM\OneToMany(targetEntity: WatchList::class, mappedBy: 'connector')]
|
||||||
|
private Collection $watchLists;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->watchLists = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@@ -70,4 +83,34 @@ class Connector
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, WatchList>
|
||||||
|
*/
|
||||||
|
public function getWatchLists(): Collection
|
||||||
|
{
|
||||||
|
return $this->watchLists;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addWatchList(WatchList $watchList): static
|
||||||
|
{
|
||||||
|
if (!$this->watchLists->contains($watchList)) {
|
||||||
|
$this->watchLists->add($watchList);
|
||||||
|
$watchList->setConnector($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeWatchList(WatchList $watchList): static
|
||||||
|
{
|
||||||
|
if ($this->watchLists->removeElement($watchList)) {
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
|
if ($watchList->getConnector() === $this) {
|
||||||
|
$watchList->setConnector(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ class WatchList
|
|||||||
#[SerializedName("triggers")]
|
#[SerializedName("triggers")]
|
||||||
private Collection $watchListTriggers;
|
private Collection $watchListTriggers;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(inversedBy: 'watchLists')]
|
||||||
|
private ?Connector $connector = null;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->token = Uuid::v4();
|
$this->token = Uuid::v4();
|
||||||
@@ -146,4 +149,16 @@ class WatchList
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getConnector(): ?Connector
|
||||||
|
{
|
||||||
|
return $this->connector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setConnector(?Connector $connector): static
|
||||||
|
{
|
||||||
|
$this->connector = $connector;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user