1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\PannelloAmministrazioneBundle\Utils; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
7
|
|
|
use Cdf\BiCoreBundle\Utils\Api\ApiUtils; |
8
|
|
|
|
9
|
|
|
class Commands |
10
|
|
|
{ |
11
|
|
|
/* @var $apppaths ProjectPath */ |
|
|
|
|
12
|
|
|
|
13
|
|
|
private $apppaths; |
14
|
|
|
/* @var $pammutils Utility */ |
|
|
|
|
15
|
|
|
private $pammutils; |
16
|
|
|
|
17
|
1 |
|
public function __construct(ProjectPath $projectpath, Utility $pautils) |
18
|
|
|
{ |
19
|
1 |
|
$this->apppaths = $projectpath; |
20
|
1 |
|
$this->pammutils = $pautils; |
21
|
1 |
|
} |
22
|
|
|
|
23
|
|
|
// @codeCoverageIgnoreStart |
24
|
|
|
public function getVcs() |
25
|
|
|
{ |
26
|
|
|
$command = ""; |
27
|
|
|
$fs = new Filesystem(); |
28
|
|
|
|
29
|
|
|
$projectDir = $this->apppaths->getRootPath(); |
30
|
|
|
if ($fs->exists($projectDir . DIRECTORY_SEPARATOR . '.svn')) { |
31
|
|
|
$command = 'svn update'; |
32
|
|
|
} |
33
|
|
|
if ($fs->exists($projectDir . DIRECTORY_SEPARATOR . '.git')) { |
34
|
|
|
$command = 'git pull'; |
35
|
|
|
} |
36
|
|
|
if (!$command) { |
37
|
|
|
throw new Exception('Vcs non trovato', 100); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $this->pammutils->runCommand($command, $projectDir); |
41
|
|
|
} |
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 (0 != $result['errcode']) { |
50
|
|
|
return array( |
51
|
1 |
|
'errcode' => -1, |
52
|
1 |
|
'command' => $command, |
53
|
1 |
|
'message' => 'Errore nel comando:' . $command . ';' . $result['message'], |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return array( |
58
|
1 |
|
'errcode' => 0, |
59
|
1 |
|
'command' => $command, |
60
|
1 |
|
'message' => 'Eseguito comando:' . $command . ';' . $result['message'],); |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
public function generateFormCrud($entityform, $generatemplate, $isAPI = false) |
64
|
|
|
{ |
65
|
|
|
// check if some item already exist, and it interrupts the execution if any |
66
|
1 |
|
$pannelloamministrazioneentity = $entityform; |
67
|
|
|
/* @var $fs Filesystem */ |
68
|
1 |
|
if ($isAPI) { |
69
|
|
|
$entityform = substr($pannelloamministrazioneentity, strpos($pannelloamministrazioneentity, ".") + 1); |
70
|
|
|
$projectname = substr($pannelloamministrazioneentity, 0, strpos($pannelloamministrazioneentity, ".")); |
71
|
|
|
} else { |
72
|
1 |
|
$entityform = $pannelloamministrazioneentity; |
73
|
1 |
|
$projectname = ""; |
74
|
|
|
} |
75
|
1 |
|
$resultchk = $this->checkFormCrud($entityform, $projectname, $isAPI); |
76
|
|
|
|
77
|
1 |
|
if (0 !== $resultchk['errcode']) { |
78
|
|
|
return $resultchk; |
79
|
|
|
} |
80
|
1 |
|
$formcrudparms = array('entityform' => $entityform, '--generatemplate' => $generatemplate); |
81
|
1 |
|
if ($isAPI) { |
82
|
|
|
$formcrudparms['--isApi'] = true; |
83
|
|
|
$formcrudparms['--projectname'] = $projectname; |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
$retmsggenerateform = $this->pammutils->runSymfonyCommand('pannelloamministrazione:generateformcrud', $formcrudparms); |
87
|
|
|
|
88
|
|
|
$retmsg = array( |
89
|
1 |
|
'errcode' => $retmsggenerateform['errcode'], |
90
|
1 |
|
'command' => $retmsggenerateform['command'], |
91
|
1 |
|
'message' => $retmsggenerateform['message'], |
92
|
|
|
); |
93
|
|
|
|
94
|
1 |
|
return $retmsg; |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
public function checkFormCrud($entityform, string $projectname = "", bool $isAPI = false) |
98
|
|
|
{ |
99
|
|
|
/* @var $fs Filesystem */ |
100
|
1 |
|
$fs = new Filesystem(); |
101
|
1 |
|
$srcPath = $this->apppaths->getSrcPath(); |
102
|
1 |
|
$appPath = $srcPath; |
103
|
1 |
|
if (!is_writable($appPath)) { |
104
|
|
|
return array('errcode' => -1, 'message' => $appPath . ' non scrivibile'); |
105
|
|
|
} |
106
|
|
|
|
107
|
1 |
|
if (!$isAPI) { |
108
|
|
|
//Look for Entities... but they should already exist... |
109
|
1 |
|
$entityPath = $appPath . '/Entity' . DIRECTORY_SEPARATOR . $entityform . '.php'; |
110
|
1 |
|
if (!$fs->exists($entityPath)) { |
111
|
1 |
|
return array('errcode' => -1, 'message' => $entityPath . ' entity non trovata'); |
112
|
|
|
} |
113
|
|
|
} else { |
114
|
|
|
$apiUtil = new ApiUtils(); |
115
|
|
|
$modelClass = $apiUtil->getModelClass($projectname, $entityform); |
116
|
|
|
if (!class_exists($modelClass)) { |
117
|
|
|
return array('errcode' => -1, 'message' => $modelClass . ' model not found'); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
1 |
|
$formPath = $appPath . '/Form/' . $entityform . 'Type.php'; |
122
|
1 |
|
if ($fs->exists($formPath)) { |
123
|
|
|
return array('errcode' => -1, 'message' => $formPath . ' esistente'); |
124
|
|
|
} |
125
|
|
|
|
126
|
1 |
|
$controllerPath = $appPath . '/Controller' . DIRECTORY_SEPARATOR . $entityform . 'Controller.php'; |
127
|
|
|
|
128
|
1 |
|
if ($fs->exists($controllerPath)) { |
129
|
|
|
return array('errcode' => -1, 'message' => $controllerPath . ' esistente'); |
130
|
|
|
} |
131
|
|
|
|
132
|
1 |
|
$viewPathSrc = $this->apppaths->getTemplatePath() . DIRECTORY_SEPARATOR . $entityform; |
133
|
|
|
|
134
|
1 |
|
if ($fs->exists($viewPathSrc)) { |
135
|
|
|
return array('errcode' => -1, 'message' => $viewPathSrc . ' esistente'); |
136
|
|
|
} |
137
|
|
|
|
138
|
1 |
|
return array('errcode' => 0, 'message' => 'OK'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function clearcache() |
142
|
|
|
{ |
143
|
|
|
$cmdoutput = ''; |
144
|
|
|
//$envs = array('dev', 'test', 'prod'); |
145
|
|
|
$envs[] = getenv("APP_ENV"); |
|
|
|
|
146
|
|
|
foreach ($envs as $env) { |
147
|
|
|
$result = $this->pammutils->clearcache($env); |
148
|
|
|
$cmdoutput = $cmdoutput . $result['message']; |
149
|
|
|
if (0 !== $result['errcode']) { |
150
|
|
|
return $result; |
151
|
|
|
} |
152
|
|
|
$result['message'] = $cmdoutput; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
return $result; |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
1 |
|
public function aggiornaSchemaDatabase() |
159
|
|
|
{ |
160
|
1 |
|
$result = $this->pammutils->runSymfonyCommand('doctrine:schema:update', array('--force' => true)); |
161
|
|
|
|
162
|
1 |
|
return $result; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|