|
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\Output\OutputInterface; |
|
9
|
|
|
use Fi\OsBundle\DependencyInjection\OsFunctions; |
|
10
|
|
|
|
|
11
|
|
|
class GenerateOrmEntitiesCommand extends ContainerAwareCommand |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
protected $apppaths; |
|
15
|
|
|
protected $genhelper; |
|
16
|
|
|
protected $pammutils; |
|
17
|
|
|
|
|
18
|
2 |
|
protected function configure() |
|
19
|
|
|
{ |
|
20
|
|
|
$this |
|
21
|
2 |
|
->setName('pannelloamministrazione:generateymlentities') |
|
22
|
2 |
|
->setDescription('Genera le entities partendo da un modello workbeanch mwb') |
|
23
|
2 |
|
->setHelp('Genera i ifle yml per le entities partendo da un modello workbeanch mwb, <br/>fifree.mwb Fi/CoreBundle default<br/>') |
|
24
|
2 |
|
->addArgument('mwbfile', InputArgument::REQUIRED, 'Nome file mwb, fifree.mwb') |
|
25
|
|
|
; |
|
26
|
2 |
|
} |
|
27
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
28
|
|
|
{ |
|
29
|
1 |
|
set_time_limit(0); |
|
30
|
1 |
|
$this->apppaths = $this->getContainer()->get("pannelloamministrazione.projectpath"); |
|
|
|
|
|
|
31
|
1 |
|
$this->genhelper = $this->getContainer()->get("pannelloamministrazione.generatorhelper"); |
|
|
|
|
|
|
32
|
1 |
|
$this->pammutils = $this->getContainer()->get("pannelloamministrazione.utils"); |
|
|
|
|
|
|
33
|
1 |
|
$mwbfile = $input->getArgument('mwbfile'); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
1 |
|
$wbFile = $this->apppaths->getDocPath() . DIRECTORY_SEPARATOR . $mwbfile; |
|
|
|
|
|
|
36
|
1 |
|
$checkprerequisiti = $this->genhelper->checkprerequisiti($mwbfile, $output); |
|
37
|
|
|
|
|
38
|
1 |
|
if ($checkprerequisiti < 0) { |
|
39
|
|
|
return -1; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
$destinationPath = $this->genhelper->getDestinationEntityYmlPath(); |
|
43
|
|
|
|
|
44
|
1 |
|
$command = $this->getExportJsonCommand($wbFile); |
|
45
|
|
|
|
|
46
|
1 |
|
$schemaupdateresult = $this->pammutils->runCommand($command); |
|
47
|
1 |
|
if ($schemaupdateresult["errcode"] < 0) { |
|
|
|
|
|
|
48
|
|
|
$output->writeln($schemaupdateresult["message"]); |
|
|
|
|
|
|
49
|
|
|
return 1; |
|
50
|
|
|
} else { |
|
51
|
1 |
|
$output->writeln($schemaupdateresult["message"]); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
$this->genhelper->removeExportJsonFile(); |
|
55
|
|
|
|
|
56
|
1 |
|
$tablecheck = $this->genhelper->checktables($destinationPath, $wbFile, $output); |
|
57
|
|
|
|
|
58
|
1 |
|
if ($tablecheck < 0) { |
|
59
|
|
|
return 1; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
$output->writeln('<info>Entities yml create</info>'); |
|
63
|
1 |
|
return 0; |
|
64
|
|
|
} |
|
65
|
1 |
|
private function getExportJsonCommand($wbFile) |
|
66
|
|
|
{ |
|
67
|
1 |
|
$exportJson = $this->genhelper->getExportJsonFile(); |
|
|
|
|
|
|
68
|
1 |
|
$scriptGenerator = $this->genhelper->getScriptGenerator(); |
|
|
|
|
|
|
69
|
1 |
|
$destinationPathEscaped = $this->genhelper->getDestinationEntityYmlPath(); |
|
70
|
1 |
|
$exportjsonfile = $this->genhelper->getJsonMwbGenerator(); |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
1 |
|
$exportjsonreplaced = str_replace('[dir]', $destinationPathEscaped, $exportjsonfile); |
|
73
|
|
|
|
|
74
|
1 |
|
file_put_contents($exportJson, $exportjsonreplaced); |
|
75
|
1 |
|
$sepchr = OsFunctions::getSeparator(); |
|
76
|
1 |
|
if (OsFunctions::isWindows()) { |
|
77
|
|
|
$command = 'cd ' . $this->apppaths->getRootPath() . $sepchr |
|
78
|
|
|
. $scriptGenerator . '.bat ' |
|
79
|
|
|
. ' --config=' . |
|
80
|
|
|
$exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped; |
|
81
|
|
|
} else { |
|
82
|
1 |
|
$phpPath = OsFunctions::getPHPExecutableFromPath(); |
|
83
|
1 |
|
$command = 'cd ' . $this->apppaths->getRootPath() . $sepchr |
|
84
|
1 |
|
. $phpPath . ' ' . $scriptGenerator . ' ' |
|
85
|
1 |
|
. ' --config=' . |
|
86
|
1 |
|
$exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
1 |
|
return $command; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
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.