|
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
|
1 |
|
public function getVcs() |
|
22
|
|
|
{ |
|
23
|
1 |
|
$fs = new Filesystem(); |
|
24
|
|
|
|
|
25
|
1 |
|
$sepchr = OsFunctions::getSeparator(); |
|
|
|
|
|
|
26
|
1 |
|
$projectDir = $this->apppaths->getRootPath(); |
|
27
|
1 |
|
$vcscommand = ""; |
|
|
|
|
|
|
28
|
1 |
|
if ($fs->exists($projectDir . DIRECTORY_SEPARATOR . '.svn')) { |
|
29
|
|
|
$vcscommand = 'svn update'; |
|
30
|
|
|
} |
|
31
|
1 |
|
if ($fs->exists($projectDir . DIRECTORY_SEPARATOR . '.git')) { |
|
32
|
|
|
$vcscommand = 'git pull'; |
|
33
|
|
|
} |
|
34
|
1 |
|
if (!$vcscommand) { |
|
35
|
1 |
|
throw new \Exception("Vcs non trovato", 100); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
$command = 'cd ' . $projectDir . $sepchr . $vcscommand; |
|
38
|
|
|
return $this->pammutils->runCommand($command); |
|
39
|
|
|
} |
|
40
|
1 |
|
public function generateEntity($wbFile) |
|
41
|
|
|
{ |
|
42
|
1 |
|
$command = "pannelloamministrazione:generateymlentities"; |
|
|
|
|
|
|
43
|
1 |
|
$result = $this->pammutils->runSymfonyCommand($command, array('mwbfile' => $wbFile)); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
1 |
|
if ($result["errcode"] != 0) { |
|
|
|
|
|
|
46
|
|
|
return array( |
|
47
|
|
|
'errcode' => -1, |
|
48
|
|
|
'message' => 'Errore nel comando: <i style="color: white;">' . |
|
49
|
|
|
$command . '</i><br/><i style="color: red;">' . |
|
50
|
|
|
str_replace("\n", '<br/>', $result["message"]) . |
|
|
|
|
|
|
51
|
|
|
'in caso di errori eseguire il comando symfony non da web: pannelloamministrazione:generateymlentities ' . |
|
52
|
|
|
$wbFile . '<br/></i>', |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return array( |
|
57
|
1 |
|
'errcode' => 0, |
|
58
|
|
|
'message' => '<pre>Eseguito comando: <i style = "color: white;">' . |
|
59
|
1 |
|
$command . '</i><br/>' . str_replace("\n", '<br/>', $result["message"]) . '</pre>',); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
1 |
|
public function generateEntityClass() |
|
62
|
|
|
{ |
|
63
|
1 |
|
$command = "pannelloamministrazione:generateentities"; |
|
|
|
|
|
|
64
|
1 |
|
$result = $this->pammutils->runSymfonyCommand($command, array()); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
1 |
|
if ($result["errcode"] != 0) { |
|
|
|
|
|
|
67
|
|
|
return array( |
|
68
|
|
|
'errcode' => -1, |
|
69
|
|
|
'message' => 'Errore nel comando: <i style="color: white;">' . |
|
70
|
|
|
$command . '</i><br/><i style="color: red;">' . |
|
71
|
|
|
str_replace("\n", '<br/>', $result["message"]) . |
|
|
|
|
|
|
72
|
|
|
'in caso di errori eseguire il comando symfony non da web: pannelloamministrazione:generateentities ' . |
|
73
|
|
|
'<br/>Opzione --schemaupdate oer aggiornare anche lo schema database</i>', |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return array( |
|
78
|
1 |
|
'errcode' => 0, |
|
79
|
|
|
'message' => '<pre>Eseguito comando: <i style = "color: white;">' . |
|
80
|
1 |
|
$command . '</i><br/>' . str_replace("\n", '<br/>', $result["message"]) . '</pre>',); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
1 |
|
public function generateFormCrud($entityform) |
|
83
|
|
|
{ |
|
84
|
|
|
/* @var $fs \Symfony\Component\Filesystem\Filesystem */ |
|
85
|
1 |
|
$resultchk = $this->checkFormCrud($entityform); |
|
86
|
|
|
|
|
87
|
1 |
|
if ($resultchk["errcode"] != 0) { |
|
|
|
|
|
|
88
|
|
|
return $resultchk; |
|
89
|
|
|
} |
|
90
|
1 |
|
$formcrudparms = array("entityform" => $entityform); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
1 |
|
$retmsggenerateform = $this->pammutils->runSymfonyCommand('pannelloamministrazione:generateformcrud', $formcrudparms); |
|
93
|
|
|
|
|
94
|
|
|
$retmsg = array( |
|
95
|
1 |
|
'errcode' => $retmsggenerateform['errcode'], |
|
96
|
1 |
|
'command' => $retmsggenerateform['command'], |
|
97
|
1 |
|
'message' => $retmsggenerateform['message'], |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
1 |
|
return $retmsg; |
|
101
|
|
|
} |
|
102
|
1 |
|
public function checkFormCrud($entityform) |
|
103
|
|
|
{ |
|
104
|
|
|
/* @var $fs \Symfony\Component\Filesystem\Filesystem */ |
|
105
|
1 |
|
$fs = new Filesystem(); |
|
|
|
|
|
|
106
|
1 |
|
$srcPath = $this->apppaths->getSrcPath(); |
|
107
|
1 |
|
$appPath = $srcPath; |
|
108
|
1 |
|
if (!is_writable($appPath)) { |
|
109
|
|
|
return array('errcode' => -1, 'message' => $appPath . ' non scrivibile'); |
|
110
|
|
|
} |
|
111
|
1 |
|
$formPath = $appPath . '/Form/' . $entityform . 'Type.php'; |
|
112
|
|
|
|
|
113
|
1 |
|
if ($fs->exists($formPath)) { |
|
114
|
|
|
return array('errcode' => -1, 'message' => $formPath . ' esistente'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
1 |
|
$controllerPath = $appPath . '/Controller' . DIRECTORY_SEPARATOR . $entityform . 'Controller.php'; |
|
118
|
|
|
|
|
119
|
1 |
|
if ($fs->exists($controllerPath)) { |
|
120
|
|
|
return array('errcode' => -1, 'message' => $controllerPath . ' esistente'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
1 |
|
$viewPathSrc = $appPath . '/Resources/views/' . $entityform; |
|
124
|
|
|
|
|
125
|
1 |
|
if ($fs->exists($viewPathSrc)) { |
|
126
|
|
|
return array('errcode' => -1, 'message' => $viewPathSrc . ' esistente'); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
1 |
|
return array('errcode' => 0, 'message' => 'OK'); |
|
130
|
|
|
} |
|
131
|
|
|
public function clearcache() |
|
132
|
|
|
{ |
|
133
|
|
|
$cmdoutput = ""; |
|
|
|
|
|
|
134
|
|
|
$envs = array("dev", "test", "prod"); |
|
|
|
|
|
|
135
|
|
|
foreach ($envs as $env) { |
|
136
|
|
|
$cmdoutput = $cmdoutput . $this->clearcacheEnv($env); |
|
137
|
|
|
} |
|
138
|
|
|
//$cmdoutput = $cmdoutput . $this->clearcacheEnv($this->container->get('kernel')->getEnvironment()); |
|
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
return $cmdoutput; |
|
141
|
|
|
} |
|
142
|
|
|
public function clearcacheEnv($env) |
|
143
|
|
|
{ |
|
144
|
|
|
$ret = $this->pammutils->clearcache($env); |
|
145
|
|
|
|
|
146
|
|
|
return $ret["errmsg"]; |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
1 |
|
public function aggiornaSchemaDatabase() |
|
149
|
|
|
{ |
|
150
|
1 |
|
$result = $this->pammutils->runSymfonyCommand('doctrine:schema:update', array('--force' => true)); |
|
151
|
|
|
|
|
152
|
1 |
|
return $result; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
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.