BiCoreBundleInstallCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 408
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
eloc 75
dl 0
loc 408
ccs 48
cts 54
cp 0.8889
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 45 4
A configure() 0 8 1
A generateDefaultData() 0 332 1
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 static $defaultName = 'bicorebundle:install';
17
    protected string $fixtureFile;
18
    private UserManipulator $usermanipulator;
19
20 1
    protected function configure(): void
21
    {
22 1
        $this
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 1
        ;
29
    }
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
    }
38
39 1
    protected function execute(InputInterface $input, OutputInterface $output): int
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 1
        $argumentsdata = array(
71 1
            'command' => 'bicorebundle:configuratorimport',
72 1
            array('--truncatetables' => true),
73 1
        );
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
        return 0;
84
    }
85
86
    /**
87
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
88
     */
89 1
    private function generateDefaultData(string $admin, string $adminemail): void
90
    {
91
        //$todaydt = new \DateTime();
92
        //$today = $todaydt->format("Y-m-d") . "T00:00:00+01:00";
93
94 1
        $defaultData = <<<EOF
95 1
Cdf\BiCoreBundle\Entity\Ruoli:
96
    -
97
        id: 1
98
        ruolo: 'Super Admin'
99
        paginainiziale: /adminpanel
100
        superadmin: true
101
        admin: true
102
        user: false
103
    -
104
        id: 2
105
        ruolo: Amministratore
106
        paginainiziale: /adminpanel
107
        superadmin: false
108
        admin: true
109
        user: false
110
    -
111
        id: 3
112
        ruolo: Utente
113
        paginainiziale: /
114
        superadmin: false
115
        admin: false
116
        user: true
117
Cdf\BiCoreBundle\Entity\Operatori:
118
    -
119 1
        username: $admin
120 1
        usernameCanonical: $admin
121 1
        email: $adminemail
122 1
        emailCanonical: $adminemail
123
        enabled: true
124
        salt: null
125 1
        password: $admin
126
        lastLogin: null
127
        confirmationToken: null
128
        passwordRequestedAt: null
129
        roles:
130
            - ROLE_SUPER_ADMIN
131
        id: 1
132 1
        operatore: $admin
133
        ruoli_id: 1
134
    -
135
        username: userreadroles
136
        usernameCanonical: userreadroles
137
        email: [email protected]
138
        emailCanonical: [email protected]
139
        enabled: true
140
        salt: mNVzoSgms1k9JU2Eb/syehddayryUqNDh0LFzjggcCM
141
        password: 1yNtksQ2XpN+zj/Jk9IP0MpBZcaBxg0nltY+EML4Vlv3cJ8g6U6/YaejAP+tagemH2N2htTqP7tELs2ZhlRAHw==
142
        lastLogin: null
143
        confirmationToken: null
144
        passwordRequestedAt: null
145
        roles: {  }
146
        id: 2
147
        operatore: null
148
        ruoli_id: 3
149
    -
150
        username: usernoroles
151
        usernameCanonical: usernoroles
152
        email: [email protected]
153
        emailCanonical: [email protected]
154
        enabled: true
155
        salt: nczIukArDyAEH6vvjehM973qvfDjE.WGzkP24umtpfE
156
        password: Ce0FJ16dd5HfwJ8CbzocZB3UDZWzwvD9l/A3kyJJR1oHoisxGjF06qR4sSj/Nsk8J6aCI1GtgmHbJfeF7TS93w==
157
        lastLogin: null
158
        confirmationToken: null
159
        passwordRequestedAt: null
160
        roles: {  }
161
        id: 3
162
        operatore: null
163
        ruoli_id: 3                
164
Cdf\BiCoreBundle\Entity\Permessi:
165
    -
166
        id: 1
167
        modulo: Menuapplicazione
168
        crud: crud
169
        operatori_id: null
170
        ruoli_id: 1
171
    -
172
        id: 2
173
        modulo: Opzionitabella
174
        crud: crud
175
        operatori_id: null
176
        ruoli_id: 1
177
    -
178
        id: 3
179
        modulo: Tabelle
180
        crud: crud
181
        operatori_id: null
182
        ruoli_id: 1
183
    -
184
        id: 4
185
        modulo: Permessi
186
        crud: crud
187
        operatori_id: null
188
        ruoli_id: 1
189
    -
190
        id: 5
191
        modulo: Operatori
192
        crud: cru
193
        operatori_id: null
194
        ruoli_id: 1
195
    -
196
        id: 6
197
        modulo: Ruoli
198
        crud: crud
199
        operatori_id: null
200
        ruoli_id: 2
201
    -
202
        id: 7
203
        modulo: Cliente
204
        crud: crud
205
        operatori_id: null
206
        ruoli_id: 2
207
    -
208
        id: 8
209
        modulo: Fornitore
210
        crud: crud
211
        operatori_id: null
212
        ruoli_id: 2
213
    -
214
        id: 9
215
        modulo: Prodottofornitore
216
        crud: crud
217
        operatori_id: null
218
        ruoli_id: 2
219
    -
220
        id: 10
221
        modulo: Ordine
222
        crud: crud
223
        operatori_id: null
224
        ruoli_id: 2
225
    -
226
        id: 11
227
        modulo: Ordine
228
        crud: crud
229
        operatori_id: null
230
        ruoli_id: 2
231
    -
232
        id: 12
233
        modulo: Magazzino
234
        crud: r
235
        operatori_id: 2
236
        ruoli_id: null
237
238
Cdf\BiCoreBundle\Entity\Colonnetabelle:
239
  -
240
    id: 1
241
    nometabella: '*'
242
    nomecampo: null
243
    mostraindex: null
244
    ordineindex: null
245
    larghezzaindex: null
246
    etichettaindex: null
247
    operatori_id: null
248
    registrastorico: null
249
    editabile: null
250
  -
251
    id: 2
252
    nometabella: Permessi
253
    nomecampo: modulo
254
    mostraindex: true
255
    ordineindex: 20
256
    larghezzaindex: 20
257
    etichettaindex: Modulo
258
    operatori_id: null
259
    registrastorico: true
260
    editabile: true
261
  -
262
    id: 3
263
    nometabella: Permessi
264
    nomecampo: crud
265
    mostraindex: true
266
    ordineindex: 30
267
    larghezzaindex: 20
268
    etichettaindex: CRUD
269
    operatori_id: null
270
    registrastorico: true
271
    editabile: true
272
  -
273
    id: 4
274
    nometabella: Permessi
275
    nomecampo: ruoli
276
    mostraindex: true
277
    ordineindex: 50
278
    larghezzaindex: 20
279
    etichettaindex: Ruolo
280
    operatori_id: null
281
    registrastorico: true
282
    editabile: true
283
  -
284
    id: 5
285
    nometabella: Permessi
286
    nomecampo: operatori
287
    mostraindex: true
288
    ordineindex: 60
289
    larghezzaindex: 20
290
    etichettaindex: Operatore
291
    operatori_id: null
292
    registrastorico: true
293
    editabile: true
294
295
Cdf\BiCoreBundle\Entity\Opzionitabelle:
296
  -
297
    id: 1
298
    nometabella: '*'
299
    descrizione: null
300
    parametro: titolo
301
    valore: 'Elenco dati per %tabella%'
302
  -
303
    id: 2
304
    nometabella: '*'
305
    descrizione: 'Altezza Griglia'
306
    parametro: altezzagriglia
307
    valore: '400'
308
309
Cdf\BiCoreBundle\Entity\Menuapplicazione:
310
  -
311
    id: 1
312
    nome: Amministrazione
313
    percorso: null
314
    padre: null
315
    ordine: 20
316
    attivo: true
317
    target: null
318
    tag: Amministrazione
319
    notifiche: null
320
    autorizzazionerichiesta: true
321
    percorsonotifiche: null
322
  -
323
    id: 2
324
    nome: Operatori
325
    percorso: Operatori
326
    padre: 1
327
    ordine: 10
328
    attivo: true
329
    target: null
330
    tag: null
331
    notifiche: null
332
    autorizzazionerichiesta: null
333
    percorsonotifiche: null
334
  -
335
    id: 3
336
    nome: Ruoli
337
    percorso: Ruoli
338
    padre: 1
339
    ordine: 20
340
    attivo: true
341
    target: null
342
    tag: null
343
    notifiche: null
344
    autorizzazionerichiesta: null
345
    percorsonotifiche: null
346
  -
347
    id: 4
348
    nome: Permessi
349
    percorso: Permessi
350
    padre: 1
351
    ordine: 30
352
    attivo: true
353
    target: null
354
    tag: null
355
    notifiche: null
356
    autorizzazionerichiesta: null
357
    percorsonotifiche: null
358
  -
359
    id: 5
360
    nome: 'Gestione tabelle di sistema'
361
    percorso: null
362
    padre: 1
363
    ordine: 40
364
    attivo: true
365
    target: null
366
    tag: null
367
    notifiche: null
368
    autorizzazionerichiesta: null
369
    percorsonotifiche: null
370
  -
371
    id: 6
372
    nome: 'Colonne tabelle'
373
    percorso: Colonnetabelle
374
    padre: 5
375
    ordine: 10
376
    attivo: true
377
    target: null
378
    tag: null
379
    notifiche: null
380
    autorizzazionerichiesta: null
381
    percorsonotifiche: null
382
  -
383
    id: 7
384
    nome: 'Opzioni tabelle'
385
    percorso: Opzionitabelle
386
    padre: 5
387
    ordine: 20
388
    attivo: true
389
    target: null
390
    tag: null
391
    notifiche: null
392
    autorizzazionerichiesta: null
393
    percorsonotifiche: null
394
  -
395
    id: 8
396
    nome: 'Menu Applicazione'
397
    percorso: Menuapplicazione
398
    padre: 1
399
    ordine: 50
400
    attivo: true
401
    target: null
402
    tag: null
403
    notifiche: null
404
    autorizzazionerichiesta: null
405
    percorsonotifiche: null
406
  -
407
    id: 9
408
    nome: Utilità
409
    percorso: fi_pannello_amministrazione_homepage
410
    padre: 1
411
    ordine: 100
412
    attivo: true
413
    target: null
414
    tag: null
415
    notifiche: null
416
    autorizzazionerichiesta: null
417
    percorsonotifiche: null
418 1
EOF;
419 1
        $fs = new Filesystem();
420 1
        $fs->dumpFile($this->fixtureFile, $defaultData);
421
    }
422
}
423