|
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
|
1 |
|
protected function configure() |
|
19
|
|
|
{ |
|
20
|
1 |
|
$this |
|
21
|
1 |
|
->setName('pannelloamministrazione:generateymlentities') |
|
22
|
1 |
|
->setDescription('Genera le entities partendo da un modello workbeanch mwb') |
|
23
|
1 |
|
->setHelp('Genera i ifle yml per le entities partendo da un modello workbeanch mwb, <br/>fifree.mwb Fi/CoreBundle default<br/>') |
|
24
|
1 |
|
->addArgument('mwbfile', InputArgument::REQUIRED, 'Nome file mwb, fifree.mwb') |
|
25
|
1 |
|
->addArgument('bundlename', InputArgument::REQUIRED, 'Nome del bundle, Fi/CoreBundle'); |
|
26
|
1 |
|
} |
|
27
|
|
|
|
|
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
|
|
|
$bundlename = $input->getArgument('bundlename'); |
|
36
|
|
|
$mwbfile = $input->getArgument('mwbfile'); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$wbFile = $this->apppaths->getDocPath() . DIRECTORY_SEPARATOR . $mwbfile; |
|
|
|
|
|
|
39
|
|
|
$checkprerequisiti = $this->genhelper->checkprerequisiti($bundlename, $mwbfile, $output); |
|
40
|
|
|
|
|
41
|
|
|
if ($checkprerequisiti < 0) { |
|
42
|
|
|
return -1; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$destinationPath = $this->genhelper->getDestinationEntityYmlPath($bundlename); |
|
46
|
|
|
|
|
47
|
|
|
$command = $this->getExportJsonCommand($bundlename, $wbFile); |
|
48
|
|
|
|
|
49
|
|
|
$schemaupdateresult = $this->pammutils->runCommand($command); |
|
50
|
|
|
if ($schemaupdateresult["errcode"] < 0) { |
|
|
|
|
|
|
51
|
|
|
$output->writeln($schemaupdateresult["errmsg"]); |
|
|
|
|
|
|
52
|
|
|
return 1; |
|
53
|
|
|
} else { |
|
54
|
|
|
$output->writeln($schemaupdateresult["errmsg"]); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->genhelper->removeExportJsonFile(); |
|
58
|
|
|
|
|
59
|
|
|
$tablecheck = $this->genhelper->checktables($destinationPath, $wbFile, $output); |
|
60
|
|
|
|
|
61
|
|
|
if ($tablecheck < 0) { |
|
62
|
|
|
return 1; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$output->writeln('<info>Entities yml create</info>'); |
|
66
|
|
|
/* $generateentitiesresult = $this->pammutils->clearCache(); |
|
|
|
|
|
|
67
|
|
|
if ($generateentitiesresult["errcode"] < 0) { |
|
68
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
69
|
|
|
return 1; |
|
70
|
|
|
} else { |
|
71
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
72
|
|
|
} */ |
|
73
|
|
|
return 0; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
private function getExportJsonCommand($bundlePath, $wbFile) |
|
77
|
|
|
{ |
|
78
|
|
|
$exportJson = $this->genhelper->getExportJsonFile(); |
|
|
|
|
|
|
79
|
|
|
$scriptGenerator = $this->genhelper->getScriptGenerator(); |
|
|
|
|
|
|
80
|
|
|
$destinationPathEscaped = str_replace('/', "\/", str_replace('\\', '/', $this->genhelper->getDestinationEntityYmlPath($bundlePath))); |
|
|
|
|
|
|
81
|
|
|
$bundlePathEscaped = str_replace('\\', '\\\\', str_replace('/', '\\', $bundlePath)); |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
$exportjsonfile = $this->genhelper->getJsonMwbGenerator(); |
|
84
|
|
|
|
|
85
|
|
|
$bundlejson = str_replace('[bundle]', str_replace('/', '', $bundlePathEscaped), $exportjsonfile); |
|
|
|
|
|
|
86
|
|
|
$exportjsonreplaced = str_replace('[dir]', $destinationPathEscaped, $bundlejson); |
|
87
|
|
|
file_put_contents($exportJson, $exportjsonreplaced); |
|
88
|
|
|
$sepchr = OsFunctions::getSeparator(); |
|
89
|
|
|
if (OsFunctions::isWindows()) { |
|
90
|
|
|
$command = 'cd ' . $this->apppaths->getRootPath() . $sepchr |
|
91
|
|
|
. $scriptGenerator . '.bat --export=doctrine2-yaml ' |
|
92
|
|
|
. ' --config=' . |
|
93
|
|
|
$exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped; |
|
94
|
|
|
} else { |
|
95
|
|
|
$phpPath = OsFunctions::getPHPExecutableFromPath(); |
|
96
|
|
|
$command = 'cd ' . $this->apppaths->getRootPath() . $sepchr |
|
97
|
|
|
. $phpPath . ' ' . $scriptGenerator . ' --export=doctrine2-yaml ' |
|
98
|
|
|
. ' --config=' . |
|
99
|
|
|
$exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $command; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
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.