From 334b56cb8f478c92b511a263d300c827829489a9 Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Mon, 23 Jan 2023 16:15:48 +0100 Subject: [PATCH] bundle fixes --- README.md | 2 +- Schema/template-group.json | 5 +- Schema/template.json | 2 +- Service/InstallationService.php | 92 ++++++++++++--------------------- 4 files changed, 37 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 37b57a1..0d31e12 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ An example repository for creating php symfony flex bundles ### Using this bundle - + #### Installing with common-gateway admin user-interface @todo! diff --git a/Schema/template-group.json b/Schema/template-group.json index 8dc2c02..f785d8f 100644 --- a/Schema/template-group.json +++ b/Schema/template-group.json @@ -17,7 +17,7 @@ "templates": { "type": "array", "items": { - "$ref": "#/components/schemas/Template" + "$ref": "https://common-gateway.nl/template.schema.json" } }, "application": { @@ -25,9 +25,6 @@ }, "organization": { "type": "string" - }, - "": { - "type": "string" } }, "required": [ diff --git a/Schema/template.json b/Schema/template.json index 2dcc8be..10c5418 100644 --- a/Schema/template.json +++ b/Schema/template.json @@ -59,7 +59,7 @@ "templateGroups": { "type": "array", "items": { - "$ref": "#/components/schemas/TemplateGroup" + "$ref": "https://common-gateway.nl/template-group.schema.json" } } }, diff --git a/Service/InstallationService.php b/Service/InstallationService.php index b0404e0..c249a5e 100644 --- a/Service/InstallationService.php +++ b/Service/InstallationService.php @@ -7,6 +7,7 @@ use App\Entity\Endpoint; use CommonGateway\CoreBundle\Installer\InstallerInterface; use Doctrine\ORM\EntityManagerInterface; +use PhpParser\Parser\Multiple; use Symfony\Component\Console\Style\SymfonyStyle; class InstallationService implements InstallerInterface @@ -51,66 +52,41 @@ public function checkDataConsistency() { // Lets create some genneric dashboard cards - // $objectsThatShouldHaveCards = ['https://common-gateway.nl/template-group.schema.json', 'https://common-gateway.nl/template.schema.json']; - - // foreach ($objectsThatShouldHaveCards as $object) { - // (isset($this->io) ? $this->io->writeln('Looking for a dashboard card for: ' . $object) : ''); - // $entity = $this->entityManager->getRepository('App:Entity')->findOneBy(['reference' => $object]); - // if ( - // $entity && - // !$dashboardCard = $this->entityManager->getRepository('App:DashboardCard')->findOneBy(['entityId' => $entity->getId()]) - // ) { - // $dashboardCard = new DashboardCard($entity); - // $this->entityManager->persist($dashboardCard); - // (isset($this->io) ? $this->io->writeln('Dashboard card created') : ''); - // continue; - // } - // (isset($this->io) ? $this->io->writeln('Dashboard card found') : ''); - // } + $objectsThatShouldHaveCards = ['https://common-gateway.nl/template-group.schema.json', 'https://common-gateway.nl/template.schema.json']; + + foreach ($objectsThatShouldHaveCards as $object) { + (isset($this->io) ? $this->io->writeln('Looking for a dashboard card for: ' . $object) : ''); + $entity = $this->entityManager->getRepository('App:Entity')->findOneBy(['reference' => $object]); + if ( + $entity && + !$dashboardCard = $this->entityManager->getRepository('App:DashboardCard')->findOneBy(['entityId' => $entity->getId()]) + ) { + $dashboardCard = new DashboardCard($entity); + $this->entityManager->persist($dashboardCard); + (isset($this->io) ? $this->io->writeln('Dashboard card created') : ''); + continue; + } + (isset($this->io) ? $this->io->writeln('Dashboard card found') : ''); + } // Let create some endpoints - // $objectsThatShouldHaveEndpoints = ['https://common-gateway.nl/template-group.schema.json', 'https://common-gateway.nl/template.schema.json']; - - // foreach ($objectsThatShouldHaveEndpoints as $object) { - // (isset($this->io) ? $this->io->writeln('Looking for a endpoint for: ' . $object) : ''); - // $entity = $this->entityManager->getRepository('App:Entity')->findOneBy(['reference' => $object]); - - // if ( - // $entity && - // count($entity->getEndpoints()) == 0 - // ) { - // $endpoint = new Endpoint($entity); - // $this->entityManager->persist($endpoint); - // (isset($this->io) ? $this->io->writeln('Endpoint created') : ''); - // continue; - // } - // (isset($this->io) ? $this->io->writeln('Endpoint found') : ''); - // } - - $schemaRepository = $this->entityManager->getRepository('App:Entity'); - $endpointRepository = $this->entityManager->getRepository('App:Endpoint'); - $templateGroup = $schemaRepository->findOneBy(['name' => 'TemplateGroup']); - - $endpoint = $endpointRepository->findOneBy(['name' => 'TemplateGroups collection']) ?? new Endpoint(); - $endpoint->setName('TemplateGroups collection'); - $endpoint->setPathRegex('^(template_groups)$'); - $endpoint->setPath(['template_groups']); - $endpoint->setMethods(["POST", "GET"]); - $endpoint->setMethod("GET"); - $endpoint->setEntity($templateGroup); - $endpoint->setOperationType('collection'); - $this->entityManager->persist($endpoint); - - $endpoint = $endpointRepository->findOneBy(['name' => 'TemplateGroups item']) ?? new Endpoint(); - $endpoint->setName('TemplateGroups item'); - $endpoint->setPathRegex('^(template_groups/[a-z0-9-]{36})$'); - $endpoint->setPath(['template_groups', '[a-z0-9-]{36}']); - $endpoint->setMethods(["PUT", "GET"]); - $endpoint->setMethod("PUT"); - $endpoint->setEntity($templateGroup); - $endpoint->setOperationType('item'); - $this->entityManager->persist($endpoint); - + $objectsThatShouldHaveEndpoints = [['ref' => 'https://common-gateway.nl/template-group.schema.json', 'path' => 'template_groups'], ['ref' => 'https://common-gateway.nl/template.schema.json', 'path' => 'templates']]; + + foreach ($objectsThatShouldHaveEndpoints as $object) { + (isset($this->io) ? $this->io->writeln('Looking for a endpoint for: ' . $object['ref']) : ''); + $entity = $this->entityManager->getRepository('App:Entity')->findOneBy(['reference' => $object['ref']]); + + if ( + $entity && + count($entity->getEndpoints()) == 0 + ) { + $endpoint = new Endpoint($entity, $object['path']); + $this->entityManager->persist($endpoint); + (isset($this->io) ? $this->io->writeln('Endpoint created') : ''); + continue; + } + (isset($this->io) ? $this->io->writeln('Endpoint found') : ''); + } $this->entityManager->flush();