1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fi\PannelloAmministrazioneBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Fi\OsBundle\DependencyInjection\OsFunctions; |
11
|
|
|
|
12
|
|
|
class GenerateentitiesCommand extends ContainerAwareCommand |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
protected $apppaths; |
16
|
|
|
protected $genhelper; |
17
|
|
|
protected $pammutils; |
18
|
|
|
|
19
|
6 |
|
protected function configure() |
20
|
|
|
{ |
21
|
|
|
$this |
22
|
6 |
|
->setName('pannelloamministrazione:generateentities') |
23
|
6 |
|
->setDescription('Genera le entities partendo da un modello workbeanch mwb') |
24
|
6 |
|
->setHelp('Genera le entities partendo da un modello workbeanch mwb, <br/>fifree.mwb Fi/CoreBundle default [--schemaupdate]<br/>') |
25
|
6 |
|
->addArgument('em', InputArgument::OPTIONAL, 'Entity manager, default = default') |
26
|
6 |
|
->addOption('schemaupdate', null, InputOption::VALUE_NONE, 'Se settato fa anche lo schema update sul db'); |
27
|
6 |
|
} |
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
set_time_limit(0); |
31
|
|
|
$this->apppaths = $this->getContainer()->get("pannelloamministrazione.projectpath"); |
|
|
|
|
32
|
|
|
$this->genhelper = $this->getContainer()->get("pannelloamministrazione.generatorhelper"); |
|
|
|
|
33
|
|
|
$this->pammutils = $this->getContainer()->get("pannelloamministrazione.utils"); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$schemaupdate = false; |
36
|
|
|
|
37
|
|
|
if (!$input->getArgument('em')) { |
38
|
|
|
$emdest = 'default'; |
39
|
|
|
} else { |
40
|
|
|
$emdest = $input->getArgument('em'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ($input->getOption('schemaupdate')) { |
44
|
|
|
$schemaupdate = true; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/* $generateentitiesresult = $this->pammutils->clearCache(); |
|
|
|
|
48
|
|
|
if ($generateentitiesresult["errcode"] < 0) { |
49
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
50
|
|
|
return 1; |
51
|
|
|
} else { |
52
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
53
|
|
|
} */ |
54
|
|
|
$generatecheck = $this->generateentities($emdest, $schemaupdate, $output); |
55
|
|
|
if ($generatecheck < 0) { |
56
|
|
|
return 1; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return 0; |
60
|
|
|
} |
61
|
|
|
private function generateentities($emdest, $schemaupdate, $output) |
62
|
|
|
{ |
63
|
|
|
/* GENERATE ENTITIES */ |
64
|
|
|
$output->writeln('Creazione entities class'); |
65
|
|
|
|
66
|
|
|
$console = $this->apppaths->getConsole(); |
|
|
|
|
67
|
|
|
$scriptGenerator = $console . ' make:entity'; |
68
|
|
|
$phpPath = OsFunctions::getPHPExecutableFromPath(); |
|
|
|
|
69
|
|
|
|
70
|
|
|
$command = $phpPath . ' ' . $scriptGenerator . ' --regenerate App'; |
71
|
|
|
|
72
|
|
|
$generateentitiesresult = $this->pammutils->runCommand($command); |
73
|
|
|
if ($generateentitiesresult["errcode"] < 0) { |
|
|
|
|
74
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
|
|
|
75
|
|
|
return 1; |
76
|
|
|
} else { |
77
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$output->writeln('<info>Entities class create</info>'); |
81
|
|
|
|
82
|
|
|
if ($schemaupdate) { |
83
|
|
|
$output->writeln('Aggiornamento database...'); |
84
|
|
|
|
85
|
|
|
$scriptGenerator = $console . ' doctrine:schema:update'; |
86
|
|
|
|
87
|
|
|
$phpPath = OsFunctions::getPHPExecutableFromPath(); |
88
|
|
|
$command = $phpPath . ' ' . $scriptGenerator . ' --force --em=' . $emdest |
89
|
|
|
. ' --no-debug --env=' . $this->getContainer()->get('kernel')->getEnvironment(); |
90
|
|
|
|
91
|
|
|
$schemaupdateresult = $this->pammutils->runCommand($command); |
92
|
|
|
if ($schemaupdateresult["errcode"] < 0) { |
|
|
|
|
93
|
|
|
$output->writeln($schemaupdateresult["errmsg"]); |
|
|
|
|
94
|
|
|
} else { |
95
|
|
|
$output->writeln($schemaupdateresult["errmsg"]); |
|
|
|
|
96
|
|
|
$output->writeln('<info>Aggiornamento database completato</info>'); |
97
|
|
|
} |
98
|
|
|
return $schemaupdateresult["errcode"]; |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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.