diff --git a/migrations/Version20211215142553.php b/migrations/Version20211215142553.php deleted file mode 100644 index 548a22b458389f7504fe3e4a84055a1b53781630..0000000000000000000000000000000000000000 --- a/migrations/Version20211215142553.php +++ /dev/null @@ -1,37 +0,0 @@ -<?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 Version20211215142553 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 capsule (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, aut_crea INT NOT NULL, dt_crea DATETIME NOT NULL, aut_maj INT DEFAULT 0 NOT NULL, dt_maj DATETIME DEFAULT \'0\' NOT NULL, link VARCHAR(255) NOT NULL, edition_link VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE editeur_capsule (capsule_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_A18592E2714704E9 (capsule_id), INDEX IDX_A18592E2A76ED395 (user_id), PRIMARY KEY(capsule_id, user_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE editeur_capsule ADD CONSTRAINT FK_A18592E2714704E9 FOREIGN KEY (capsule_id) REFERENCES capsule (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE editeur_capsule ADD CONSTRAINT FK_A18592E2A76ED395 FOREIGN KEY (user_id) REFERENCES `user` (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 editeur_capsule DROP FOREIGN KEY FK_A18592E2714704E9'); - $this->addSql('ALTER TABLE editeur_capsule DROP FOREIGN KEY FK_A18592E2A76ED395'); - $this->addSql('DROP TABLE capsule'); - $this->addSql('DROP TABLE editeur_capsule'); - } -} diff --git a/migrations/Version20211215152200.php b/migrations/Version20211215152200.php new file mode 100644 index 0000000000000000000000000000000000000000..be6f5e4ac488e4f3e2bfe8da23fdce5188bdd5de --- /dev/null +++ b/migrations/Version20211215152200.php @@ -0,0 +1,31 @@ +<?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 Version20211215152200 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 capsule (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, aut_crea VARCHAR(255) NOT NULL, dt_crea DATETIME NOT NULL, aut_maj INT DEFAULT NULL, dt_maj DATETIME DEFAULT NULL, link VARCHAR(255) NOT NULL, edition_link VARCHAR(255) NOT NULL, UNIQUE INDEX index_capsule_nom (nom), UNIQUE INDEX index_capsule_link (link), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE capsule'); + } +} diff --git a/src/DataFixtures/AppCapsuleFixtures.php b/src/DataFixtures/AppCapsuleFixtures.php index fa0cde8c87386993966542708574187bfec98b13..02163fb101760590cb19a3273faf13edaa60388f 100644 --- a/src/DataFixtures/AppCapsuleFixtures.php +++ b/src/DataFixtures/AppCapsuleFixtures.php @@ -13,24 +13,24 @@ class AppCapsuleFixtures extends Fixture { $this->createCapsuleWithData( $manager, - 'anonymous', + 2, new DateTime(), 'https://youtu.be/oPmMUZbnc3o', 'Adele', '', - '', - new DateTime() + null, + null ); $this->createCapsuleWithData( $manager, - 'Camille', + 2, new DateTime(), 'https://youtu.be/-xulsY5AGew', 'Pomme', '', - '', - new DateTime() + null, + null ); $manager->flush(); @@ -38,22 +38,22 @@ class AppCapsuleFixtures extends Fixture private function createCapsuleWithData( ObjectManager $manager, - string $author, + int $author, DateTime $date_time, string $link, string $name, string $edition_link, - string $update_author, + ?int $update_author, ?DateTime $update_datetime ): void { $capsule = new Capsule(); - $capsule->setAuthor($author); - $capsule->setCreationDate($date_time); + $capsule->setAutCrea($author); + $capsule->setDtCrea($date_time); $capsule->setLink($link); $capsule->setEditionLink($edition_link); - $capsule->setName($name); - $capsule->setUpdateAuthor($update_author); - $capsule->setUpdateDate($update_datetime); + $capsule->setNom($name); + $capsule->setAutMaj($update_author); + $capsule->setDtMaj($update_datetime); $manager->persist($capsule); } diff --git a/src/Entity/User.php b/src/Entity/User.php index 5bb021ccb9b1bb9646c0035e587b450e0abe7e91..37a58c6a6ba03d4f72deef0855ab1a44fbefbde9 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -85,7 +85,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface private string $salt; /** - * @ORM\ManyToMany(targetEntity=Capsule::class, mappedBy="editors") + * @ORM\OneToMany(targetEntity=Capsule::class, mappedBy="aut_crea") */ private $capsules; @@ -237,7 +237,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface { if (!$this->capsules->contains($capsule)) { $this->capsules[] = $capsule; - $capsule->addEditor($this); + $capsule->setAutCrea($this); } return $this; @@ -246,7 +246,10 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface public function removeCapsule(Capsule $capsule): self { if ($this->capsules->removeElement($capsule)) { - $capsule->removeEditor($this); + // set the owning side to null (unless already changed) + if ($capsule->getAutCrea() === $this) { + $capsule->setAutCrea(null); + } } return $this;