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
Branches
Tags
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;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20211215142553 extends AbstractMigration
final class Version20211215152200 extends AbstractMigration
{
public function getDescription(): string
{
......@@ -20,18 +20,12 @@ final class Version20211215142553 extends AbstractMigration
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');
$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('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');
}
}
......@@ -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);
}
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment