From 75caf3fa14193fb7afec7910517da3179ec5e4f1 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 16 Jul 2021 09:55:07 +0200 Subject: [PATCH] rdv: adapt entities + add fixtures --- .../Controller/CalendarController.php | 480 ++++++++++++++++++ .../DataFixtures/ORM/LoadCancelReason.php | 46 ++ .../DataFixtures/ORM/LoadInvite.php | 44 ++ .../ChillCalendarExtension.php | 48 ++ .../DependencyInjection/Configuration.php | 29 ++ .../Entity/CancelReason.php | 6 +- .../ChillCalendarBundle/Entity/Invite.php | 8 +- .../config/services/fixtures.yaml | 8 + .../migrations/Version20210715141731.php | 9 +- 9 files changed, 668 insertions(+), 10 deletions(-) create mode 100644 src/Bundle/ChillCalendarBundle/Controller/CalendarController.php create mode 100644 src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCancelReason.php create mode 100644 src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadInvite.php create mode 100644 src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php create mode 100644 src/Bundle/ChillCalendarBundle/DependencyInjection/Configuration.php create mode 100644 src/Bundle/ChillCalendarBundle/config/services/fixtures.yaml diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php new file mode 100644 index 000000000..616829f19 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -0,0 +1,480 @@ +, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\CalendarBundle\Controller; + +use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Privacy\PrivacyEvent; +use Psr\Log\LoggerInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Form\Form; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Core\Role\Role; +use Chill\CalendarBundle\Entity\Calendar; +use Chill\CalendarBundle\Form\CalendarType; +use Symfony\Component\Serializer\SerializerInterface; + +/** + * Class CalendarController + * + * @package Chill\CalendarBundle\Controller + */ +class CalendarController extends AbstractController +{ + protected EventDispatcherInterface $eventDispatcher; + + protected AuthorizationHelper $authorizationHelper; + + protected LoggerInterface $logger; + + protected SerializerInterface $serializer; + + public function __construct( + EventDispatcherInterface $eventDispatcher, + AuthorizationHelper $authorizationHelper, + LoggerInterface $logger, + SerializerInterface $serializer + ) { + $this->eventDispatcher = $eventDispatcher; + $this->authorizationHelper = $authorizationHelper; + $this->logger = $logger; + $this->serializer = $serializer; + } + + /** + * Lists all Calendar entities. + */ + public function listAction(Request $request): Response + { + $em = $this->getDoctrine()->getManager(); + $view = null; + + [$person, $accompanyingPeriod] = $this->getEntity($request); + + if ($person instanceof Person) { + $reachableScopes = $this->authorizationHelper + ->getReachableCircles($this->getUser(), new Role('CHILL_Calendar_SEE'), + $person->getCenter()); + + $activities = $em->getRepository(Calendar::class) + ->findByPersonImplied($person, $reachableScopes) + ; + + $event = new PrivacyEvent($person, array( + 'element_class' => Calendar::class, + 'action' => 'list' + )); + $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); + + $view = 'ChillCalendarBundle:Calendar:listPerson.html.twig'; + } elseif ($accompanyingPeriod instanceof AccompanyingPeriod) { + $activities = $em->getRepository('ChillCalendarBundle:Calendar')->findBy( + ['accompanyingPeriod' => $accompanyingPeriod], + ['date' => 'DESC'], + ); + + $view = 'ChillCalendarBundle:Calendar:listAccompanyingCourse.html.twig'; + } + + return $this->render($view, array( + 'activities' => $activities, + 'person' => $person, + 'accompanyingCourse' => $accompanyingPeriod, + )); + } + + public function selectTypeAction(Request $request): Response + { + $em = $this->getDoctrine()->getManager(); + $view = null; + + [$person, $accompanyingPeriod] = $this->getEntity($request); + + if ($accompanyingPeriod instanceof AccompanyingPeriod) { + $view = 'ChillCalendarBundle:Calendar:selectTypeAccompanyingCourse.html.twig'; + } elseif ($person instanceof Person) { + $view = 'ChillCalendarBundle:Calendar:selectTypePerson.html.twig'; + } + + $data = []; + + $activityTypeCategories = $em->getRepository(\Chill\CalendarBundle\Entity\ActivityTypeCategory::class) + ->findBy(['active' => true], ['ordering' => 'ASC']); + + foreach ($activityTypeCategories as $activityTypeCategory) { + $activityTypes = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) + ->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']); + + $data[] = [ + 'activityTypeCategory' => $activityTypeCategory, + 'activityTypes' => $activityTypes, + ]; + } + + if ($view === null) { + throw $this->createNotFoundException('Template not found'); + } + + return $this->render($view, [ + 'person' => $person, + 'accompanyingCourse' => $accompanyingPeriod, + 'data' => $data, + ]); + } + + public function newAction(Request $request): Response + { + $em = $this->getDoctrine()->getManager(); + + [$person, $accompanyingPeriod] = $this->getEntity($request); + + if ($accompanyingPeriod instanceof AccompanyingPeriod) { + $view = 'ChillCalendarBundle:Calendar:newAccompanyingCourse.html.twig'; + } elseif ($person instanceof Person) { + $view = 'ChillCalendarBundle:Calendar:newPerson.html.twig'; + } + + $activityType_id = $request->get('activityType_id', 0); + $activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) + ->find($activityType_id); + + if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType || + !$activityType->isActive()) { + + $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + return $this->redirectToRoute('chill_activity_activity_select_type', $params); + } + + $entity = new Calendar(); + $entity->setUser($this->getUser()); + + if ($person instanceof Person) { + $entity->setPerson($person); + } + + if ($accompanyingPeriod instanceof AccompanyingPeriod) { + $entity->setAccompanyingPeriod($accompanyingPeriod); + } + + $entity->setType($activityType); + $entity->setDate(new \DateTime('now')); + + // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période + // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity); + + $form = $this->createForm(ActivityType::class, $entity, [ + 'center' => $entity->getCenter(), + 'role' => new Role('CHILL_ACTIVITY_CREATE'), + 'activityType' => $entity->getType(), + 'accompanyingPeriod' => $accompanyingPeriod, + ])->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em->persist($entity); + $em->flush(); + + $this->addFlash('success', $this->get('translator')->trans('Success : activity created!')); + + $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + $params['id'] = $entity->getId(); + + return $this->redirectToRoute('chill_activity_activity_show', $params); + } + + if ($view === null) { + throw $this->createNotFoundException('Template not found'); + } + + $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); + + return $this->render($view, [ + 'person' => $person, + 'accompanyingCourse' => $accompanyingPeriod, + 'entity' => $entity, + 'form' => $form->createView(), + 'activity_json' => $activity_array + ]); + } + + public function showAction(Request $request, $id): Response + { + $em = $this->getDoctrine()->getManager(); + + [$person, $accompanyingPeriod] = $this->getEntity($request); + + if ($accompanyingPeriod instanceof AccompanyingPeriod) { + $view = 'ChillCalendarBundle:Calendar:showAccompanyingCourse.html.twig'; + } elseif ($person instanceof Person) { + $view = 'ChillCalendarBundle:Calendar:showPerson.html.twig'; + } + + $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Calendar entity.'); + } + + if (null !== $accompanyingPeriod) { + $entity->personsAssociated = $entity->getPersonsAssociated(); + $entity->personsNotAssociated = $entity->getPersonsNotAssociated(); + } + + // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période + // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity); + + $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); + + // TODO + /* + $event = new PrivacyEvent($person, array( + 'element_class' => Activity::class, + 'element_id' => $entity->getId(), + 'action' => 'show' + )); + $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); + */ + + if ($view === null) { + throw $this->createNotFoundException('Template not found'); + } + + return $this->render($view, array( + 'person' => $person, + 'accompanyingCourse' => $accompanyingPeriod, + 'entity' => $entity, + 'delete_form' => $deleteForm->createView(), + )); + } + + /** + * Displays a form to edit an existing Activity entity. + * + */ + public function editAction($id, Request $request): Response + { + $em = $this->getDoctrine()->getManager(); + + [$person, $accompanyingPeriod] = $this->getEntity($request); + + if ($accompanyingPeriod instanceof AccompanyingPeriod) { + $view = 'ChillCalendarBundle:Calendar:editAccompanyingCourse.html.twig'; + } elseif ($person instanceof Person) { + $view = 'ChillCalendarBundle:Calendar:editPerson.html.twig'; + } + + $entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find Calendar entity.'); + } + + // TODO + // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); + + $form = $this->createForm(CalendarType::class, $entity, [ + 'center' => $entity->getCenter(), + 'role' => new Role('CHILL_ACTIVITY_UPDATE'), + 'activityType' => $entity->getType(), + 'accompanyingPeriod' => $accompanyingPeriod, + ])->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em->persist($entity); + $em->flush(); + + $this->addFlash('success', $this->get('translator')->trans('Success : activity updated!')); + + $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + $params['id'] = $id; + return $this->redirectToRoute('chill_activity_activity_show', $params); + } + + $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); + + /* + * TODO + $event = new PrivacyEvent($person, array( + 'element_class' => Calendar::class, + 'element_id' => $entity->getId(), + 'action' => 'edit' + )); + $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); + */ + + if ($view === null) { + throw $this->createNotFoundException('Template not found'); + } + + $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); + + return $this->render($view, array( + 'entity' => $entity, + 'edit_form' => $form->createView(), + 'delete_form' => $deleteForm->createView(), + 'person' => $person, + 'accompanyingCourse' => $accompanyingPeriod, + 'activity_json' => $activity_array + )); + } + + /** + * Deletes a Calendar entity. + * + */ + public function deleteAction(Request $request, $id) + { + $em = $this->getDoctrine()->getManager(); + + [$person, $accompanyingPeriod] = $this->getEntity($request); + + if ($accompanyingPeriod instanceof AccompanyingPeriod) { + $view = 'ChillCalendarBundle:Calendar:confirm_deleteAccompanyingCourse.html.twig'; + } elseif ($person instanceof Person) { + $view = 'ChillCalendarBundle:Calendar:confirm_deletePerson.html.twig'; + } + + /* @var $activity Calendar */ + $activity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id); + + if (!$activity) { + throw $this->createNotFoundException('Unable to find Calendar entity.'); + } + + // TODO + // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); + + $form = $this->createDeleteForm($id, $person, $accompanyingPeriod); + + if ($request->getMethod() === Request::METHOD_DELETE) { + $form->handleRequest($request); + + if ($form->isValid()) { + + $this->logger->notice("An activity has been removed", array( + 'by_user' => $this->getUser()->getUsername(), + 'activity_id' => $activity->getId(), + 'person_id' => $activity->getPerson() ? $activity->getPerson()->getId() : null, + 'comment' => $activity->getComment()->getComment(), + 'scope_id' => $activity->getScope() ? $activity->getScope()->getId() : null, + 'reasons_ids' => $activity->getReasons() + ->map(function ($ar) { return $ar->getId(); }) + ->toArray(), + 'type_id' => $activity->getType()->getId(), + 'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null, + 'date' => $activity->getDate()->format('Y-m-d'), + 'attendee' => $activity->getAttendee() + )); + + $em->remove($activity); + $em->flush(); + + $this->addFlash('success', $this->get('translator') + ->trans("The activity has been successfully removed.")); + + $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + return $this->redirectToRoute('chill_activity_activity_list', $params); + } + } + + if ($view === null) { + throw $this->createNotFoundException('Template not found'); + } + + return $this->render($view, array( + 'activity' => $activity, + 'delete_form' => $form->createView(), + 'person' => $person, + 'accompanyingCourse' => $accompanyingPeriod, + )); + } + + /** + * Creates a form to delete a Calendar entity by id. + */ + private function createDeleteForm(int $id, ?Person $person, ?AccompanyingPeriod $accompanyingPeriod): Form + { + $params = $this->buildParamsToUrl($person, $accompanyingPeriod); + $params['id'] = $id; + + return $this->createFormBuilder() + ->setAction($this->generateUrl('chill_activity_activity_delete', $params)) + ->setMethod('DELETE') + ->add('submit', SubmitType::class, array('label' => 'Delete')) + ->getForm() + ; + } + + private function getEntity(Request $request): array + { + $em = $this->getDoctrine()->getManager(); + $person = $accompanyingPeriod = null; + + if ($request->query->has('person_id')) { + $person_id = $request->get('person_id'); + $person = $em->getRepository(Person::class)->find($person_id); + + if ($person === null) { + throw $this->createNotFoundException('Person not found'); + } + + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + } elseif ($request->query->has('accompanying_period_id')) { + $accompanying_period_id = $request->get('accompanying_period_id'); + $accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($accompanying_period_id); + + if ($accompanyingPeriod === null) { + throw $this->createNotFoundException('Accompanying Period not found'); + } + + // TODO Add permission + // $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + } else { + throw $this->createNotFoundException("Person or Accompanying Period not found"); + } + + return [ + $person, $accompanyingPeriod + ]; + } + + private function buildParamsToUrl( + ?Person $person, + ?AccompanyingPeriod $accompanyingPeriod + ): array { + $params = []; + + if ($person) { + $params['person_id'] = $person->getId(); + } + + if ($accompanyingPeriod) { + $params['accompanying_period_id'] = $accompanyingPeriod->getId(); + } + + return $params; + } +} diff --git a/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCancelReason.php b/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCancelReason.php new file mode 100644 index 000000000..d9e92a049 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCancelReason.php @@ -0,0 +1,46 @@ + array('fr' => 'Annulé par l\'utilisateur')), + array('name' => array('fr' => 'Annulé par l\'usager')), + array('name' => array('fr' => 'Ne pas comptabiliser')), + ); + + foreach ($arr as $a) { + print "Creating calendar cancel reason : " . $a['name']['fr'] . "\n"; + $cancelReason= (new CancelReason()) + ->setCanceledBy($a['name']) + ->setActive(true); + $manager->persist($cancelReason); + $reference = 'CancelReason_'.$a['name']['fr']; + $this->addReference($reference, $cancelReason); + static::$references[] = $reference; + } + + $manager->flush(); + } +} diff --git a/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadInvite.php b/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadInvite.php new file mode 100644 index 000000000..93d5f6f55 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadInvite.php @@ -0,0 +1,44 @@ + array('fr' => 'Rendez-vous décliné')), + array('name' => array('fr' => 'Rendez-vous accepté')), + ); + + foreach ($arr as $a) { + print "Creating calendar invite : " . $a['name']['fr'] . "\n"; + $invite= (new Invite()) + ->setStatus($a['name']); + $manager->persist($invite); + $reference = 'Invite_'.$a['name']['fr']; + $this->addReference($reference, $invite); + static::$references[] = $reference; + } + + $manager->flush(); + } +} diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php new file mode 100644 index 000000000..a1f68da1e --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php @@ -0,0 +1,48 @@ +processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); + $loader->load('services/fixtures.yaml'); + } + + public function prepend(ContainerBuilder $container) + { + // $this->preprendRoutes($container); + } + + // protected function preprendRoutes(ContainerBuilder $container) + // { + + // $container->prependExtensionConfig('chill_main', array( + // 'routing' => array( + // 'resources' => array( + // '@ChillCalendarBundle/config/routes.yaml' + // ) + // ) + // )); + // } + + +} diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/Configuration.php new file mode 100644 index 000000000..40524b53e --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/Configuration.php @@ -0,0 +1,29 @@ +getRootNode('chill_calendar'); + + // Here you should define the parameters that are allowed to + // configure your bundle. See the documentation linked above for + // more information on that topic. + + return $treeBuilder; + } +} diff --git a/src/Bundle/ChillCalendarBundle/Entity/CancelReason.php b/src/Bundle/ChillCalendarBundle/Entity/CancelReason.php index dacb2fd5e..6a21b215c 100644 --- a/src/Bundle/ChillCalendarBundle/Entity/CancelReason.php +++ b/src/Bundle/ChillCalendarBundle/Entity/CancelReason.php @@ -24,7 +24,7 @@ class CancelReason private $active; /** - * @ORM\Column(type="string", length=255) + * @ORM\Column(type="json_array") */ private $canceledBy; @@ -50,12 +50,12 @@ class CancelReason return $this; } - public function getCanceledBy(): ?string + public function getCanceledBy(): ?array { return $this->canceledBy; } - public function setCanceledBy(string $canceledBy): self + public function setCanceledBy(array $canceledBy): self { $this->canceledBy = $canceledBy; diff --git a/src/Bundle/ChillCalendarBundle/Entity/Invite.php b/src/Bundle/ChillCalendarBundle/Entity/Invite.php index c1f792d7d..9b44a93ee 100644 --- a/src/Bundle/ChillCalendarBundle/Entity/Invite.php +++ b/src/Bundle/ChillCalendarBundle/Entity/Invite.php @@ -25,21 +25,21 @@ class Invite private User $user; /** - * @ORM\Column(type="string", length=255) + * @ORM\Column(type="json_array") */ - private $status; + private $status = []; public function getId(): ?int { return $this->id; } - public function getStatus(): ?string + public function getStatus(): ?array { return $this->status; } - public function setStatus(string $status): self + public function setStatus(array $status): self { $this->status = $status; diff --git a/src/Bundle/ChillCalendarBundle/config/services/fixtures.yaml b/src/Bundle/ChillCalendarBundle/config/services/fixtures.yaml new file mode 100644 index 000000000..235856a4b --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/config/services/fixtures.yaml @@ -0,0 +1,8 @@ +--- +services: + Chill\CalendarBundle\DataFixtures\ORM\LoadCancelReason: + tags: + - { 'name': doctrine.fixture.orm } + Chill\CalendarBundle\DataFixtures\ORM\LoadInvite: + tags: + - { 'name': doctrine.fixture.orm } diff --git a/src/Bundle/ChillCalendarBundle/migrations/Version20210715141731.php b/src/Bundle/ChillCalendarBundle/migrations/Version20210715141731.php index e93358fb7..7e535fe27 100644 --- a/src/Bundle/ChillCalendarBundle/migrations/Version20210715141731.php +++ b/src/Bundle/ChillCalendarBundle/migrations/Version20210715141731.php @@ -49,9 +49,11 @@ final class Version20210715141731 extends AbstractMigration $this->addSql('CREATE INDEX IDX_38D57D05A76ED395 ON chill_calendar.calendar_range (user_id)'); $this->addSql('COMMENT ON COLUMN chill_calendar.calendar_range.startDate IS \'(DC2Type:date_immutable)\''); $this->addSql('COMMENT ON COLUMN chill_calendar.calendar_range.endDate IS \'(DC2Type:date_immutable)\''); - $this->addSql('CREATE TABLE chill_calendar.cancel_reason (id INT NOT NULL, active BOOLEAN NOT NULL, canceledBy VARCHAR(255) NOT NULL, name JSON NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE chill_calendar.cancel_reason (id INT NOT NULL, active BOOLEAN NOT NULL, canceledBy JSON NOT NULL, name JSON NOT NULL, PRIMARY KEY(id))'); $this->addSql('COMMENT ON COLUMN chill_calendar.cancel_reason.name IS \'(DC2Type:json_array)\''); - $this->addSql('CREATE TABLE chill_calendar.invite (id INT NOT NULL, user_id INT DEFAULT NULL, status VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('COMMENT ON COLUMN chill_calendar.cancel_reason.canceledBy IS \'(DC2Type:json_array)\''); + $this->addSql('CREATE TABLE chill_calendar.invite (id INT NOT NULL, user_id INT DEFAULT NULL, status JSON NOT NULL, PRIMARY KEY(id))'); + $this->addSql('COMMENT ON COLUMN chill_calendar.invite.status IS \'(DC2Type:json_array)\''); $this->addSql('CREATE INDEX IDX_F517FFA7A76ED395 ON chill_calendar.invite (user_id)'); $this->addSql('ALTER TABLE chill_calendar.calendar ADD CONSTRAINT FK_712315ACA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE chill_calendar.calendar ADD CONSTRAINT FK_712315ACD7FA8EF0 FOREIGN KEY (accompanyingPeriod_id) REFERENCES chill_person_accompanying_period (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); @@ -72,7 +74,7 @@ final class Version20210715141731 extends AbstractMigration } public function down(Schema $schema): void - { + { $this->addSql('ALTER TABLE chill_calendar.calendar_to_persons DROP CONSTRAINT FK_AEE94715A40A2C8'); $this->addSql('ALTER TABLE chill_calendar.calendar_to_non_professionals DROP CONSTRAINT FK_FADF2C77A40A2C8'); $this->addSql('ALTER TABLE chill_calendar.calendar_to_thirdparties DROP CONSTRAINT FK_2BAB7EFDA40A2C8'); @@ -92,5 +94,6 @@ final class Version20210715141731 extends AbstractMigration $this->addSql('DROP TABLE chill_calendar.calendar_range'); $this->addSql('DROP TABLE chill_calendar.cancel_reason'); $this->addSql('DROP TABLE chill_calendar.invite'); + $this->addSql('DROP SCHEMA chill_calendar'); } }