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