|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AbstractInstallController controller d'installation de l'application GLSR. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Quétier Laurent <[email protected]> |
|
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
|
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
10
|
|
|
* |
|
11
|
|
|
* @version since 1.0.0 |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace AppBundle\Controller\Install; |
|
16
|
|
|
|
|
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* AbstractInstall controller |
|
22
|
|
|
* |
|
23
|
|
|
* @category Controller |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class AbstractInstallController extends Controller |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Etape X de l'installation. |
|
29
|
|
|
* Fonction adaptable aux différentes phases de l'installation. |
|
30
|
|
|
* |
|
31
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
32
|
|
|
* |
|
33
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse| |
|
34
|
|
|
* array<string,string|null|Settings|\Symfony\Component\Form\FormView> Rendue de la page |
|
35
|
|
|
*/ |
|
36
|
|
|
public function stepAction(Request $request, $entity, $entityPath, $typePath, $number) |
|
37
|
|
|
{ |
|
38
|
|
|
$etm = $this->getDoctrine()->getManager(); |
|
39
|
|
|
${'ct'.$entity} = count($etm->getRepository('AppBundle:'.$entity)->findAll()); |
|
40
|
|
|
${strtolower($entity)} = $etm->getClassMetadata($entityPath)->newInstance(); |
|
41
|
|
|
$message = null; |
|
42
|
|
|
|
|
43
|
|
|
// if (${'ct'.$entity} > 0 && $request->getMethod() == 'GET' && is_int($number)) { |
|
|
|
|
|
|
44
|
|
|
// $message = 'gestock.install.st'.$number.'.yet_exist'; |
|
45
|
|
|
// } |
|
46
|
|
|
$form = $this->createForm(new $typePath(), ${strtolower($entity)}, array( |
|
47
|
|
|
'action' => $this->generateUrl('gs_install_st'.$number) |
|
48
|
|
|
)); |
|
49
|
|
|
if (is_int($number)) { |
|
50
|
|
|
$return = array('message' => $message, 'form' => $form->createView(),); |
|
51
|
|
|
} else { |
|
52
|
|
|
$return = array( |
|
53
|
|
|
strtolower($entity) => ${strtolower($entity)}, |
|
54
|
|
|
'form' => $form->createView(), |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
59
|
|
|
$etm = $this->getDoctrine()->getManager(); |
|
60
|
|
|
$etm->persist(${strtolower($entity)}); |
|
61
|
|
|
$etm->flush(); |
|
62
|
|
|
|
|
63
|
|
|
if ($form->get('save')->isSubmitted()) { |
|
64
|
|
|
$return = $this->redirect($this->generateUrl('gs_install_st4')); |
|
65
|
|
|
} elseif ($form->get('addmore')->isSubmitted()) { |
|
66
|
|
|
$return = $this->redirect($this->generateUrl('gs_install_st'.$number)); |
|
67
|
|
|
} else { |
|
68
|
|
|
$return = $this->redirect($this->generateUrl('gs_install_st'.$number)); |
|
69
|
|
|
} |
|
70
|
|
|
$this->addFlash('info', 'gestock.install.st'.$number.'.flash'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $return; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.