|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cdf\PannelloAmministrazioneBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
|
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 Cdf\PannelloAmministrazioneBundle\DependencyInjection\ProjectPath; |
|
11
|
|
|
use Cdf\PannelloAmministrazioneBundle\DependencyInjection\GeneratorHelper; |
|
12
|
|
|
use Cdf\PannelloAmministrazioneBundle\DependencyInjection\PannelloAmministrazioneUtils; |
|
13
|
|
|
|
|
14
|
|
|
class GenerateOrmEntitiesCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
protected $apppaths; |
|
18
|
|
|
protected $genhelper; |
|
19
|
|
|
protected $pammutils; |
|
20
|
|
|
|
|
21
|
1 |
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
|
|
$this |
|
24
|
1 |
|
->setName('pannelloamministrazione:generateormentities') |
|
25
|
1 |
|
->setDescription('Genera le entities partendo da un modello workbeanch mwb') |
|
26
|
1 |
|
->setHelp('Genera i file orm per le entities partendo da un modello workbeanch mwb, <br/>bi.mwb Fi/BiCoreBundle default<br/>') |
|
27
|
1 |
|
->addArgument('mwbfile', InputArgument::REQUIRED, 'Nome file mwb, bi.mwb') |
|
28
|
|
|
; |
|
29
|
1 |
|
} |
|
30
|
|
|
|
|
31
|
1 |
|
public function __construct(ProjectPath $projectpath, GeneratorHelper $genhelper, PannelloAmministrazioneUtils $pammutils) |
|
32
|
|
|
{ |
|
33
|
1 |
|
$this->apppaths = $projectpath; |
|
|
|
|
|
|
34
|
1 |
|
$this->genhelper = $genhelper; |
|
35
|
1 |
|
$this->pammutils = $pammutils; |
|
36
|
|
|
|
|
37
|
|
|
// you *must* call the parent constructor |
|
38
|
1 |
|
parent::__construct(); |
|
39
|
1 |
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
42
|
|
|
{ |
|
43
|
1 |
|
set_time_limit(0); |
|
44
|
|
|
|
|
45
|
1 |
|
$mwbfile = $input->getArgument('mwbfile'); |
|
46
|
|
|
|
|
47
|
1 |
|
$wbFile = $this->apppaths->getDocPath() . DIRECTORY_SEPARATOR . $mwbfile; |
|
|
|
|
|
|
48
|
1 |
|
$checkprerequisiti = $this->genhelper->checkprerequisiti($mwbfile, $output); |
|
49
|
|
|
|
|
50
|
1 |
|
if ($checkprerequisiti < 0) { |
|
51
|
|
|
return -1; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
$destinationPath = $this->genhelper->getDestinationEntityOrmPath(); |
|
55
|
|
|
|
|
56
|
1 |
|
$exportJson = $this->genhelper->getExportJsonFile(); |
|
|
|
|
|
|
57
|
1 |
|
$scriptGenerator = $this->genhelper->getScriptGenerator(); |
|
|
|
|
|
|
58
|
1 |
|
$destinationPathEscaped = $this->genhelper->getDestinationEntityOrmPath(); |
|
59
|
1 |
|
$exportjsonfile = $this->genhelper->getJsonMwbGenerator(); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
1 |
|
$exportjsonreplaced = str_replace('[dir]', $destinationPathEscaped, $exportjsonfile); |
|
62
|
|
|
|
|
63
|
1 |
|
file_put_contents($exportJson, $exportjsonreplaced); |
|
64
|
1 |
|
if (OsFunctions::isWindows()) { |
|
65
|
|
|
$workingdir = $this->apppaths->getRootPath(); |
|
|
|
|
|
|
66
|
|
|
$command = $scriptGenerator . '.bat'; |
|
|
|
|
|
|
67
|
|
|
$arguments[] = '--config=' . $exportJson; |
|
|
|
|
|
|
68
|
|
|
$arguments[] = $wbFile; |
|
69
|
|
|
$arguments[] = $destinationPathEscaped; |
|
70
|
|
|
} else { |
|
71
|
1 |
|
$workingdir = $this->apppaths->getRootPath(); |
|
|
|
|
|
|
72
|
1 |
|
$command = $scriptGenerator; |
|
|
|
|
|
|
73
|
1 |
|
$arguments[] = '--config=' . $exportJson; |
|
74
|
1 |
|
$arguments[] = $wbFile; |
|
75
|
1 |
|
$arguments[] = $destinationPathEscaped; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
$schemaupdateresult = $this->pammutils->runCommand($command, $arguments, $workingdir); |
|
79
|
1 |
|
if ($schemaupdateresult["errcode"] < 0) { |
|
|
|
|
|
|
80
|
|
|
$output->writeln($schemaupdateresult["message"]); |
|
|
|
|
|
|
81
|
|
|
return 1; |
|
82
|
|
|
} else { |
|
83
|
1 |
|
$output->writeln($schemaupdateresult["message"]); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
$this->genhelper->removeExportJsonFile(); |
|
87
|
1 |
|
$tablecheck = $this->genhelper->checktables($destinationPath, $wbFile, $output); |
|
88
|
|
|
|
|
89
|
1 |
|
if ($tablecheck < 0) { |
|
90
|
1 |
|
return 1; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
1 |
|
$output->writeln('<info>Entities yml create</info>'); |
|
94
|
1 |
|
return 0; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
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.