|
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
|
1 |
|
protected function configure() |
|
20
|
|
|
{ |
|
21
|
1 |
|
$this |
|
22
|
1 |
|
->setName('pannelloamministrazione:generateentities') |
|
23
|
1 |
|
->setDescription('Genera le entities partendo da un modello workbeanch mwb') |
|
24
|
1 |
|
->setHelp('Genera le entities partendo da un modello workbeanch mwb, <br/>fifree.mwb Fi/CoreBundle default [--schemaupdate]<br/>') |
|
25
|
1 |
|
->addArgument('bundlename', InputArgument::REQUIRED, 'Nome del bundle, Fi/CoreBundle') |
|
26
|
1 |
|
->addArgument('em', InputArgument::OPTIONAL, 'Entity manager, default = default') |
|
27
|
1 |
|
->addOption('schemaupdate', null, InputOption::VALUE_NONE, 'Se settato fa anche lo schema update sul db'); |
|
28
|
1 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
31
|
|
|
{ |
|
32
|
|
|
set_time_limit(0); |
|
33
|
|
|
$this->apppaths = $this->getContainer()->get("pannelloamministrazione.projectpath"); |
|
|
|
|
|
|
34
|
|
|
$this->genhelper = $this->getContainer()->get("pannelloamministrazione.generatorhelper"); |
|
|
|
|
|
|
35
|
|
|
$this->pammutils = $this->getContainer()->get("pannelloamministrazione.utils"); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$bundlename = $input->getArgument('bundlename'); |
|
|
|
|
|
|
38
|
|
|
$schemaupdate = false; |
|
39
|
|
|
|
|
40
|
|
|
if (!$input->getArgument('em')) { |
|
41
|
|
|
$emdest = 'default'; |
|
42
|
|
|
} else { |
|
43
|
|
|
$emdest = $input->getArgument('em'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if ($input->getOption('schemaupdate')) { |
|
47
|
|
|
$schemaupdate = true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/* $generateentitiesresult = $this->pammutils->clearCache(); |
|
|
|
|
|
|
51
|
|
|
if ($generateentitiesresult["errcode"] < 0) { |
|
52
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
53
|
|
|
return 1; |
|
54
|
|
|
} else { |
|
55
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
56
|
|
|
} */ |
|
57
|
|
|
|
|
58
|
|
|
$generatecheck = $this->generateentities($bundlename, $emdest, $schemaupdate, $output); |
|
59
|
|
|
if ($generatecheck < 0) { |
|
60
|
|
|
return 1; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return 0; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
private function generateentities($bundlename, $emdest, $schemaupdate, $output) |
|
67
|
|
|
{ |
|
68
|
|
|
/* GENERATE ENTITIES */ |
|
69
|
|
|
$output->writeln('Creazione entities class per il bundle ' . str_replace('/', '', $bundlename)); |
|
70
|
|
|
|
|
71
|
|
|
$console = $this->apppaths->getConsole(); |
|
|
|
|
|
|
72
|
|
|
$scriptGenerator = $console . ' doctrine:generate:entities'; |
|
73
|
|
|
$phpPath = OsFunctions::getPHPExecutableFromPath(); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
$command = $phpPath . ' ' . $scriptGenerator . ' --no-backup ' . str_replace('/', '', $bundlename) |
|
76
|
|
|
. ' --env=' . $this->getContainer()->get('kernel')->getEnvironment(); |
|
77
|
|
|
|
|
78
|
|
|
$generateentitiesresult = $this->pammutils->runCommand($command); |
|
79
|
|
|
if ($generateentitiesresult["errcode"] < 0) { |
|
|
|
|
|
|
80
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
|
|
|
|
|
81
|
|
|
return 1; |
|
82
|
|
|
} else { |
|
83
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$output->writeln('<info>Entities class create</info>'); |
|
87
|
|
|
|
|
88
|
|
|
if ($schemaupdate) { |
|
89
|
|
|
$output->writeln('Aggiornamento database...'); |
|
90
|
|
|
|
|
91
|
|
|
$scriptGenerator = $console . ' doctrine:schema:update'; |
|
92
|
|
|
|
|
93
|
|
|
$phpPath = OsFunctions::getPHPExecutableFromPath(); |
|
94
|
|
|
$command = $phpPath . ' ' . $scriptGenerator . ' --force --em=' . $emdest |
|
95
|
|
|
. ' --no-debug --env=' . $this->getContainer()->get('kernel')->getEnvironment(); |
|
96
|
|
|
|
|
97
|
|
|
$schemaupdateresult = $this->pammutils->runCommand($command); |
|
98
|
|
|
if ($schemaupdateresult["errcode"] < 0) { |
|
|
|
|
|
|
99
|
|
|
$output->writeln($schemaupdateresult["errmsg"]); |
|
|
|
|
|
|
100
|
|
|
} else { |
|
101
|
|
|
$output->writeln($schemaupdateresult["errmsg"]); |
|
|
|
|
|
|
102
|
|
|
$output->writeln('<info>Aggiornamento database completato</info>'); |
|
103
|
|
|
} |
|
104
|
|
|
return $schemaupdateresult["errcode"]; |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
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.