1 | <?php |
||
9 | class PannelloamministrazioneCommands |
||
10 | { |
||
11 | |||
12 | private $container; |
||
13 | private $apppaths; |
||
14 | private $pammutils; |
||
15 | |||
16 | 1 | public function __construct($container) |
|
22 | |||
23 | 1 | public function getVcs() |
|
42 | |||
43 | public function generateBundle($bundleName) |
||
81 | |||
82 | public function generateEntity($wbFile, $bundlePath) |
||
103 | |||
104 | public function generateEntityClass($bundlePath) |
||
125 | |||
126 | public function generateFormCrud($bundlename, $entityform) |
||
127 | { |
||
128 | /* @var $fs \Symfony\Component\Filesystem\Filesystem */ |
||
129 | $fs = new Filesystem(); |
||
130 | $srcPath = $this->apppaths->getSrcPath(); |
||
131 | $appPath = $this->apppaths->getAppPath(); |
||
132 | if (!is_writable($appPath)) { |
||
133 | return array('errcode' => -1, 'message' => $appPath . ' non scrivibile'); |
||
134 | } |
||
135 | $formPath = $srcPath . DIRECTORY_SEPARATOR . $bundlename . DIRECTORY_SEPARATOR . |
||
136 | 'Form' . DIRECTORY_SEPARATOR . $entityform . 'Type.php'; |
||
137 | |||
138 | if ($fs->exists($formPath)) { |
||
139 | return array('errcode' => -1, 'message' => $formPath . ' esistente'); |
||
140 | } |
||
141 | |||
142 | $controllerPath = $srcPath . DIRECTORY_SEPARATOR . $bundlename . DIRECTORY_SEPARATOR . |
||
143 | 'Controller' . DIRECTORY_SEPARATOR . $entityform . 'Controller.php'; |
||
144 | |||
145 | if ($fs->exists($controllerPath)) { |
||
146 | return array('errcode' => -1, 'message' => $controllerPath . ' esistente'); |
||
147 | } |
||
148 | |||
149 | $viewPathSrc = $srcPath . DIRECTORY_SEPARATOR . $bundlename . DIRECTORY_SEPARATOR . |
||
150 | 'Resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $entityform; |
||
151 | |||
152 | if ($fs->exists($viewPathSrc)) { |
||
153 | return array('errcode' => -1, 'message' => $viewPathSrc . ' esistente'); |
||
154 | } |
||
155 | |||
156 | $crudparms = array( |
||
157 | 'entity' => str_replace('/', '', $bundlename) . ':' . $entityform, |
||
158 | '--route-prefix' => $entityform, |
||
159 | "--env" => $this->container->get('kernel')->getEnvironment(), |
||
160 | '--with-write' => true, |
||
161 | '--format' => 'yml', |
||
162 | '--overwrite' => false, |
||
163 | '--no-interaction' => true, |
||
164 | '--no-debug' => true); |
||
165 | |||
166 | $resultcrud = $this->pammutils->runSymfonyCommand('doctrine:generate:crud', $crudparms); |
||
167 | |||
168 | if ($resultcrud['errcode'] == 0) { |
||
169 | if ($fs->exists($viewPathSrc)) { |
||
170 | $fs->remove($viewPathSrc); |
||
171 | } |
||
172 | $formcrudparms = array("bundlename" => $bundlename, "entityform" => $entityform); |
||
173 | |||
174 | $retmsggenerateform = $this->pammutils->runSymfonyCommand('pannelloamministrazione:generateformcrud', $formcrudparms); |
||
175 | |||
176 | $appviews = $appPath . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'views'; |
||
177 | $this->cleanTemplatePath($appviews); |
||
178 | |||
179 | $resourcesviews = $appPath . DIRECTORY_SEPARATOR . 'Resources'; |
||
180 | $this->cleanTemplatePath($resourcesviews); |
||
181 | |||
182 | $retmsg = array( |
||
183 | 'errcode' => 0, |
||
184 | 'command' => $resultcrud['command'], |
||
185 | 'message' => $resultcrud['message'] . $retmsggenerateform['message'], |
||
186 | ); |
||
187 | } else { |
||
188 | $retmsg = array( |
||
189 | 'errcode' => $resultcrud['errcode'], |
||
190 | 'command' => $resultcrud['command'], |
||
191 | 'message' => $resultcrud['message'], |
||
192 | ); |
||
193 | } |
||
194 | |||
195 | return $retmsg; |
||
196 | } |
||
197 | |||
198 | private function cleanTemplatePath($path) |
||
199 | { |
||
200 | $fs = new Filesystem(); |
||
201 | $ret = 0; |
||
202 | if ($fs->exists($path)) { |
||
203 | $finder = new Finder(); |
||
204 | $ret = $finder->files()->in($path); |
||
205 | if (count($ret) == 0) { |
||
206 | $fs->remove($path); |
||
207 | } |
||
208 | } |
||
209 | } |
||
210 | |||
211 | public function clearcache() |
||
212 | { |
||
213 | $cmdoutput = ""; |
||
214 | $envs = array("dev", "test", "prod"); |
||
215 | foreach ($envs as $env) { |
||
216 | $cmdoutput = $cmdoutput . $this->clearcacheEnv($env); |
||
217 | } |
||
218 | //$cmdoutput = $cmdoutput . $this->clearcacheEnv($this->container->get('kernel')->getEnvironment()); |
||
219 | |||
220 | return $cmdoutput; |
||
221 | } |
||
222 | |||
223 | public function clearcacheEnv($env) |
||
229 | |||
230 | public function aggiornaSchemaDatabase() |
||
236 | } |
||
237 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.