From eda015a5ec0efe994a22904c173adf1c9cb866d4 Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 19 Feb 2020 13:34:33 +0100 Subject: [PATCH] Correction fixtures Project/Request --- backend/src/DataFixtures/ProjectFixtures.php | 82 +++++----------- backend/src/DataFixtures/RequestFixtures.php | 97 +++++-------------- .../src/Migrations/Version20200219122346.php | 35 +++++++ 3 files changed, 86 insertions(+), 128 deletions(-) create mode 100644 backend/src/Migrations/Version20200219122346.php diff --git a/backend/src/DataFixtures/ProjectFixtures.php b/backend/src/DataFixtures/ProjectFixtures.php index 3747deb..a66df52 100644 --- a/backend/src/DataFixtures/ProjectFixtures.php +++ b/backend/src/DataFixtures/ProjectFixtures.php @@ -16,75 +16,46 @@ class ProjectFixtures extends Fixture implements DependentFixtureInterface { //NEW PROJECT - $user = $manager + $dev1 = $manager ->getRepository(User::class) ->findOneByUsername('dev1') ; - $project = new Project(); - $request = $manager - ->getRepository(Request::class) - ->findOneByTitle('Demande num 1') - ; - $project->addRequest($request); - $request = $manager - ->getRepository(Request::class) - ->findOneByTitle('Demande num 2') - ; - $project->addRequest($request); - $request = $manager - ->getRepository(Request::class) - ->findOneByTitle('Demande num 3') - ; - $project->addRequest($request); - - $project->setName("Projet 1"); - $project->addUser($user); - $manager->persist($project); - - //NEW PROJECT - $user = $manager + $client1 = $manager ->getRepository(User::class) ->findOneByUsername('client1') ; - $project = new Project(); - - $request = $manager - ->getRepository(Request::class) - ->findOneByTitle('Demande num 4') - ; - $project->addRequest($request); - $request = $manager - ->getRepository(Request::class) - ->findOneByTitle('Demande num 5') - ; - $project->addRequest($request); - - $project->setName("Projet 2"); - $project->addUser($user); - $manager->persist($project); - - //NEW PROJECT - $user = $manager - ->getRepository(User::class) - ->findOneByUsername('client1') - ; - - $project = new Project(); - $project->setName("Projet 3"); - $project->addUser($user); - $manager->persist($project); - - //NEW PROJECT - $user = $manager + $client2 = $manager ->getRepository(User::class) ->findOneByUsername('client2') ; + $project = new Project(); + $project->setName("Projet 1"); + $project->addUser($dev1); + $manager->persist($project); + + //NEW PROJECT + $project = new Project(); + $project->setName("Projet 2"); + $project->addUser($client1); + $project->addUser($dev1); + $manager->persist($project); + + //NEW PROJECT + + $project = new Project(); + $project->setName("Projet 3"); + $project->addUser($client1); + $project->addUser($dev1); + $manager->persist($project); + + //NEW PROJECT + $project = new Project(); $project->setName("Projet 4"); - $project->addUser($user); + $project->addUser($client2); $manager->persist($project); $manager->flush(); @@ -95,7 +66,6 @@ class ProjectFixtures extends Fixture implements DependentFixtureInterface { return [ UserFixtures::class, - RequestFixtures::class ]; } diff --git a/backend/src/DataFixtures/RequestFixtures.php b/backend/src/DataFixtures/RequestFixtures.php index e8f515f..7a3118e 100644 --- a/backend/src/DataFixtures/RequestFixtures.php +++ b/backend/src/DataFixtures/RequestFixtures.php @@ -2,6 +2,7 @@ namespace App\DataFixtures; +use App\Entity\Project; use App\Entity\Request; use App\Entity\RequestStatus; use App\Entity\User; @@ -15,94 +16,45 @@ class RequestFixtures extends Fixture implements DependentFixtureInterface public function load(ObjectManager $manager) { + + + //NEW REQUEST - $user = $manager + $client1 = $manager ->getRepository(User::class) ->findOneByUsername('client1') ; - $status = $manager + $enAttenteStatus = $manager ->getRepository(RequestStatus::class) ->findOneBySlug('en-attente') ; - $request = new Request(); - $request->setTitle("Demande num 1"); - $request->setAuthor($user); - $request->setCreatedAt(new DateTime()); - $request->setStatus($status); - $manager->persist($request); - - //NEW REQUEST - $user = $manager - ->getRepository(User::class) - ->findOneByUsername('client1') - ; - - $status = $manager + $prisEnCompteStatus = $manager ->getRepository(RequestStatus::class) ->findOneBySlug('pris-en-compte') ; + $project2 = $manager + ->getRepository(Project::class) + ->findOneByName('Projet 2') + ; + + $request = new Request(); + $request->setTitle("Demande num 1"); + $request->setAuthor($client1); + $request->setCreatedAt(new DateTime()); + $request->setStatus($enAttenteStatus); + $request->setProject($project2); + $manager->persist($request); + + $request = new Request(); $request->setTitle("Demande num 2"); - $request->setAuthor($user); + $request->setAuthor($client1); $request->setCreatedAt(new DateTime()); - $request->setStatus($status); - $manager->persist($request); - - //NEW REQUEST - $user = $manager - ->getRepository(User::class) - ->findOneByUsername('client1') - ; - - $status = $manager - ->getRepository(RequestStatus::class) - ->findOneBySlug('en-cours-de-traitement') - ; - - $request = new Request(); - $request->setTitle("Demande num 3"); - $request->setAuthor($user); - $request->setCreatedAt(new DateTime()); - $request->setStatus($status); - $manager->persist($request); - - //NEW REQUEST - $user = $manager - ->getRepository(User::class) - ->findOneByUsername('client2') - ; - - $status = $manager - ->getRepository(RequestStatus::class) - ->findOneBySlug('traite') - ; - - $request = new Request(); - $request->setTitle("Demande num 4"); - $request->setAuthor($user); - $request->setCreatedAt(new DateTime()); - $request->setStatus($status); - $manager->persist($request); - - //NEW REQUEST - $user = $manager - ->getRepository(User::class) - ->findOneByUsername('client2') - ; - - $status = $manager - ->getRepository(RequestStatus::class) - ->findOneBySlug('clos') - ; - - $request = new Request(); - $request->setTitle("Demande num 5"); - $request->setAuthor($user); - $request->setCreatedAt(new DateTime()); - $request->setStatus($status); + $request->setStatus($prisEnCompteStatus); + $request->setProject($project2); $manager->persist($request); $manager->flush(); @@ -114,6 +66,7 @@ class RequestFixtures extends Fixture implements DependentFixtureInterface return [ RequestStatusFixtures::class, UserFixtures::class, + ProjectFixtures::class, ]; } diff --git a/backend/src/Migrations/Version20200219122346.php b/backend/src/Migrations/Version20200219122346.php new file mode 100644 index 0000000..38c4b56 --- /dev/null +++ b/backend/src/Migrations/Version20200219122346.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE request_status ADD slug VARCHAR(64) NOT NULL'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE request_status DROP slug'); + } +}