1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
11
|
|
|
use FOS\UserBundle\Util\UserManipulator; |
12
|
|
|
|
13
|
|
|
class BiCoreBundleInstallCommand extends Command |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
protected $fixtureFile; |
17
|
|
|
private $usermanipulator; |
18
|
|
|
|
19
|
1 |
|
protected function configure() |
20
|
|
|
{ |
21
|
|
|
$this |
22
|
1 |
|
->setName('bicorebundle:install') |
23
|
1 |
|
->setDescription('Installazione ambiente bi') |
24
|
1 |
|
->setHelp('Crea il database, un utente amministratore e i dati di default') |
25
|
1 |
|
->addArgument('admin', InputArgument::REQUIRED, 'Username per amministratore') |
26
|
1 |
|
->addArgument('adminpass', InputArgument::REQUIRED, 'Password per amministratore') |
27
|
1 |
|
->addArgument('adminemail', InputArgument::REQUIRED, 'Email per amministratore') |
28
|
|
|
; |
29
|
1 |
|
} |
30
|
|
|
|
31
|
1 |
|
public function __construct(UserManipulator $usermanipulator) |
32
|
|
|
{ |
33
|
1 |
|
$this->usermanipulator = $usermanipulator; |
34
|
|
|
|
35
|
|
|
// you *must* call the parent constructor |
36
|
1 |
|
parent::__construct(); |
37
|
1 |
|
} |
38
|
|
|
|
39
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
40
|
|
|
{ |
41
|
1 |
|
$admin = $input->getArgument('admin'); |
|
|
|
|
42
|
1 |
|
$adminpass = $input->getArgument('adminpass'); |
|
|
|
|
43
|
1 |
|
$adminemail = $input->getArgument('adminemail'); |
|
|
|
|
44
|
1 |
|
$this->fixtureFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'fixtures.yml'; |
45
|
|
|
|
46
|
1 |
|
if (!$admin) { |
47
|
|
|
echo "Inserire il nome utente dell'amministratore"; |
48
|
|
|
|
49
|
|
|
return 1; |
50
|
|
|
} |
51
|
1 |
|
if (!$adminpass) { |
52
|
|
|
echo "Inserire la password per dell'amministratore"; |
53
|
|
|
|
54
|
|
|
return 1; |
55
|
|
|
} |
56
|
1 |
|
if (!$adminemail) { |
57
|
|
|
echo "Inserire la mail dell'amministratore"; |
58
|
|
|
|
59
|
|
|
return 1; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
$commanddb = $this->getApplication()->find('bicorebundle:createdatabase'); |
|
|
|
|
63
|
1 |
|
$argumentsdb = array('command' => 'bicorebundle:createdatabase'); |
64
|
1 |
|
$inputc = new ArrayInput($argumentsdb); |
|
|
|
|
65
|
1 |
|
$commanddb->run($inputc, $output); |
66
|
|
|
|
67
|
1 |
|
$this->generateDefaultData($admin, $adminemail); |
68
|
|
|
|
69
|
1 |
|
$commanddata = $this->getApplication()->find('bicorebundle:configuratorimport'); |
|
|
|
|
70
|
|
|
$argumentsdata = array( |
71
|
1 |
|
'command' => 'bicorebundle:configuratorimport', |
72
|
|
|
array("--truncatetables" => true) |
|
|
|
|
73
|
|
|
); |
74
|
1 |
|
$inputd = new ArrayInput($argumentsdata); |
|
|
|
|
75
|
1 |
|
$commanddata->run($inputd, $output); |
76
|
|
|
|
77
|
1 |
|
$fs = new Filesystem(); |
78
|
1 |
|
$fs->remove($this->fixtureFile); |
79
|
|
|
|
80
|
1 |
|
$userManipulator = $this->usermanipulator; |
81
|
|
|
|
82
|
1 |
|
$userManipulator->changePassword($admin, $adminpass); |
|
|
|
|
83
|
1 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* This will suppress UnusedLocalVariable |
87
|
|
|
* warnings in this method |
88
|
|
|
* |
89
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
90
|
|
|
*/ |
91
|
1 |
|
private function generateDefaultData($admin, $adminemail) |
92
|
|
|
{ |
93
|
|
|
//$todaydt = new \DateTime(); |
|
|
|
|
94
|
|
|
//$today = $todaydt->format("Y-m-d") . "T00:00:00+01:00"; |
|
|
|
|
95
|
|
|
|
96
|
|
|
$defaultData = <<<EOF |
97
|
|
|
Cdf\BiCoreBundle\Entity\Ruoli: |
98
|
|
|
- |
99
|
|
|
id: 1 |
100
|
|
|
ruolo: 'Super Admin' |
101
|
|
|
paginainiziale: /adminpanel |
102
|
|
|
superadmin: true |
103
|
|
|
admin: true |
104
|
|
|
user: false |
105
|
|
|
- |
106
|
|
|
id: 2 |
107
|
|
|
ruolo: Amministratore |
108
|
|
|
paginainiziale: /adminpanel |
109
|
|
|
superadmin: false |
110
|
|
|
admin: true |
111
|
|
|
user: false |
112
|
|
|
- |
113
|
|
|
id: 3 |
114
|
|
|
ruolo: Utente |
115
|
|
|
paginainiziale: / |
116
|
|
|
superadmin: false |
117
|
|
|
admin: false |
118
|
|
|
user: true |
119
|
|
|
Cdf\BiCoreBundle\Entity\Operatori: |
120
|
|
|
- |
121
|
1 |
|
username: $admin |
122
|
1 |
|
usernameCanonical: $admin |
123
|
1 |
|
email: $adminemail |
124
|
1 |
|
emailCanonical: $adminemail |
125
|
|
|
enabled: true |
126
|
|
|
salt: null |
127
|
1 |
|
password: $admin |
128
|
|
|
lastLogin: null |
129
|
|
|
confirmationToken: null |
130
|
|
|
passwordRequestedAt: null |
131
|
|
|
roles: |
132
|
|
|
- ROLE_SUPER_ADMIN |
133
|
|
|
id: 1 |
134
|
1 |
|
operatore: $admin |
135
|
|
|
ruoli_id: 1 |
136
|
|
|
- |
137
|
|
|
username: userreadroles |
138
|
|
|
usernameCanonical: userreadroles |
139
|
|
|
email: [email protected] |
140
|
|
|
emailCanonical: [email protected] |
141
|
|
|
enabled: true |
142
|
|
|
salt: mNVzoSgms1k9JU2Eb/syehddayryUqNDh0LFzjggcCM |
143
|
|
|
password: 1yNtksQ2XpN+zj/Jk9IP0MpBZcaBxg0nltY+EML4Vlv3cJ8g6U6/YaejAP+tagemH2N2htTqP7tELs2ZhlRAHw== |
144
|
|
|
lastLogin: null |
145
|
|
|
confirmationToken: null |
146
|
|
|
passwordRequestedAt: null |
147
|
|
|
roles: { } |
148
|
|
|
id: 2 |
149
|
|
|
operatore: null |
150
|
|
|
ruoli_id: 3 |
151
|
|
|
- |
152
|
|
|
username: usernoroles |
153
|
|
|
usernameCanonical: usernoroles |
154
|
|
|
email: [email protected] |
155
|
|
|
emailCanonical: [email protected] |
156
|
|
|
enabled: true |
157
|
|
|
salt: nczIukArDyAEH6vvjehM973qvfDjE.WGzkP24umtpfE |
158
|
|
|
password: Ce0FJ16dd5HfwJ8CbzocZB3UDZWzwvD9l/A3kyJJR1oHoisxGjF06qR4sSj/Nsk8J6aCI1GtgmHbJfeF7TS93w== |
159
|
|
|
lastLogin: null |
160
|
|
|
confirmationToken: null |
161
|
|
|
passwordRequestedAt: null |
162
|
|
|
roles: { } |
163
|
|
|
id: 3 |
164
|
|
|
operatore: null |
165
|
|
|
ruoli_id: 3 |
166
|
|
|
Cdf\BiCoreBundle\Entity\Permessi: |
167
|
|
|
- |
168
|
|
|
id: 1 |
169
|
|
|
modulo: Menuapplicazione |
170
|
|
|
crud: crud |
171
|
|
|
operatori_id: null |
172
|
|
|
ruoli_id: 1 |
173
|
|
|
- |
174
|
|
|
id: 2 |
175
|
|
|
modulo: Opzionitabella |
176
|
|
|
crud: crud |
177
|
|
|
operatori_id: null |
178
|
|
|
ruoli_id: 1 |
179
|
|
|
- |
180
|
|
|
id: 3 |
181
|
|
|
modulo: Tabelle |
182
|
|
|
crud: crud |
183
|
|
|
operatori_id: null |
184
|
|
|
ruoli_id: 1 |
185
|
|
|
- |
186
|
|
|
id: 4 |
187
|
|
|
modulo: Permessi |
188
|
|
|
crud: crud |
189
|
|
|
operatori_id: null |
190
|
|
|
ruoli_id: 1 |
191
|
|
|
- |
192
|
|
|
id: 5 |
193
|
|
|
modulo: Operatori |
194
|
|
|
crud: cru |
195
|
|
|
operatori_id: null |
196
|
|
|
ruoli_id: 1 |
197
|
|
|
- |
198
|
|
|
id: 6 |
199
|
|
|
modulo: Ruoli |
200
|
|
|
crud: crud |
201
|
|
|
operatori_id: null |
202
|
|
|
ruoli_id: 2 |
203
|
|
|
- |
204
|
|
|
id: 7 |
205
|
|
|
modulo: Cliente |
206
|
|
|
crud: crud |
207
|
|
|
operatori_id: null |
208
|
|
|
ruoli_id: 2 |
209
|
|
|
- |
210
|
|
|
id: 8 |
211
|
|
|
modulo: Fornitore |
212
|
|
|
crud: crud |
213
|
|
|
operatori_id: null |
214
|
|
|
ruoli_id: 2 |
215
|
|
|
- |
216
|
|
|
id: 9 |
217
|
|
|
modulo: Prodottofornitore |
218
|
|
|
crud: crud |
219
|
|
|
operatori_id: null |
220
|
|
|
ruoli_id: 2 |
221
|
|
|
- |
222
|
|
|
id: 10 |
223
|
|
|
modulo: Ordine |
224
|
|
|
crud: crud |
225
|
|
|
operatori_id: null |
226
|
|
|
ruoli_id: 2 |
227
|
|
|
- |
228
|
|
|
id: 11 |
229
|
|
|
modulo: Ordine |
230
|
|
|
crud: crud |
231
|
|
|
operatori_id: null |
232
|
|
|
ruoli_id: 2 |
233
|
|
|
- |
234
|
|
|
id: 12 |
235
|
|
|
modulo: Magazzino |
236
|
|
|
crud: r |
237
|
|
|
operatori_id: 2 |
238
|
|
|
ruoli_id: null |
239
|
|
|
|
240
|
|
|
Cdf\BiCoreBundle\Entity\Colonnetabelle: |
241
|
|
|
- |
242
|
|
|
id: 1 |
243
|
|
|
nometabella: '*' |
244
|
|
|
nomecampo: null |
245
|
|
|
mostraindex: null |
246
|
|
|
ordineindex: null |
247
|
|
|
larghezzaindex: null |
248
|
|
|
etichettaindex: null |
249
|
|
|
operatori_id: null |
250
|
|
|
registrastorico: null |
251
|
|
|
editabile: null |
252
|
|
|
- |
253
|
|
|
id: 2 |
254
|
|
|
nometabella: Permessi |
255
|
|
|
nomecampo: modulo |
256
|
|
|
mostraindex: true |
257
|
|
|
ordineindex: 20 |
258
|
|
|
larghezzaindex: 20 |
259
|
|
|
etichettaindex: Modulo |
260
|
|
|
operatori_id: null |
261
|
|
|
registrastorico: true |
262
|
|
|
editabile: true |
263
|
|
|
- |
264
|
|
|
id: 3 |
265
|
|
|
nometabella: Permessi |
266
|
|
|
nomecampo: crud |
267
|
|
|
mostraindex: true |
268
|
|
|
ordineindex: 30 |
269
|
|
|
larghezzaindex: 20 |
270
|
|
|
etichettaindex: CRUD |
271
|
|
|
operatori_id: null |
272
|
|
|
registrastorico: true |
273
|
|
|
editabile: true |
274
|
|
|
- |
275
|
|
|
id: 4 |
276
|
|
|
nometabella: Permessi |
277
|
|
|
nomecampo: ruoli |
278
|
|
|
mostraindex: true |
279
|
|
|
ordineindex: 50 |
280
|
|
|
larghezzaindex: 20 |
281
|
|
|
etichettaindex: Ruolo |
282
|
|
|
operatori_id: null |
283
|
|
|
registrastorico: true |
284
|
|
|
editabile: true |
285
|
|
|
- |
286
|
|
|
id: 5 |
287
|
|
|
nometabella: Permessi |
288
|
|
|
nomecampo: operatori |
289
|
|
|
mostraindex: true |
290
|
|
|
ordineindex: 60 |
291
|
|
|
larghezzaindex: 20 |
292
|
|
|
etichettaindex: Operatore |
293
|
|
|
operatori_id: null |
294
|
|
|
registrastorico: true |
295
|
|
|
editabile: true |
296
|
|
|
|
297
|
|
|
Cdf\BiCoreBundle\Entity\Opzionitabelle: |
298
|
|
|
- |
299
|
|
|
id: 1 |
300
|
|
|
nometabella: '*' |
301
|
|
|
descrizione: null |
302
|
|
|
parametro: titolo |
303
|
|
|
valore: 'Elenco dati per %tabella%' |
304
|
|
|
- |
305
|
|
|
id: 2 |
306
|
|
|
nometabella: '*' |
307
|
|
|
descrizione: 'Altezza Griglia' |
308
|
|
|
parametro: altezzagriglia |
309
|
|
|
valore: '400' |
310
|
|
|
|
311
|
|
|
Cdf\BiCoreBundle\Entity\Menuapplicazione: |
312
|
|
|
- |
313
|
|
|
id: 1 |
314
|
|
|
nome: Amministrazione |
315
|
|
|
percorso: null |
316
|
|
|
padre: null |
317
|
|
|
ordine: 20 |
318
|
|
|
attivo: true |
319
|
|
|
target: null |
320
|
|
|
tag: Amministrazione |
321
|
|
|
notifiche: null |
322
|
|
|
autorizzazionerichiesta: true |
323
|
|
|
percorsonotifiche: null |
324
|
|
|
- |
325
|
|
|
id: 2 |
326
|
|
|
nome: Operatori |
327
|
|
|
percorso: Operatori |
328
|
|
|
padre: 1 |
329
|
|
|
ordine: 10 |
330
|
|
|
attivo: true |
331
|
|
|
target: null |
332
|
|
|
tag: null |
333
|
|
|
notifiche: null |
334
|
|
|
autorizzazionerichiesta: null |
335
|
|
|
percorsonotifiche: null |
336
|
|
|
- |
337
|
|
|
id: 3 |
338
|
|
|
nome: Ruoli |
339
|
|
|
percorso: Ruoli |
340
|
|
|
padre: 1 |
341
|
|
|
ordine: 20 |
342
|
|
|
attivo: true |
343
|
|
|
target: null |
344
|
|
|
tag: null |
345
|
|
|
notifiche: null |
346
|
|
|
autorizzazionerichiesta: null |
347
|
|
|
percorsonotifiche: null |
348
|
|
|
- |
349
|
|
|
id: 4 |
350
|
|
|
nome: Permessi |
351
|
|
|
percorso: Permessi |
352
|
|
|
padre: 1 |
353
|
|
|
ordine: 30 |
354
|
|
|
attivo: true |
355
|
|
|
target: null |
356
|
|
|
tag: null |
357
|
|
|
notifiche: null |
358
|
|
|
autorizzazionerichiesta: null |
359
|
|
|
percorsonotifiche: null |
360
|
|
|
- |
361
|
|
|
id: 5 |
362
|
|
|
nome: 'Gestione tabelle di sistema' |
363
|
|
|
percorso: null |
364
|
|
|
padre: 1 |
365
|
|
|
ordine: 40 |
366
|
|
|
attivo: true |
367
|
|
|
target: null |
368
|
|
|
tag: null |
369
|
|
|
notifiche: null |
370
|
|
|
autorizzazionerichiesta: null |
371
|
|
|
percorsonotifiche: null |
372
|
|
|
- |
373
|
|
|
id: 6 |
374
|
|
|
nome: 'Colonne tabelle' |
375
|
|
|
percorso: Colonnetabelle |
376
|
|
|
padre: 5 |
377
|
|
|
ordine: 10 |
378
|
|
|
attivo: true |
379
|
|
|
target: null |
380
|
|
|
tag: null |
381
|
|
|
notifiche: null |
382
|
|
|
autorizzazionerichiesta: null |
383
|
|
|
percorsonotifiche: null |
384
|
|
|
- |
385
|
|
|
id: 7 |
386
|
|
|
nome: 'Opzioni tabelle' |
387
|
|
|
percorso: Opzionitabelle |
388
|
|
|
padre: 5 |
389
|
|
|
ordine: 20 |
390
|
|
|
attivo: true |
391
|
|
|
target: null |
392
|
|
|
tag: null |
393
|
|
|
notifiche: null |
394
|
|
|
autorizzazionerichiesta: null |
395
|
|
|
percorsonotifiche: null |
396
|
|
|
- |
397
|
|
|
id: 8 |
398
|
|
|
nome: 'Menu Applicazione' |
399
|
|
|
percorso: Menuapplicazione |
400
|
|
|
padre: 1 |
401
|
|
|
ordine: 50 |
402
|
|
|
attivo: true |
403
|
|
|
target: null |
404
|
|
|
tag: null |
405
|
|
|
notifiche: null |
406
|
|
|
autorizzazionerichiesta: null |
407
|
|
|
percorsonotifiche: null |
408
|
|
|
- |
409
|
|
|
id: 9 |
410
|
|
|
nome: Utilità |
411
|
|
|
percorso: fi_pannello_amministrazione_homepage |
412
|
|
|
padre: 1 |
413
|
|
|
ordine: 100 |
414
|
|
|
attivo: true |
415
|
|
|
target: null |
416
|
|
|
tag: null |
417
|
|
|
notifiche: null |
418
|
|
|
autorizzazionerichiesta: null |
419
|
|
|
percorsonotifiche: null |
420
|
|
|
EOF; |
421
|
1 |
|
$fs = new Filesystem(); |
|
|
|
|
422
|
1 |
|
$fs->dumpFile($this->fixtureFile, $defaultData); |
423
|
1 |
|
} |
424
|
|
|
} |
425
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.