|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* InstallController 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 Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
18
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
19
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
20
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
22
|
|
|
use AppBundle\Entity\User; |
|
23
|
|
|
use AppBundle\Form\Type\UserType; |
|
24
|
|
|
use AppBundle\Entity\Company; |
|
25
|
|
|
use AppBundle\Form\Type\CompanyType; |
|
26
|
|
|
use AppBundle\Entity\Settings; |
|
27
|
|
|
use AppBundle\Form\Type\SettingsType; |
|
28
|
|
|
use AppBundle\Entity\Supplier; |
|
29
|
|
|
use AppBundle\Form\Type\SupplierType; |
|
30
|
|
|
use AppBundle\Entity\Article; |
|
31
|
|
|
use AppBundle\Form\Type\ArticleType; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* class InstallController |
|
35
|
|
|
* |
|
36
|
|
|
* @category Controller |
|
37
|
|
|
* |
|
38
|
|
|
* @Route("/install") |
|
39
|
|
|
*/ |
|
40
|
|
|
class InstallController extends Controller |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* Page d'accueil de l'installation. |
|
44
|
|
|
* |
|
45
|
|
|
* @Route("/", name="gs_install") |
|
46
|
|
|
* |
|
47
|
|
|
* @return Symfony\Component\HttpFoundation\Response Rendue de la page |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
public function indexAction() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->render('AppBundle:install:index.html.twig'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Etape 1 de l'installation. |
|
56
|
|
|
* Création des utilisateurs. |
|
57
|
|
|
* |
|
58
|
|
|
* @Route("/step1", name="gs_install_st1") |
|
59
|
|
|
* @Method({"POST","GET"}) |
|
60
|
|
|
* @Template("AppBundle:install:step1.html.twig") |
|
61
|
|
|
* |
|
62
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
|
|
|
|
|
63
|
|
|
* |
|
64
|
|
|
* @return Symfony\Component\HttpFoundation\Response Rendue de la page |
|
|
|
|
|
|
65
|
|
|
*/ |
|
66
|
|
|
public function step1Action(Request $request) |
|
67
|
|
|
{ |
|
68
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
69
|
|
|
$ctUser = count($em->getRepository('AppBundle:User')->findAll()); |
|
70
|
|
|
$user = new User(); |
|
71
|
|
|
$message = null; |
|
72
|
|
|
|
|
73
|
|
|
if ($ctUser > 0 && $request->getMethod() == 'GET') { |
|
74
|
|
|
$message = 'gestock.install.st1.yet_exist'; |
|
75
|
|
|
} |
|
76
|
|
|
$form = $this->createForm(new UserType(), $user, array( |
|
77
|
|
|
'action' => $this->generateUrl('gs_install_st1'), |
|
78
|
|
|
)); |
|
79
|
|
|
|
|
80
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
81
|
|
|
$user->setEnabled(true); |
|
82
|
|
|
$userManager = $this->get('fos_user.user_manager'); |
|
83
|
|
|
$userManager->updateUser($user); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return array( |
|
87
|
|
|
'message' => $message, |
|
88
|
|
|
'user' => $user, |
|
89
|
|
|
'form' => $form->createView() |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Etape 2 de l'installation. |
|
95
|
|
|
* Création de l'entreprise. |
|
96
|
|
|
* |
|
97
|
|
|
* @Route("/step2", name="gs_install_st2") |
|
98
|
|
|
* @Method({"POST","GET"}) |
|
99
|
|
|
* @Template("AppBundle:install:step2.html.twig") |
|
100
|
|
|
* |
|
101
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
|
|
|
|
|
102
|
|
|
* |
|
103
|
|
|
* @return Symfony\Component\HttpFoundation\Response Rendue de la page |
|
|
|
|
|
|
104
|
|
|
*/ |
|
105
|
|
View Code Duplication |
public function step2Action(Request $request) |
|
|
|
|
|
|
106
|
|
|
{ |
|
107
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
108
|
|
|
$ctCompany = count($em->getRepository('AppBundle:Company')->findAll()); |
|
109
|
|
|
$company = new Company(); |
|
110
|
|
|
$message = null; |
|
111
|
|
|
|
|
112
|
|
|
if ($ctCompany > 0 && $request->getMethod() == 'GET') { |
|
113
|
|
|
$message = 'gestock.install.st2.yet_exist'; |
|
114
|
|
|
} |
|
115
|
|
|
$form = $this->createForm(new CompanyType(), $company, array( |
|
116
|
|
|
'action' => $this->generateUrl('gs_install_st2') |
|
117
|
|
|
)); |
|
118
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
119
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
120
|
|
|
$em->persist($company); |
|
121
|
|
|
$em->flush(); |
|
122
|
|
|
|
|
123
|
|
|
return $this->redirect($this->generateUrl('gs_install_st2')); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return array('message' => $message, 'company' => $company, 'form' => $form->createView()); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Etape 3 de l'installation. |
|
131
|
|
|
* Création de la configuration. |
|
132
|
|
|
* |
|
133
|
|
|
* @Route("/step3", name="gs_install_st3") |
|
134
|
|
|
* @Method({"POST","GET"}) |
|
135
|
|
|
* @Template("AppBundle:install:step3.html.twig") |
|
136
|
|
|
* |
|
137
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
|
|
|
|
|
138
|
|
|
* |
|
139
|
|
|
* @return Symfony\Component\HttpFoundation\Response Rendue de la page |
|
|
|
|
|
|
140
|
|
|
*/ |
|
141
|
|
View Code Duplication |
public function step3Action(Request $request) |
|
|
|
|
|
|
142
|
|
|
{ |
|
143
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
144
|
|
|
$ctSettings = count($em->getRepository('AppBundle:Settings')->findAll()); |
|
145
|
|
|
$settings = new Settings(); |
|
146
|
|
|
$message = null; |
|
147
|
|
|
|
|
148
|
|
|
if ($ctSettings > 0 && $request->getMethod() == 'GET') { |
|
149
|
|
|
$message = 'gestock.install.st3.yet_exist'; |
|
150
|
|
|
} |
|
151
|
|
|
$form = $this->createForm(new SettingsType(), $settings, array( |
|
152
|
|
|
'action' => $this->generateUrl('gs_install_st3') |
|
153
|
|
|
)); |
|
154
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
155
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
156
|
|
|
$em->persist($settings); |
|
157
|
|
|
$em->flush(); |
|
158
|
|
|
|
|
159
|
|
|
return $this->redirect($this->generateUrl('gs_install_st3')); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return array('message' => $message, 'settings' => $settings, 'form' => $form->createView()); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Etape 4 de l'installation. |
|
167
|
|
|
* Cronfiguration de l'application. |
|
168
|
|
|
* |
|
169
|
|
|
* @Route("/step4", name="gs_install_st4") |
|
170
|
|
|
* @Method({"GET"}) |
|
171
|
|
|
* @Template("AppBundle:install:step4.html.twig") |
|
172
|
|
|
* |
|
173
|
|
|
* @return Symfony\Component\HttpFoundation\Response Rendue de la page |
|
|
|
|
|
|
174
|
|
|
*/ |
|
175
|
|
|
public function step4Action() |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->render('AppBundle:install:step4.html.twig'); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Etape 5 de l'installation. |
|
182
|
|
|
* Création des fournisseurs. |
|
183
|
|
|
* |
|
184
|
|
|
* @Route("/step5", name="gs_install_st5") |
|
185
|
|
|
* @Method({"POST","GET"}) |
|
186
|
|
|
* @Template("AppBundle:install:step5.html.twig") |
|
187
|
|
|
* |
|
188
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
|
|
|
|
|
189
|
|
|
* |
|
190
|
|
|
* @return Symfony\Component\HttpFoundation\Response Rendue de la page |
|
|
|
|
|
|
191
|
|
|
*/ |
|
192
|
|
View Code Duplication |
public function step5Action(Request $request) |
|
|
|
|
|
|
193
|
|
|
{ |
|
194
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
195
|
|
|
$ctSupplier = count($em->getRepository('AppBundle:Supplier')->findAll()); |
|
196
|
|
|
$suppliers = new Supplier(); |
|
197
|
|
|
$message = null; |
|
198
|
|
|
|
|
199
|
|
|
if ($ctSupplier > 0 && $request->getMethod() == 'GET') { |
|
200
|
|
|
$message = 'gestock.install.st5.yet_exist'; |
|
201
|
|
|
} |
|
202
|
|
|
$form = $this->createForm(new SupplierType(), $suppliers, array( |
|
203
|
|
|
'action' => $this->generateUrl('gs_install_st5') |
|
204
|
|
|
)); |
|
205
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
206
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
207
|
|
|
$em->persist($suppliers); |
|
208
|
|
|
$em->flush(); |
|
209
|
|
|
|
|
210
|
|
|
return $this->redirect($this->generateUrl('gs_install_st5')); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
return array('message' => $message, 'suppliers' => $suppliers, 'form' => $form->createView()); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Etape 6 de l'installation. |
|
218
|
|
|
* Création des articles. |
|
219
|
|
|
* |
|
220
|
|
|
* @Route("/step6", name="gs_install_st6") |
|
221
|
|
|
* @Method({"POST","GET"}) |
|
222
|
|
|
* @Template("AppBundle:install:step6.html.twig") |
|
223
|
|
|
* |
|
224
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request Requète du formulaire |
|
|
|
|
|
|
225
|
|
|
* |
|
226
|
|
|
* @return Symfony\Component\HttpFoundation\Response Rendue de la page |
|
|
|
|
|
|
227
|
|
|
*/ |
|
228
|
|
View Code Duplication |
public function step6Action(Request $request) |
|
|
|
|
|
|
229
|
|
|
{ |
|
230
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
231
|
|
|
$ctArticles = count($em->getRepository('AppBundle:Article')->findAll()); |
|
232
|
|
|
$articles = new Article(); |
|
233
|
|
|
$message = null; |
|
234
|
|
|
|
|
235
|
|
|
if ($ctArticles > 0 && $request->getMethod() == 'GET') { |
|
236
|
|
|
$message = 'gestock.install.st6.yet_exist'; |
|
237
|
|
|
} |
|
238
|
|
|
$form = $this->createForm(new ArticleType(), $articles, array( |
|
239
|
|
|
'action' => $this->generateUrl('gs_install_st6') |
|
240
|
|
|
)); |
|
241
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
242
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
243
|
|
|
$em->persist($articles); |
|
244
|
|
|
$em->flush(); |
|
245
|
|
|
|
|
246
|
|
|
return $this->redirect($this->generateUrl('gs_install_st6')); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
return array('message' => $message, 'articles' => $articles, 'form' => $form->createView()); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Etape 7 de l'installation. |
|
254
|
|
|
* Inventaire d'installation. |
|
255
|
|
|
* |
|
256
|
|
|
* @Route("/step7", name="gs_install_st7") |
|
257
|
|
|
* @Method({"GET"}) |
|
258
|
|
|
* @Template("AppBundle:install:step7.html.twig") |
|
259
|
|
|
* |
|
260
|
|
|
* @return Symfony\Component\HttpFoundation\Response Rendue de la page |
|
|
|
|
|
|
261
|
|
|
*/ |
|
262
|
|
|
public function step7Action() |
|
263
|
|
|
{ |
|
264
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
265
|
|
|
$settings = $em->getRepository('AppBundle:Settings')->find(1); |
|
266
|
|
|
$message = null; |
|
267
|
|
|
|
|
268
|
|
|
if ($settings->getFirstInventory() == null) { |
|
269
|
|
|
$message = 'gestock.install.st7.yet_exist'; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
return array('message' => $message); |
|
273
|
|
|
} |
|
274
|
|
|
} |
|
275
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.