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