Skip to content
Snippets Groups Projects
Commit c92e561b authored by Camille Simiand's avatar Camille Simiand Committed by Sebastien
Browse files

Update capsule table schema

parent ebcdec21
No related branches found
No related tags found
3 merge requests!43tuleap-83-access-my-capsules,!42Draft: access-my-capsules-conflicts-fixed,!40Draft: Tuleap 83 access my capsules
...@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; ...@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/** /**
* Auto-generated Migration: Please modify to your needs! * Auto-generated Migration: Please modify to your needs!
*/ */
final class Version20211215142553 extends AbstractMigration final class Version20211215152200 extends AbstractMigration
{ {
public function getDescription(): string public function getDescription(): string
{ {
...@@ -20,18 +20,12 @@ final class Version20211215142553 extends AbstractMigration ...@@ -20,18 +20,12 @@ final class Version20211215142553 extends AbstractMigration
public function up(Schema $schema): void public function up(Schema $schema): void
{ {
// this up() migration is auto-generated, please modify it to your needs // 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 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');
$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 public function down(Schema $schema): void
{ {
// this down() migration is auto-generated, please modify it to your needs // 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 capsule');
$this->addSql('DROP TABLE editeur_capsule');
} }
} }
...@@ -13,24 +13,24 @@ class AppCapsuleFixtures extends Fixture ...@@ -13,24 +13,24 @@ class AppCapsuleFixtures extends Fixture
{ {
$this->createCapsuleWithData( $this->createCapsuleWithData(
$manager, $manager,
'anonymous', 2,
new DateTime(), new DateTime(),
'https://youtu.be/oPmMUZbnc3o', 'https://youtu.be/oPmMUZbnc3o',
'Adele', 'Adele',
'', '',
'', null,
new DateTime() null
); );
$this->createCapsuleWithData( $this->createCapsuleWithData(
$manager, $manager,
'Camille', 2,
new DateTime(), new DateTime(),
'https://youtu.be/-xulsY5AGew', 'https://youtu.be/-xulsY5AGew',
'Pomme', 'Pomme',
'', '',
'', null,
new DateTime() null
); );
$manager->flush(); $manager->flush();
...@@ -38,22 +38,22 @@ class AppCapsuleFixtures extends Fixture ...@@ -38,22 +38,22 @@ class AppCapsuleFixtures extends Fixture
private function createCapsuleWithData( private function createCapsuleWithData(
ObjectManager $manager, ObjectManager $manager,
string $author, int $author,
DateTime $date_time, DateTime $date_time,
string $link, string $link,
string $name, string $name,
string $edition_link, string $edition_link,
string $update_author, ?int $update_author,
?DateTime $update_datetime ?DateTime $update_datetime
): void { ): void {
$capsule = new Capsule(); $capsule = new Capsule();
$capsule->setAuthor($author); $capsule->setAutCrea($author);
$capsule->setCreationDate($date_time); $capsule->setDtCrea($date_time);
$capsule->setLink($link); $capsule->setLink($link);
$capsule->setEditionLink($edition_link); $capsule->setEditionLink($edition_link);
$capsule->setName($name); $capsule->setNom($name);
$capsule->setUpdateAuthor($update_author); $capsule->setAutMaj($update_author);
$capsule->setUpdateDate($update_datetime); $capsule->setDtMaj($update_datetime);
$manager->persist($capsule); $manager->persist($capsule);
} }
......
...@@ -85,7 +85,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface ...@@ -85,7 +85,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
private string $salt; private string $salt;
/** /**
* @ORM\ManyToMany(targetEntity=Capsule::class, mappedBy="editors") * @ORM\OneToMany(targetEntity=Capsule::class, mappedBy="aut_crea")
*/ */
private $capsules; private $capsules;
...@@ -237,7 +237,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface ...@@ -237,7 +237,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
{ {
if (!$this->capsules->contains($capsule)) { if (!$this->capsules->contains($capsule)) {
$this->capsules[] = $capsule; $this->capsules[] = $capsule;
$capsule->addEditor($this); $capsule->setAutCrea($this);
} }
return $this; return $this;
...@@ -246,7 +246,10 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface ...@@ -246,7 +246,10 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
public function removeCapsule(Capsule $capsule): self public function removeCapsule(Capsule $capsule): self
{ {
if ($this->capsules->removeElement($capsule)) { 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; return $this;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment