1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\PannelloAmministrazioneBundle\Utils; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
6
|
|
|
use Fi\OsBundle\DependencyInjection\OsFunctions; |
7
|
|
|
use Cdf\PannelloAmministrazioneBundle\Utils\ProjectPath; |
8
|
|
|
use Cdf\PannelloAmministrazioneBundle\Utils\Utility; |
9
|
|
|
|
10
|
|
|
class Commands |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/* @var $apppaths \Cdf\PannelloAmministrazioneBundle\Utils\ProjectPath */ |
|
|
|
|
14
|
|
|
private $apppaths; |
15
|
|
|
/* @var $pammutils \Cdf\PannelloAmministrazioneBundle\Utils\Utility */ |
|
|
|
|
16
|
|
|
private $pammutils; |
17
|
|
|
|
18
|
1 |
|
public function __construct(ProjectPath $projectpath, Utility $pautils) |
19
|
|
|
{ |
20
|
1 |
|
$this->apppaths = $projectpath; |
|
|
|
|
21
|
1 |
|
$this->pammutils = $pautils; |
22
|
1 |
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
// @codeCoverageIgnoreStart |
26
|
|
|
public function getVcs() |
27
|
|
|
{ |
28
|
|
|
$fs = new Filesystem(); |
29
|
|
|
|
30
|
|
|
$sepchr = OsFunctions::getSeparator(); |
|
|
|
|
31
|
|
|
$projectDir = $this->apppaths->getRootPath(); |
32
|
|
|
$vcscommand = ""; |
|
|
|
|
33
|
|
|
if ($fs->exists($projectDir . DIRECTORY_SEPARATOR . '.svn')) { |
34
|
|
|
$vcscommand = 'svn update'; |
35
|
|
|
} |
36
|
|
|
if ($fs->exists($projectDir . DIRECTORY_SEPARATOR . '.git')) { |
37
|
|
|
$vcscommand = 'git pull'; |
38
|
|
|
} |
39
|
|
|
if (!$vcscommand) { |
40
|
|
|
throw new \Exception("Vcs non trovato", 100); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
$command = 'cd ' . $projectDir . $sepchr . $vcscommand; |
43
|
|
|
return $this->pammutils->runCommand($command); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// @codeCoverageIgnoreEnd |
47
|
1 |
|
public function generateEntity($wbFile) |
48
|
|
|
{ |
49
|
1 |
|
$command = "pannelloamministrazione:generateormentities"; |
|
|
|
|
50
|
1 |
|
$result = $this->pammutils->runSymfonyCommand($command, array('mwbfile' => $wbFile)); |
|
|
|
|
51
|
|
|
|
52
|
1 |
|
if ($result["errcode"] != 0) { |
|
|
|
|
53
|
|
|
return array( |
54
|
1 |
|
'errcode' => -1, |
55
|
1 |
|
'command' => $command, |
56
|
1 |
|
'message' => 'Errore nel comando:' . $command . ';' . $result["message"], |
|
|
|
|
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return array( |
61
|
1 |
|
'errcode' => 0, |
62
|
1 |
|
'command' => $command, |
63
|
1 |
|
'message' => 'Eseguito comando:' . $command . ';' . $result["message"]); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function generateFormCrud($entityform, $generatemplate) |
67
|
|
|
{ |
68
|
|
|
/* @var $fs \Symfony\Component\Filesystem\Filesystem */ |
69
|
1 |
|
$resultchk = $this->checkFormCrud($entityform); |
70
|
|
|
|
71
|
1 |
|
if ($resultchk["errcode"] !== 0) { |
|
|
|
|
72
|
1 |
|
return $resultchk; |
73
|
|
|
} |
74
|
1 |
|
$formcrudparms = array("entityform" => $entityform, "--generatemplate" => $generatemplate); |
|
|
|
|
75
|
|
|
|
76
|
1 |
|
$retmsggenerateform = $this->pammutils->runSymfonyCommand('pannelloamministrazione:generateformcrud', $formcrudparms); |
77
|
|
|
|
78
|
|
|
$retmsg = array( |
79
|
1 |
|
'errcode' => $retmsggenerateform['errcode'], |
80
|
1 |
|
'command' => $retmsggenerateform['command'], |
81
|
1 |
|
'message' => $retmsggenerateform['message'], |
82
|
|
|
); |
83
|
|
|
|
84
|
1 |
|
return $retmsg; |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
public function checkFormCrud($entityform) |
88
|
|
|
{ |
89
|
|
|
/* @var $fs \Symfony\Component\Filesystem\Filesystem */ |
90
|
1 |
|
$fs = new Filesystem(); |
|
|
|
|
91
|
1 |
|
$srcPath = $this->apppaths->getSrcPath(); |
92
|
1 |
|
$appPath = $srcPath; |
93
|
1 |
|
if (!is_writable($appPath)) { |
94
|
|
|
return array('errcode' => -1, 'message' => $appPath . ' non scrivibile'); |
95
|
|
|
} |
96
|
1 |
|
$formPath = $appPath . '/Form/' . $entityform . 'Type.php'; |
97
|
|
|
|
98
|
1 |
|
$entityPath = $appPath . '/Entity' . DIRECTORY_SEPARATOR . $entityform . '.php'; |
99
|
|
|
|
100
|
1 |
|
if (!$fs->exists($entityPath)) { |
101
|
|
|
return array('errcode' => -1, 'message' => $entityPath . ' entity non trovata'); |
102
|
|
|
} |
103
|
|
|
|
104
|
1 |
|
if ($fs->exists($formPath)) { |
105
|
1 |
|
return array('errcode' => -1, 'message' => $formPath . ' esistente'); |
106
|
|
|
} |
107
|
|
|
|
108
|
1 |
|
$controllerPath = $appPath . '/Controller' . DIRECTORY_SEPARATOR . $entityform . 'Controller.php'; |
109
|
|
|
|
110
|
1 |
|
if ($fs->exists($controllerPath)) { |
111
|
|
|
return array('errcode' => -1, 'message' => $controllerPath . ' esistente'); |
112
|
|
|
} |
113
|
|
|
|
114
|
1 |
|
$viewPathSrc = $this->apppaths->getTemplatePath() . DIRECTORY_SEPARATOR . $entityform; |
115
|
|
|
|
116
|
1 |
|
if ($fs->exists($viewPathSrc)) { |
117
|
|
|
return array('errcode' => -1, 'message' => $viewPathSrc . ' esistente'); |
118
|
|
|
} |
119
|
|
|
|
120
|
1 |
|
return array('errcode' => 0, 'message' => 'OK'); |
121
|
|
|
} |
122
|
|
|
|
123
|
1 |
|
public function clearcache() |
124
|
|
|
{ |
125
|
1 |
|
$cmdoutput = ""; |
|
|
|
|
126
|
1 |
|
$envs = array("dev", "test", "prod"); |
|
|
|
|
127
|
1 |
|
foreach ($envs as $env) { |
128
|
1 |
|
$result = $this->pammutils->clearcache($env); |
|
|
|
|
129
|
1 |
|
$cmdoutput = $cmdoutput . $result["message"]; |
|
|
|
|
130
|
1 |
|
if ($result["errcode"] !== 0) { |
|
|
|
|
131
|
|
|
return $result; |
132
|
|
|
} |
133
|
1 |
|
$result["message"] = $cmdoutput; |
|
|
|
|
134
|
|
|
} |
135
|
1 |
|
return $result; |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
1 |
|
public function aggiornaSchemaDatabase() |
139
|
|
|
{ |
140
|
1 |
|
$result = $this->pammutils->runSymfonyCommand('doctrine:schema:update', array('--force' => true)); |
141
|
|
|
|
142
|
1 |
|
return $result; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|