1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fi\PannelloAmministrazioneBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
6
|
|
|
use Fi\OsBundle\DependencyInjection\OsFunctions; |
7
|
|
|
|
8
|
|
|
class PannelloamministrazioneCommands |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
private $container; |
12
|
|
|
private $apppaths; |
13
|
|
|
private $pammutils; |
14
|
|
|
|
15
|
2 |
|
public function __construct($container) |
16
|
|
|
{ |
17
|
2 |
|
$this->container = $container; |
18
|
2 |
|
$this->apppaths = $container->get("pannelloamministrazione.projectpath"); |
|
|
|
|
19
|
2 |
|
$this->pammutils = $container->get("pannelloamministrazione.utils"); |
|
|
|
|
20
|
2 |
|
} |
21
|
|
|
|
22
|
1 |
|
public function getVcs() |
23
|
|
|
{ |
24
|
1 |
|
$fs = new Filesystem(); |
25
|
|
|
|
26
|
1 |
|
$sepchr = OsFunctions::getSeparator(); |
|
|
|
|
27
|
1 |
|
$projectDir = $this->apppaths->getRootPath(); |
28
|
1 |
|
$vcscommand = ""; |
|
|
|
|
29
|
1 |
|
if ($fs->exists($projectDir . DIRECTORY_SEPARATOR . '.svn')) { |
30
|
|
|
$vcscommand = 'svn update'; |
31
|
|
|
} |
32
|
1 |
|
if ($fs->exists($projectDir . DIRECTORY_SEPARATOR . '.git')) { |
33
|
|
|
$vcscommand = 'git pull'; |
34
|
|
|
} |
35
|
1 |
|
if (!$vcscommand) { |
36
|
1 |
|
throw new \Exception("Vcs non trovato", 100); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
$command = 'cd ' . $projectDir . $sepchr . $vcscommand; |
39
|
|
|
return $this->pammutils->runCommand($command); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function generateBundle($bundleName) |
43
|
|
|
{ |
44
|
|
|
/* @var $fs \Symfony\Component\Filesystem\Filesystem */ |
45
|
1 |
|
$fs = new Filesystem(); |
46
|
|
|
|
47
|
1 |
|
$srcPath = $this->apppaths->getSrcPath(); |
48
|
|
|
|
49
|
1 |
|
$bundlePath = $this->apppaths->getSrcPath() . DIRECTORY_SEPARATOR . $bundleName; |
50
|
|
|
|
51
|
1 |
|
if ($fs->exists($bundlePath)) { |
52
|
1 |
|
return array('errcode' => -1, 'command' => 'generate:bundle', 'message' => "Il bundle esiste gia' in $bundlePath"); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
// if (!is_writable($bundlePath)) { |
|
|
|
|
55
|
|
|
// return array('errcode' => -1, 'command' => 'generate:bundle', 'message' => "$bundlePath non scrivibile"); |
56
|
|
|
// } |
57
|
|
|
|
58
|
|
|
$commandparms = array( |
59
|
1 |
|
'--namespace' => $bundleName, |
60
|
1 |
|
'--dir' => $srcPath . DIRECTORY_SEPARATOR, |
61
|
1 |
|
'--format' => 'yml', |
62
|
1 |
|
'--env' => $this->container->get('kernel')->getEnvironment(), |
63
|
1 |
|
'--no-interaction' => true, |
64
|
1 |
|
'--no-debug' => true, |
65
|
1 |
|
); |
66
|
1 |
|
$result = $this->pammutils->runSymfonyCommand('generate:bundle', $commandparms); |
|
|
|
|
67
|
1 |
|
$bundlePath = $srcPath . DIRECTORY_SEPARATOR . $bundleName; |
|
|
|
|
68
|
1 |
|
if ($fs->exists($bundlePath)) { |
69
|
|
|
$addmessage = 'Per abilitare il nuovo bundle nel kernel controllare che sia presente in app/AppKernel.php, ' |
70
|
1 |
|
. 'pulire la cache e aggiornare la pagina'; |
71
|
1 |
|
$ret = array('errcode' => 0, 'command' => 'generate:bundle', 'message' => $result["message"] . $addmessage); |
|
|
|
|
72
|
1 |
|
} else { |
73
|
|
|
$addmessage = "Non e' stato creato il bundle in $bundlePath"; |
|
|
|
|
74
|
|
|
$ret = array('errcode' => -1, 'command' => 'generate:bundle', 'message' => $result["message"] . $addmessage); |
|
|
|
|
75
|
|
|
} |
76
|
1 |
|
return $ret; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
public function generateEntity($wbFile, $bundlePath) |
80
|
|
|
{ |
81
|
1 |
|
$command = "pannelloamministrazione:generateymlentities"; |
|
|
|
|
82
|
1 |
|
$result = $this->pammutils->runSymfonyCommand($command, array('mwbfile' => $wbFile, 'bundlename' => $bundlePath)); |
|
|
|
|
83
|
|
|
|
84
|
1 |
|
if ($result["errcode"] != 0) { |
|
|
|
|
85
|
|
|
return array( |
86
|
|
|
'errcode' => -1, |
87
|
|
|
'message' => 'Errore nel comando: <i style="color: white;">' . |
88
|
|
|
$command . '</i><br/><i style="color: red;">' . |
89
|
|
|
str_replace("\n", '<br/>', $result["message"]) . |
|
|
|
|
90
|
|
|
'in caso di errori eseguire il comando symfony non da web: pannelloamministrazione:generateymlentities ' . |
91
|
|
|
$wbFile . ' ' . $bundlePath . '<br/></i>', |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return array( |
96
|
1 |
|
'errcode' => 0, |
97
|
|
|
'message' => '<pre>Eseguito comando: <i style = "color: white;">' . |
98
|
1 |
|
$command . '</i><br/>' . str_replace("\n", '<br/>', $result["message"]) . '</pre>',); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
public function generateEntityClass($bundlePath) |
102
|
|
|
{ |
103
|
1 |
|
$command = "pannelloamministrazione:generateentities"; |
|
|
|
|
104
|
1 |
|
$result = $this->pammutils->runSymfonyCommand($command, array('bundlename' => $bundlePath)); |
|
|
|
|
105
|
|
|
|
106
|
1 |
|
if ($result["errcode"] != 0) { |
|
|
|
|
107
|
|
|
return array( |
108
|
|
|
'errcode' => -1, |
109
|
|
|
'message' => 'Errore nel comando: <i style="color: white;">' . |
110
|
|
|
$command . '</i><br/><i style="color: red;">' . |
111
|
|
|
str_replace("\n", '<br/>', $result["message"]) . |
|
|
|
|
112
|
|
|
'in caso di errori eseguire il comando symfony non da web: pannelloamministrazione:generateentities ' . |
113
|
|
|
$bundlePath . '<br/>Opzione --schemaupdate oer aggiornare anche lo schema database</i>', |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return array( |
118
|
1 |
|
'errcode' => 0, |
119
|
|
|
'message' => '<pre>Eseguito comando: <i style = "color: white;">' . |
120
|
1 |
|
$command . '</i><br/>' . str_replace("\n", '<br/>', $result["message"]) . '</pre>',); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
1 |
|
public function generateFormCrud($bundlename, $entityform) |
124
|
|
|
{ |
125
|
|
|
/* @var $fs \Symfony\Component\Filesystem\Filesystem */ |
126
|
1 |
|
$resultchk = $this->checkFormCrud($bundlename, $entityform); |
127
|
|
|
|
128
|
1 |
|
if ($resultchk["errcode"] != 0) { |
|
|
|
|
129
|
|
|
return $resultchk; |
130
|
|
|
} |
131
|
1 |
|
$formcrudparms = array("bundlename" => $bundlename, "entityform" => $entityform); |
|
|
|
|
132
|
|
|
|
133
|
1 |
|
$retmsggenerateform = $this->pammutils->runSymfonyCommand('pannelloamministrazione:generateformcrud', $formcrudparms); |
134
|
|
|
|
135
|
|
|
$retmsg = array( |
136
|
1 |
|
'errcode' => $retmsggenerateform['errcode'], |
137
|
1 |
|
'command' => $retmsggenerateform['command'], |
138
|
1 |
|
'message' => $retmsggenerateform['message'], |
139
|
1 |
|
); |
140
|
|
|
|
141
|
1 |
|
return $retmsg; |
142
|
|
|
} |
143
|
|
|
|
144
|
1 |
|
public function checkFormCrud($bundlename, $entityform) |
145
|
|
|
{ |
146
|
|
|
/* @var $fs \Symfony\Component\Filesystem\Filesystem */ |
147
|
1 |
|
$fs = new Filesystem(); |
|
|
|
|
148
|
1 |
|
$srcPath = $this->apppaths->getSrcPath(); |
149
|
1 |
|
$appPath = $this->apppaths->getAppPath(); |
150
|
1 |
|
if (!is_writable($appPath)) { |
151
|
|
|
return array('errcode' => -1, 'message' => $appPath . ' non scrivibile'); |
152
|
|
|
} |
153
|
1 |
|
$formPath = $srcPath . DIRECTORY_SEPARATOR . $bundlename . DIRECTORY_SEPARATOR . |
154
|
1 |
|
'Form' . DIRECTORY_SEPARATOR . $entityform . 'Type.php'; |
155
|
|
|
|
156
|
1 |
|
if ($fs->exists($formPath)) { |
157
|
|
|
return array('errcode' => -1, 'message' => $formPath . ' esistente'); |
158
|
|
|
} |
159
|
|
|
|
160
|
1 |
|
$controllerPath = $srcPath . DIRECTORY_SEPARATOR . $bundlename . DIRECTORY_SEPARATOR . |
161
|
1 |
|
'Controller' . DIRECTORY_SEPARATOR . $entityform . 'Controller.php'; |
162
|
|
|
|
163
|
1 |
|
if ($fs->exists($controllerPath)) { |
164
|
|
|
return array('errcode' => -1, 'message' => $controllerPath . ' esistente'); |
165
|
|
|
} |
166
|
|
|
|
167
|
1 |
|
$viewPathSrc = $srcPath . DIRECTORY_SEPARATOR . $bundlename . DIRECTORY_SEPARATOR . |
168
|
1 |
|
'Resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $entityform; |
169
|
|
|
|
170
|
1 |
|
if ($fs->exists($viewPathSrc)) { |
171
|
|
|
return array('errcode' => -1, 'message' => $viewPathSrc . ' esistente'); |
172
|
|
|
} |
173
|
|
|
|
174
|
1 |
|
return array('errcode' => 0, 'message' => 'OK'); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function clearcache() |
178
|
|
|
{ |
179
|
|
|
$cmdoutput = ""; |
|
|
|
|
180
|
|
|
$envs = array("dev", "test", "prod"); |
|
|
|
|
181
|
|
|
foreach ($envs as $env) { |
182
|
|
|
$cmdoutput = $cmdoutput . $this->clearcacheEnv($env); |
183
|
|
|
} |
184
|
|
|
//$cmdoutput = $cmdoutput . $this->clearcacheEnv($this->container->get('kernel')->getEnvironment()); |
|
|
|
|
185
|
|
|
|
186
|
|
|
return $cmdoutput; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function clearcacheEnv($env) |
190
|
|
|
{ |
191
|
|
|
$ret = $this->pammutils->clearcache($env); |
192
|
|
|
|
193
|
|
|
return $ret["errmsg"]; |
|
|
|
|
194
|
|
|
} |
195
|
|
|
|
196
|
1 |
|
public function aggiornaSchemaDatabase() |
197
|
|
|
{ |
198
|
1 |
|
$result = $this->pammutils->runSymfonyCommand('doctrine:schema:update', array('--force' => true)); |
199
|
|
|
|
200
|
1 |
|
return $result; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
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.