-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallationService.php
More file actions
97 lines (78 loc) · 3.18 KB
/
InstallationService.php
File metadata and controls
97 lines (78 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
// src/Service/InstallationService.php
namespace CommonGateway\TemplateBundle\Service;
use App\Entity\DashboardCard;
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
{
private EntityManagerInterface $entityManager;
private SymfonyStyle $io;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* Set symfony style in order to output to the console
*
* @param SymfonyStyle $io
* @return self
*/
public function setStyle(SymfonyStyle $io): self
{
$this->io = $io;
return $this;
}
public function install()
{
$this->checkDataConsistency();
}
public function update()
{
$this->checkDataConsistency();
}
public function uninstall()
{
// Do some cleanup
}
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') : '');
}
// Let create some endpoints
$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();
// Lets see if there is a generic search endpoint
}
}