mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-18 02:05:36 +00:00
feat: add delete property on Domain
This commit is contained in:
parent
d36e520467
commit
3c557990fb
39
migrations/Version20240725140219.php
Normal file
39
migrations/Version20240725140219.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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 Version20240725140219 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 domain ADD COLUMN deleted BOOLEAN DEFAULT 0');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__domain AS SELECT ldh_name, tld_id, handle, status, created_at, updated_at FROM domain');
|
||||
$this->addSql('DROP TABLE domain');
|
||||
$this->addSql('CREATE TABLE domain (ldh_name VARCHAR(255) NOT NULL, tld_id VARCHAR(63) NOT NULL, handle VARCHAR(255) DEFAULT NULL, status CLOB DEFAULT NULL --(DC2Type:simple_array)
|
||||
, created_at DATE NOT NULL --(DC2Type:date_immutable)
|
||||
, updated_at DATE NOT NULL --(DC2Type:date_immutable)
|
||||
, PRIMARY KEY(ldh_name), CONSTRAINT FK_A7A91E0B50F7084E FOREIGN KEY (tld_id) REFERENCES tld (tld) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('INSERT INTO domain (ldh_name, tld_id, handle, status, created_at, updated_at) SELECT ldh_name, tld_id, handle, status, created_at, updated_at FROM __temp__domain');
|
||||
$this->addSql('DROP TABLE __temp__domain');
|
||||
$this->addSql('CREATE INDEX IDX_A7A91E0B50F7084E ON domain (tld_id)');
|
||||
}
|
||||
}
|
||||
47
migrations/Version20240725140319.php
Normal file
47
migrations/Version20240725140319.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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 Version20240725140319 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 TEMPORARY TABLE __temp__domain AS SELECT ldh_name, tld_id, handle, status, created_at, updated_at, deleted FROM domain');
|
||||
$this->addSql('DROP TABLE domain');
|
||||
$this->addSql('CREATE TABLE domain (ldh_name VARCHAR(255) NOT NULL, tld_id VARCHAR(63) NOT NULL, handle VARCHAR(255) DEFAULT NULL, status CLOB DEFAULT NULL --(DC2Type:simple_array)
|
||||
, created_at DATE NOT NULL --(DC2Type:date_immutable)
|
||||
, updated_at DATE NOT NULL --(DC2Type:date_immutable)
|
||||
, deleted BOOLEAN NOT NULL, PRIMARY KEY(ldh_name), CONSTRAINT FK_A7A91E0B50F7084E FOREIGN KEY (tld_id) REFERENCES tld (tld) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('INSERT INTO domain (ldh_name, tld_id, handle, status, created_at, updated_at, deleted) SELECT ldh_name, tld_id, handle, status, created_at, updated_at, deleted FROM __temp__domain');
|
||||
$this->addSql('DROP TABLE __temp__domain');
|
||||
$this->addSql('CREATE INDEX IDX_A7A91E0B50F7084E ON domain (tld_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__domain AS SELECT ldh_name, tld_id, handle, status, created_at, updated_at, deleted FROM domain');
|
||||
$this->addSql('DROP TABLE domain');
|
||||
$this->addSql('CREATE TABLE domain (ldh_name VARCHAR(255) NOT NULL, tld_id VARCHAR(63) NOT NULL, handle VARCHAR(255) DEFAULT NULL, status CLOB DEFAULT NULL --(DC2Type:simple_array)
|
||||
, created_at DATE NOT NULL --(DC2Type:date_immutable)
|
||||
, updated_at DATE NOT NULL --(DC2Type:date_immutable)
|
||||
, deleted BOOLEAN DEFAULT 0, PRIMARY KEY(ldh_name), CONSTRAINT FK_A7A91E0B50F7084E FOREIGN KEY (tld_id) REFERENCES tld (tld) NOT DEFERRABLE INITIALLY IMMEDIATE)');
|
||||
$this->addSql('INSERT INTO domain (ldh_name, tld_id, handle, status, created_at, updated_at, deleted) SELECT ldh_name, tld_id, handle, status, created_at, updated_at, deleted FROM __temp__domain');
|
||||
$this->addSql('DROP TABLE __temp__domain');
|
||||
$this->addSql('CREATE INDEX IDX_A7A91E0B50F7084E ON domain (tld_id)');
|
||||
}
|
||||
}
|
||||
@ -102,6 +102,9 @@ class Domain
|
||||
#[Groups(['domain:item'])]
|
||||
private ?Tld $tld = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $deleted = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->events = new ArrayCollection();
|
||||
@ -110,6 +113,8 @@ class Domain
|
||||
$this->nameservers = new ArrayCollection();
|
||||
$this->createdAt = new DateTimeImmutable('now');
|
||||
$this->updatedAt = new DateTimeImmutable('now');
|
||||
|
||||
$this->deleted = false;
|
||||
}
|
||||
|
||||
public function getLdhName(): ?string
|
||||
@ -302,4 +307,16 @@ class Domain
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDeleted(): ?bool
|
||||
{
|
||||
return $this->deleted;
|
||||
}
|
||||
|
||||
public function setDeleted(?bool $deleted): static
|
||||
{
|
||||
$this->deleted = $deleted;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,11 +29,11 @@ use Doctrine\ORM\Exception\ORMException;
|
||||
use Exception;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Throwable;
|
||||
|
||||
readonly class RDAPService
|
||||
{
|
||||
@ -89,7 +89,9 @@ readonly class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws HttpExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
*/
|
||||
public function registerDomains(array $domains): void
|
||||
{
|
||||
@ -100,6 +102,9 @@ readonly class RDAPService
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws HttpExceptionInterface
|
||||
*/
|
||||
public function registerDomain(string $fqdn): Domain
|
||||
{
|
||||
@ -111,18 +116,28 @@ readonly class RDAPService
|
||||
|
||||
if ($rdapServer === null) throw new Exception("Unable to determine which RDAP server to contact");
|
||||
|
||||
/** @var ?Domain $domain */
|
||||
$domain = $this->domainRepository->findOneBy(["ldhName" => strtolower($idnDomain)]);
|
||||
|
||||
|
||||
try {
|
||||
$res = $this->client->request(
|
||||
'GET', $rdapServer->getUrl() . 'domain/' . $idnDomain
|
||||
)->toArray();
|
||||
} catch (Throwable) {
|
||||
throw new Exception("Unable to contact RDAP server");
|
||||
} catch (HttpExceptionInterface $e) {
|
||||
if ($domain !== null) {
|
||||
$domain->setDeleted(true);
|
||||
$this->em->persist($domain);
|
||||
$this->em->flush();
|
||||
|
||||
return $domain;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$domain = $this->domainRepository->findOneBy(["ldhName" => strtolower($res['ldhName'])]);
|
||||
if ($domain === null) $domain = new Domain();
|
||||
|
||||
$domain->setTld($tld)->setLdhName($res['ldhName']);
|
||||
if ($domain === null) $domain = new Domain();
|
||||
$domain->setTld($tld)->setLdhName($res['ldhName'])->setDeleted(false);
|
||||
|
||||
if (array_key_exists('status', $res)) $domain->setStatus($res['status']);
|
||||
if (array_key_exists('handle', $res)) $domain->setHandle($res['handle']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user