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