Completed
Push — master ( e262bd...cc6d72 )
by Andrea
08:21
created

Fifree2installCommand::insertDefaultFfTables()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 114
Code Lines 97

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 98
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 114
ccs 98
cts 98
cp 1
rs 8.2857
cc 1
eloc 97
nc 1
nop 1
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Fi\CoreBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Input\ArrayInput;
11
12
class Fifree2installCommand extends ContainerAwareCommand
13
{
14
15 2
    protected function configure()
16
    {
17
        $this
18 2
                ->setName('fifree2:install')
19 2
                ->setDescription('Installazione ambiente fifree')
20 2
                ->setHelp('Crea il database, un utente amministratore e i dati di default')
21 2
                ->addArgument('admin', InputArgument::REQUIRED, 'Username per amministratore')
22 2
                ->addArgument('adminpass', InputArgument::REQUIRED, 'Password per amministratore')
23 2
                ->addArgument('adminemail', InputArgument::REQUIRED, 'Email per amministratore')
24
        ;
25 2
    }
26
27 1
    protected function execute(InputInterface $input, OutputInterface $output)
28
    {
29 1
        $admin = $input->getArgument('admin');
30 1
        $adminpass = $input->getArgument('adminpass');
31 1
        $adminemail = $input->getArgument('adminemail');
32
33 1
        if (!$admin) {
34
            echo "Inserire il nome utente dell'amministratore";
35
36
            return 1;
37
        }
38 1
        if (!$adminpass) {
39
            echo "Inserire la password per dell'amministratore";
40
41
            return 1;
42
        }
43 1
        if (!$adminemail) {
44
            echo "Inserire la mail dell'amministratore";
45
46
            return 1;
47
        }
48
49 1
        $commanddb = $this->getApplication()->find('fifree2:createdatabase');
50 1
        $argumentsdb = array('command' => 'fifree2:createdatabase');
51 1
        $inputc = new ArrayInput($argumentsdb);
52 1
        $commanddb->run($inputc, $output);
53
54 1
        $userManipulator = $this->getContainer()->get('fifree.fos_user.util.user_manipulator');
55
56 1
        $adminPassword = $adminpass;
57 1
        $adminUsername = $admin;
58 1
        $adminEmail = $adminemail;
59 1
        $isActive = true;
60 1
        $isSuperAdmin = true;
61 1
        $userManipulator->create($adminUsername, $adminPassword, $adminEmail, $isActive, $isSuperAdmin);
62
63 1
        $this->loadDefaultValues($admin);
64 1
    }
65
66 1
    private function loadDefaultValues($admin)
67
    {
68 1
        $em = $this->getContainer()->get('doctrine')->getManager();
69
70 1
        $ruolos = new \Fi\CoreBundle\Entity\ruoli();
71 1
        $ruolos->setRuolo('Super Admin');
72 1
        $ruolos->setPaginainiziale('/adminpanel');
73 1
        $ruolos->setIsSuperadmin(true);
74 1
        $ruolos->setIsAdmin(true);
75 1
        $ruolos->setIsUser(false);
76 1
        $em->persist($ruolos);
77 1
        $ruoloa = new \Fi\CoreBundle\Entity\ruoli();
78 1
        $ruoloa->setRuolo('Amministratore');
79 1
        $ruoloa->setPaginainiziale('/adminpanel');
80 1
        $ruoloa->setIsSuperadmin(false);
81 1
        $ruoloa->setIsAdmin(true);
82 1
        $ruoloa->setIsUser(false);
83 1
        $em->persist($ruoloa);
84 1
        $ruolou = new \Fi\CoreBundle\Entity\ruoli();
85 1
        $ruolou->setRuolo('Utente');
86 1
        $ruolou->setPaginainiziale('/ffprincipale');
87 1
        $ruolou->setIsSuperadmin(false);
88 1
        $ruolou->setIsAdmin(false);
89 1
        $ruolou->setIsUser(true);
90 1
        $em->persist($ruolou);
91 1
        $em->flush();
92
93
        //Si tiene in memoria l'id del super admin
94 1
        $ruolo = $em->getRepository('FiCoreBundle:Ruoli')->findOneBy(array('is_superadmin' => true)); //SuperAdmin
95 1
        $operatore = $em->getRepository('FiCoreBundle:Operatori')->findOneByUsername($admin);
96 1
        $operatore->setRuoli($ruolo);
97 1
        $em->persist($operatore);
98 1
        $em->flush();
99
100 1
        $this->insertDefaultMenu($em);
101
102 1
        $this->insertDefaultFfTables($em);
103
104 1
        $permessimnuapp = new \Fi\CoreBundle\Entity\permessi();
105 1
        $permessimnuapp->setRuoli($ruolo);
106 1
        $permessimnuapp->setModulo('MenuApplicazione');
107 1
        $permessimnuapp->setCrud('crud');
108 1
        $em->persist($permessimnuapp);
109
110 1
        $permessiopt = new \Fi\CoreBundle\Entity\permessi();
111 1
        $permessiopt->setRuoli($ruolo);
112 1
        $permessiopt->setModulo('OpzioniTabella');
113 1
        $permessiopt->setCrud('crud');
114 1
        $em->persist($permessiopt);
115
116 1
        $permessitbl = new \Fi\CoreBundle\Entity\permessi();
117 1
        $permessitbl->setRuoli($ruolo);
118 1
        $permessitbl->setModulo('Tabelle');
119 1
        $permessitbl->setCrud('crud');
120 1
        $em->persist($permessitbl);
121
122 1
        $permessi = new \Fi\CoreBundle\Entity\permessi();
123 1
        $permessi->setRuoli($ruolo);
124 1
        $permessi->setModulo('Permessi');
125 1
        $permessi->setCrud('crud');
126 1
        $em->persist($permessi);
127
128 1
        $permessiope = new \Fi\CoreBundle\Entity\permessi();
129 1
        $permessiope->setRuoli($ruolo);
130 1
        $permessiope->setModulo('Operatori');
131 1
        $permessiope->setCrud('cru');
132 1
        $em->persist($permessiope);
133
134 1
        $permessiruo = new \Fi\CoreBundle\Entity\permessi();
135 1
        $permessiruo->setRuoli($ruolo);
136 1
        $permessiruo->setModulo('Ruoli');
137 1
        $permessiruo->setCrud('crud');
138 1
        $em->persist($permessiruo);
139
140 1
        $permessifp = new \Fi\CoreBundle\Entity\permessi();
141 1
        $permessifp->setRuoli($ruolo);
142 1
        $permessifp->setModulo('Ffprincipale');
143 1
        $permessifp->setCrud('crud');
144 1
        $em->persist($permessifp);
145
146 1
        $permessifs = new \Fi\CoreBundle\Entity\permessi();
147 1
        $permessifs->setRuoli($ruolo);
148 1
        $permessifs->setModulo('Ffsecondaria');
149 1
        $permessifs->setCrud('crud');
150 1
        $em->persist($permessifs);
151
152 1
        $tabelle = new \Fi\CoreBundle\Entity\tabelle();
153 1
        $tabelle->setNometabella('*');
154 1
        $em->persist($tabelle);
155
156 1
        $tabelleUno = new \Fi\CoreBundle\Entity\tabelle();
157 1
        $tabelleUno->setNometabella('Ffsecondaria');
158 1
        $tabelleUno->setNomecampo('ffprincipale');
159 1
        $tabelleUno->setMostraindex(true);
160 1
        $tabelleUno->setMostrastampa(true);
161 1
        $tabelleUno->setRegistrastorico(true);
162 1
        $em->persist($tabelleUno);
163
164 1
        $tabelleDue = new \Fi\CoreBundle\Entity\tabelle();
165 1
        $tabelleDue->setNometabella('Ffsecondaria');
166 1
        $tabelleDue->setNomecampo('descsec');
167 1
        $tabelleDue->setMostraindex(true);
168 1
        $tabelleDue->setMostrastampa(true);
169 1
        $tabelleDue->setRegistrastorico(true);
170 1
        $em->persist($tabelleDue);
171
172
173 1
        $opzionitabelle = new \Fi\CoreBundle\Entity\opzioniTabella();
174 1
        $opzionitabelle->setTabelle($tabelle);
175 1
        $opzionitabelle->setParametro('titolo');
176 1
        $opzionitabelle->setValore('Elenco dati per %tabella%');
177 1
        $em->persist($opzionitabelle);
178
179 1
        $opzionitabelleag = new \Fi\CoreBundle\Entity\opzioniTabella();
180 1
        $opzionitabelleag->setTabelle($tabelle);
181 1
        $opzionitabelleag->setDescrizione('Altezza Griglia');
182 1
        $opzionitabelleag->setParametro('altezzagriglia');
183 1
        $opzionitabelleag->setValore(400);
184 1
        $em->persist($opzionitabelleag);
185
186 1
        $em->flush();
187 1
    }
188
189 1
    private function insertDefaultMenu($em)
190
    {
191 1
        $menutabelle = new \Fi\CoreBundle\Entity\menuApplicazione();
192 1
        $menutabelle->setNome('Tabelle');
193 1
        $menutabelle->setAttivo(true);
194 1
        $menutabelle->setOrdine(10);
195 1
        $em->persist($menutabelle);
196 1
        $em->flush();
197
198 1
        $menufp = new \Fi\CoreBundle\Entity\menuApplicazione();
199 1
        $menufp->setPadre($menutabelle->getId());
200 1
        $menufp->setNome('FFprincipale');
201 1
        $menufp->setPercorso('Ffprincipale');
202 1
        $menufp->setAttivo(true);
203 1
        $menufp->setOrdine(10);
204 1
        $em->persist($menufp);
205
206 1
        $menufs = new \Fi\CoreBundle\Entity\menuApplicazione();
207 1
        $menufs->setPadre($menutabelle->getId());
208 1
        $menufs->setNome('FFsecondaria');
209 1
        $menufs->setPercorso('Ffsecondaria');
210 1
        $menufs->setAttivo(true);
211 1
        $menufs->setOrdine(10);
212 1
        $em->persist($menufs);
213 1
        $em->flush();
214
215 1
        $menuAmministrazione = new \Fi\CoreBundle\Entity\menuApplicazione();
216 1
        $menuAmministrazione->setNome('Amministrazione');
217 1
        $menuAmministrazione->setAttivo(true);
218 1
        $menuAmministrazione->setOrdine(20);
219 1
        $em->persist($menuAmministrazione);
220 1
        $em->flush();
221
222 1
        $menuop = new \Fi\CoreBundle\Entity\menuApplicazione();
223 1
        $menuop->setPadre($menuAmministrazione->getId());
224 1
        $menuop->setNome('Operatori');
225 1
        $menuop->setPercorso('Operatori');
226 1
        $menuop->setAttivo(true);
227 1
        $menuop->setOrdine(10);
228 1
        $em->persist($menuop);
229
230 1
        $menuruo = new \Fi\CoreBundle\Entity\menuApplicazione();
231 1
        $menuruo->setPadre($menuAmministrazione->getId());
232 1
        $menuruo->setNome('Ruoli');
233 1
        $menuruo->setPercorso('Ruoli');
234 1
        $menuruo->setAttivo(true);
235 1
        $menuruo->setOrdine(20);
236 1
        $em->persist($menuruo);
237
238 1
        $menuapp = new \Fi\CoreBundle\Entity\menuApplicazione();
239 1
        $menuapp->setPadre($menuAmministrazione->getId());
240 1
        $menuapp->setNome('Permessi');
241 1
        $menuapp->setPercorso('Permessi');
242 1
        $menuapp->setAttivo(true);
243 1
        $menuapp->setOrdine(30);
244 1
        $em->persist($menuapp);
245
246 1
        $menutbl = new \Fi\CoreBundle\Entity\menuApplicazione();
247 1
        $menutbl->setPadre($menuAmministrazione->getId());
248 1
        $menutbl->setNome('Gestione tabelle');
249 1
        $menutbl->setPercorso('');
250 1
        $menutbl->setAttivo(true);
251 1
        $menutbl->setOrdine(40);
252 1
        $em->persist($menutbl);
253 1
        $em->flush();
254
255 1
        $menutbs = new \Fi\CoreBundle\Entity\menuApplicazione();
256 1
        $menutbs->setPadre($menutbl->getId());
257 1
        $menutbs->setNome('Tabelle');
258 1
        $menutbs->setPercorso('Tabelle');
259 1
        $menutbs->setAttivo(true);
260 1
        $menutbs->setOrdine(10);
261 1
        $em->persist($menutbs);
262
263 1
        $menuopt = new \Fi\CoreBundle\Entity\menuApplicazione();
264 1
        $menuopt->setPadre($menutbl->getId());
265 1
        $menuopt->setNome('Opzioni tabella');
266 1
        $menuopt->setPercorso('OpzioniTabella');
267 1
        $menuopt->setAttivo(true);
268 1
        $menuopt->setOrdine(20);
269 1
        $em->persist($menuopt);
270
271 1
        $menumnuapp = new \Fi\CoreBundle\Entity\menuApplicazione();
272 1
        $menumnuapp->setPadre($menuAmministrazione->getId());
273 1
        $menumnuapp->setNome('Menu Applicazione');
274 1
        $menumnuapp->setPercorso('MenuApplicazione_container');
275 1
        $menumnuapp->setAttivo(true);
276 1
        $menumnuapp->setOrdine(50);
277 1
        $em->persist($menumnuapp);
278
279 1
        $menuutil = new \Fi\CoreBundle\Entity\menuApplicazione();
280 1
        $menuutil->setPadre($menuAmministrazione->getId());
281 1
        $menuutil->setNome('Utilità');
282 1
        $menuutil->setPercorso('fi_pannello_amministrazione_homepage');
283 1
        $menuutil->setAttivo(true);
284 1
        $menuutil->setOrdine(100);
285 1
        $em->persist($menuutil);
286
287 1
        $menudemo = new \Fi\CoreBundle\Entity\menuApplicazione();
288 1
        $menudemo->setPadre($menuAmministrazione->getId());
289 1
        $menudemo->setNome('FiDemo');
290 1
        $menudemo->setPercorso('fi_demo_index');
291 1
        $menudemo->setAttivo(false);
292 1
        $menudemo->setOrdine(150);
293 1
        $em->persist($menudemo);
294 1
        $em->flush();
295 1
    }
296
297 1
    private function insertDefaultFfTables($em)
298
    {
299 1
        $ffprincipalerow = new \Fi\CoreBundle\Entity\ffprincipale();
300 1
        $ffprincipalerow->setDescrizione('Descrizione primo record');
301 1
        $em->persist($ffprincipalerow);
302 1
        $em->flush();
303 1
        $ffsecondariarow1 = new \Fi\CoreBundle\Entity\Ffsecondaria();
304 1
        $ffsecondariarow1->setFfprincipale($ffprincipalerow);
305 1
        $ffsecondariarow1->setDescsec('1° secondaria legato al 1° record principale');
306 1
        $ffsecondariarow1->setData(new \DateTime());
307 1
        $ffsecondariarow1->setIntero(10);
308 1
        $ffsecondariarow1->setImporto(12.34);
309 1
        $ffsecondariarow1->setNota('Super Nota ffsecondaria');
310 1
        $ffsecondariarow1->setAttivo(true);
311 1
        $em->persist($ffsecondariarow1);
312
313 1
        $ffsecondariarow2 = new \Fi\CoreBundle\Entity\Ffsecondaria();
314 1
        $ffsecondariarow2->setFfprincipale($ffprincipalerow);
315 1
        $ffsecondariarow2->setDescsec('2° secondaria legato al 1° record principale');
316 1
        $ffsecondariarow2->setData(new \DateTime());
317 1
        $ffsecondariarow2->setIntero(1);
318 1
        $ffsecondariarow2->setImporto(1.23);
319 1
        $ffsecondariarow2->setNota('Nota ffsecondaria');
320 1
        $ffsecondariarow2->setAttivo(true);
321
322 1
        $em->persist($ffsecondariarow2);
323
324 1
        $ffsecondariarow3 = new \Fi\CoreBundle\Entity\Ffsecondaria();
325 1
        $ffsecondariarow3->setFfprincipale($ffprincipalerow);
326 1
        $ffsecondariarow3->setDescsec('3° secondaria legato al 1° record principale');
327 1
        $ffsecondariarow3->setData(new \DateTime());
328 1
        $ffsecondariarow3->setIntero(10);
329 1
        $ffsecondariarow3->setImporto(11.34);
330 1
        $ffsecondariarow3->setNota('Nota 3° ffsecondaria');
331 1
        $ffsecondariarow3->setAttivo(false);
332
333 1
        $em->persist($ffsecondariarow3);
334
335 1
        $ffsecondariarow4 = new \Fi\CoreBundle\Entity\Ffsecondaria();
336 1
        $ffsecondariarow4->setFfprincipale($ffprincipalerow);
337 1
        $ffsecondariarow4->setDescsec('4° secondaria legato al 1° record principale');
338 1
        $ffsecondariarow4->setData(new \DateTime());
339 1
        $ffsecondariarow4->setIntero(101);
340 1
        $ffsecondariarow4->setImporto(101.34);
341 1
        $ffsecondariarow4->setNota('Nota 4° ffsecondaria');
342 1
        $ffsecondariarow4->setAttivo(true);
343
344 1
        $em->persist($ffsecondariarow4);
345
346 1
        $ffsecondariarow5 = new \Fi\CoreBundle\Entity\Ffsecondaria();
347 1
        $ffsecondariarow5->setFfprincipale($ffprincipalerow);
348 1
        $ffsecondariarow5->setDescsec('5° secondaria legato al 1° record principale');
349 1
        $ffsecondariarow5->setData(new \DateTime());
350 1
        $ffsecondariarow5->setIntero(101);
351 1
        $ffsecondariarow5->setImporto(101.34);
352 1
        $ffsecondariarow5->setNota('Nota 4° ffsecondaria');
353 1
        $ffsecondariarow5->setAttivo(true);
354
355 1
        $em->persist($ffsecondariarow5);
356
357 1
        $ffprincipale = new \Fi\CoreBundle\Entity\ffprincipale();
358 1
        $ffprincipale->setDescrizione('Descrizione secondo record');
359 1
        $em->persist($ffprincipale);
360
361 1
        $ffsecondariarow6 = new \Fi\CoreBundle\Entity\Ffsecondaria();
362 1
        $ffsecondariarow6->setFfprincipale($ffprincipale);
363 1
        $ffsecondariarow6->setDescsec('6° secondaria legato al 2° record principale');
364 1
        $ffsecondariarow6->setData(new \DateTime());
365 1
        $ffsecondariarow6->setIntero(10006);
366 1
        $ffsecondariarow6->setImporto(10006.12);
367 1
        $ffsecondariarow6->setNota('Nota altra ffsecondaria');
368 1
        $ffsecondariarow6->setAttivo(true);
369
370 1
        $em->persist($ffsecondariarow6);
371
372 1
        $ffsecondariarow7 = new \Fi\CoreBundle\Entity\Ffsecondaria();
373 1
        $ffsecondariarow7->setFfprincipale($ffprincipale);
374 1
        $ffsecondariarow7->setDescsec('7° secondaria legato al 2° record principale');
375 1
        $ffsecondariarow7->setData(new \DateTime());
376 1
        $ffsecondariarow7->setIntero(10007);
377 1
        $ffsecondariarow7->setImporto(10007.22);
378 1
        $ffsecondariarow7->setNota('Nota altra 7 ffsecondaria');
379 1
        $ffsecondariarow7->setAttivo(false);
380
381 1
        $ffsecondariarow8 = new \Fi\CoreBundle\Entity\Ffsecondaria();
382 1
        $ffsecondariarow8->setFfprincipale($ffprincipale);
383 1
        $ffsecondariarow8->setDescsec('8° secondaria legato al 2° record principale');
384 1
        $ffsecondariarow8->setData(new \DateTime());
385 1
        $ffsecondariarow8->setIntero(10008);
386 1
        $ffsecondariarow8->setImporto(10008.22);
387 1
        $ffsecondariarow8->setNota('Nota altra 8 ffsecondaria');
388 1
        $ffsecondariarow8->setAttivo(true);
389
390 1
        $em->persist($ffsecondariarow7);
391 1
        $ffsecondariarow9 = new \Fi\CoreBundle\Entity\Ffsecondaria();
392 1
        $ffsecondariarow9->setFfprincipale($ffprincipale);
393 1
        $ffsecondariarow9->setDescsec('9° secondaria legato al 2° "record principale"');
394 1
        $ffsecondariarow9->setData(new \DateTime());
395 1
        $ffsecondariarow9->setIntero(1000);
396 1
        $ffsecondariarow9->setImporto(1000.12);
397 1
        $ffsecondariarow9->setNota('Nota altra ffsecondaria');
398 1
        $ffsecondariarow9->setAttivo(true);
399 1
        $em->persist($ffsecondariarow9);
400
401 1
        $ffsecondariarow10 = new \Fi\CoreBundle\Entity\Ffsecondaria();
402 1
        $ffsecondariarow10->setFfprincipale($ffprincipale);
403 1
        $ffsecondariarow10->setDescsec("10° secondaria legato al 2° record principale ed è l'ultimo record");
404 1
        $ffsecondariarow10->setData(new \DateTime());
405 1
        $ffsecondariarow10->setIntero(1100);
406 1
        $ffsecondariarow10->setImporto(1100.99);
407 1
        $ffsecondariarow10->setNota('Nota 10° altra ffsecondaria');
408 1
        $ffsecondariarow10->setAttivo(false);
409 1
        $em->persist($ffsecondariarow10);
410 1
    }
411
}
412