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