|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
9
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
10
|
|
|
|
|
11
|
|
|
class BiConfiguratorexportCommand extends ContainerAwareCommand |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
private $entities = array(); |
|
15
|
|
|
private $em; |
|
16
|
|
|
private $systementity; |
|
17
|
|
|
private $output; |
|
18
|
|
|
|
|
19
|
3 |
|
protected function configure() |
|
20
|
|
|
{ |
|
21
|
|
|
$this |
|
22
|
3 |
|
->setName('bi:configuratorexport') |
|
23
|
3 |
|
->setDescription('Configuratore per Fifree') |
|
24
|
3 |
|
->setHelp('Esporta la configurazione di bi'); |
|
25
|
3 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @SuppressWarnings(PHPMD.UnusedLocalVariable) |
|
29
|
|
|
*/ |
|
30
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
31
|
|
|
{ |
|
32
|
1 |
|
$fs = new Filesystem; |
|
|
|
|
|
|
33
|
1 |
|
$this->em = $this->getContainer()->get("doctrine")->getManager(); |
|
|
|
|
|
|
34
|
1 |
|
$this->systementity = $this->getContainer()->get("fi.bicorebundle.utility.entity.system"); |
|
|
|
|
|
|
35
|
1 |
|
$this->output = $output; |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
try { |
|
38
|
|
|
//$fixturefile = $this->getContainer()->get('kernel')->locateResource('@BiCoreBundle/Resources/config/fixtures.yml'); |
|
|
|
|
|
|
39
|
1 |
|
$fixturefile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "fixtures.yml"; |
|
|
|
|
|
|
40
|
1 |
|
$fs->remove($fixturefile); |
|
41
|
1 |
|
$systementities = $this->systementity->getSystemEntities(); |
|
42
|
1 |
|
foreach ($systementities as $entity => $details) { |
|
43
|
1 |
|
$ret = $this->export($fixturefile, $entity); |
|
44
|
1 |
|
if ($ret == 1) { |
|
45
|
1 |
|
return 1; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
1 |
|
return 0; |
|
49
|
|
|
} catch (\Exception $exc) { |
|
50
|
|
|
echo $exc->getMessage() . " at line " . $exc->getLine(); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
protected function export($fixturefile, $entity) |
|
55
|
|
|
{ |
|
56
|
1 |
|
$entityclass = $entity; |
|
57
|
1 |
|
$ret = $this->exportEntity($fixturefile, $entityclass); |
|
|
|
|
|
|
58
|
1 |
|
if ($ret == 0) { |
|
59
|
1 |
|
foreach ($this->entities as $entity) { |
|
|
|
|
|
|
60
|
|
|
$this->output->writeln("<info>Esporto " . $entity . " su file</info>"); |
|
|
|
|
|
|
61
|
|
|
$this->exportEntityToFile($fixturefile, $entity); |
|
62
|
|
|
} |
|
63
|
1 |
|
$this->exportEntityToFile($fixturefile, $entityclass); |
|
64
|
1 |
|
return 0; |
|
65
|
|
|
} |
|
66
|
|
|
return 1; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
private function exportEntity($fixturefile, $entityclass) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
1 |
|
$entityutility = $this->getContainer()->get("fi.bicorebundle.utility.entity"); |
|
|
|
|
|
|
72
|
1 |
|
$this->output->writeln("<info>Export Entity: " . $entityclass . "</info>"); |
|
|
|
|
|
|
73
|
1 |
|
if ($entityutility->entityExists($entityclass)) { |
|
|
|
|
|
|
74
|
|
|
/* $hasEntityCollegate = $entityutility->entityHasJoinTables($entityclass); |
|
|
|
|
|
|
75
|
|
|
if ($hasEntityCollegate) { |
|
76
|
|
|
$this->output->writeln("<info>Entity " . $entityclass . " ha tabelle in join</info>"); |
|
77
|
|
|
$entityCollegata = $entityutility->getEntityJoinTables($entityclass); |
|
78
|
|
|
foreach ($entityCollegata as $key => $tabella) { |
|
79
|
|
|
$this->entities[] = $key; |
|
80
|
|
|
$this->output->writeln("<info>Prima esporto " . $key . " -> " . $tabella["entity"]["fieldName"] . "</info>"); |
|
81
|
|
|
$this->exportEntity($fixturefile, $key); |
|
82
|
|
|
} |
|
83
|
|
|
} */ |
|
84
|
|
|
} else { |
|
85
|
|
|
$this->output->writeln("<error>Entity not found: " . $entityclass . " </error>"); |
|
|
|
|
|
|
86
|
|
|
return 1; |
|
87
|
|
|
} |
|
88
|
1 |
|
return 0; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
private function exportEntityToFile($fixturefile, $entityclass) |
|
92
|
|
|
{ |
|
93
|
1 |
|
$entityDump = array(); |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
1 |
|
$query = $this->em->createQueryBuilder() |
|
97
|
1 |
|
->select('p') |
|
98
|
1 |
|
->from($entityclass, 'p') |
|
99
|
1 |
|
->orderBy("p.id", "asc") |
|
|
|
|
|
|
100
|
1 |
|
->getQuery() |
|
101
|
|
|
; |
|
102
|
1 |
|
$repo = $query->getArrayResult(); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
//$repo = $this->em->getRepository($entityclass)->findAll(); |
|
|
|
|
|
|
106
|
1 |
|
$this->output->writeln("<info>Trovate " . count($repo) . " records per l'entity " . $entityclass . "</info>"); |
|
|
|
|
|
|
107
|
1 |
|
foreach ($repo as $row) { |
|
108
|
1 |
|
$entityDump[$entityclass][] = $row; |
|
109
|
|
|
} |
|
110
|
1 |
|
if (count($entityDump) > 0) { |
|
111
|
1 |
|
$yml = Yaml::dump($entityDump); |
|
112
|
1 |
|
file_put_contents($fixturefile, $yml, FILE_APPEND); |
|
113
|
|
|
} |
|
114
|
1 |
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.