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