|
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
|
|
|
use Fi\PannelloAmministrazioneBundle\DependencyInjection\ProjectPath; |
|
11
|
|
|
use Fi\PannelloAmministrazioneBundle\DependencyInjection\PannelloAmministrazioneUtils; |
|
12
|
|
|
use Fi\PannelloAmministrazioneBundle\DependencyInjection\GeneratorHelper; |
|
13
|
|
|
|
|
14
|
|
|
class GenerateymlentitiesCommand extends ContainerAwareCommand |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
protected $apppaths; |
|
18
|
|
|
protected $genhelper; |
|
19
|
|
|
protected $pammutils; |
|
20
|
|
|
|
|
21
|
1 |
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
|
|
$this |
|
24
|
1 |
|
->setName('pannelloamministrazione:generateymlentities') |
|
25
|
1 |
|
->setDescription('Genera le entities partendo da un modello workbeanch mwb') |
|
26
|
1 |
|
->setHelp('Genera i ifle yml per le entities partendo da un modello workbeanch mwb, <br/>fifree.mwb Fi/CoreBundle default<br/>') |
|
27
|
1 |
|
->addArgument('mwbfile', InputArgument::REQUIRED, 'Nome file mwb, fifree.mwb') |
|
28
|
1 |
|
->addArgument('bundlename', InputArgument::REQUIRED, 'Nome del bundle, Fi/CoreBundle') |
|
29
|
1 |
|
->addArgument('em', InputArgument::OPTIONAL, 'Entity manager, default = default'); |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
33
|
|
|
{ |
|
34
|
|
|
set_time_limit(0); |
|
35
|
|
|
$this->apppaths = new ProjectPath($this->getContainer()); |
|
36
|
|
|
$this->genhelper = new GeneratorHelper($this->getContainer()); |
|
37
|
|
|
$this->pammutils = new PannelloAmministrazioneUtils($this->getContainer()); |
|
38
|
|
|
|
|
39
|
|
|
$bundlename = $input->getArgument('bundlename'); |
|
40
|
|
|
$mwbfile = $input->getArgument('mwbfile'); |
|
41
|
|
|
|
|
42
|
|
|
if (!$input->getArgument('em')) { |
|
43
|
|
|
$emdest = 'default'; |
|
|
|
|
|
|
44
|
|
|
} else { |
|
45
|
|
|
$emdest = $input->getArgument('em'); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$wbFile = $this->apppaths->getDocPath() . DIRECTORY_SEPARATOR . $mwbfile; |
|
49
|
|
|
$checkprerequisiti = $this->genhelper->checkprerequisiti($bundlename, $mwbfile, $output); |
|
50
|
|
|
|
|
51
|
|
|
if ($checkprerequisiti < 0) { |
|
52
|
|
|
return -1; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$destinationPath = $this->genhelper->getDestinationEntityYmlPath($bundlename); |
|
56
|
|
|
|
|
57
|
|
|
$command = $this->getExportJsonCommand($bundlename, $wbFile); |
|
58
|
|
|
|
|
59
|
|
|
$schemaupdateresult = PannelloAmministrazioneUtils::runCommand($command); |
|
60
|
|
|
if ($schemaupdateresult["errcode"] < 0) { |
|
61
|
|
|
$output->writeln($schemaupdateresult["errmsg"]); |
|
62
|
|
|
return 1; |
|
63
|
|
|
} else { |
|
64
|
|
|
$output->writeln($schemaupdateresult["errmsg"]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$this->genhelper->removeExportJsonFile(); |
|
68
|
|
|
|
|
69
|
|
|
$tablecheck = $this->genhelper->checktables($destinationPath, $wbFile, $output); |
|
70
|
|
|
|
|
71
|
|
|
if ($tablecheck < 0) { |
|
72
|
|
|
return 1; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$output->writeln('<info>Entities yml create</info>'); |
|
76
|
|
|
/* $generateentitiesresult = $this->pammutils->clearCache(); |
|
|
|
|
|
|
77
|
|
|
if ($generateentitiesresult["errcode"] < 0) { |
|
78
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
79
|
|
|
return 1; |
|
80
|
|
|
} else { |
|
81
|
|
|
$output->writeln($generateentitiesresult["errmsg"]); |
|
82
|
|
|
} */ |
|
83
|
|
|
return 0; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
private function getExportJsonCommand($bundlePath, $wbFile) |
|
87
|
|
|
{ |
|
88
|
|
|
$exportJson = $this->genhelper->getExportJsonFile(); |
|
89
|
|
|
$scriptGenerator = $this->genhelper->getScriptGenerator(); |
|
90
|
|
|
$destinationPathEscaped = str_replace('/', "\/", str_replace('\\', '/', $this->genhelper->getDestinationEntityYmlPath($bundlePath))); |
|
91
|
|
|
$bundlePathEscaped = str_replace('\\', '\\\\', str_replace('/', '\\', $bundlePath)); |
|
92
|
|
|
|
|
93
|
|
|
$exportjsonfile = GeneratorHelper::getJsonMwbGenerator(); |
|
94
|
|
|
|
|
95
|
|
|
$bundlejson = str_replace('[bundle]', str_replace('/', '', $bundlePathEscaped), $exportjsonfile); |
|
96
|
|
|
$exportjsonreplaced = str_replace('[dir]', $destinationPathEscaped, $bundlejson); |
|
97
|
|
|
file_put_contents($exportJson, $exportjsonreplaced); |
|
98
|
|
|
$sepchr = OsFunctions::getSeparator(); |
|
99
|
|
|
if (OsFunctions::isWindows()) { |
|
100
|
|
|
$command = 'cd ' . $this->apppaths->getRootPath() . $sepchr |
|
101
|
|
|
. $scriptGenerator . '.bat --export=doctrine2-yaml ' |
|
102
|
|
|
. ' --config=' . |
|
103
|
|
|
$exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped; |
|
104
|
|
|
} else { |
|
105
|
|
|
$phpPath = OsFunctions::getPHPExecutableFromPath(); |
|
106
|
|
|
$command = 'cd ' . $this->apppaths->getRootPath() . $sepchr |
|
107
|
|
|
. $phpPath . ' ' . $scriptGenerator . ' --export=doctrine2-yaml ' |
|
108
|
|
|
. ' --config=' . |
|
109
|
|
|
$exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $command; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.