1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\ZAuthModule\Command; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Command\Command; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
22
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
23
|
|
|
use Zikula\ZAuthModule\Helper\FileIOHelper; |
24
|
|
|
|
25
|
|
|
class ZikulaUsersImportCommand extends Command |
26
|
|
|
{ |
27
|
|
|
protected static $defaultName = 'zikula:users:import'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var FileIOHelper |
31
|
|
|
*/ |
32
|
|
|
private $ioHelper; |
33
|
|
|
|
34
|
|
|
public function __construct(FileIOHelper $ioHelper) |
35
|
|
|
{ |
36
|
|
|
$this->ioHelper = $ioHelper; |
37
|
|
|
|
38
|
|
|
parent::__construct(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function configure() |
42
|
|
|
{ |
43
|
|
|
$this |
44
|
|
|
->setDescription('Import a list of users.') |
45
|
|
|
->addArgument('path', InputArgument::REQUIRED, 'Path to text file containing list of users.') |
46
|
|
|
->addOption('delimiter', 'd', InputOption::VALUE_REQUIRED, 'Field delimiter (default = ,).') |
47
|
|
|
; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
51
|
|
|
{ |
52
|
|
|
$io = new SymfonyStyle($input, $output); |
53
|
|
|
$path = $input->getArgument('path'); |
54
|
|
|
$delimiter = $input->getOption('delimiter') ?? ','; |
55
|
|
|
|
56
|
|
|
$file = new File($path); |
|
|
|
|
57
|
|
|
$error = $this->ioHelper->importUsersFromFile($file, $delimiter); |
58
|
|
|
if (empty($error)) { |
59
|
|
|
$createdUsers = $this->ioHelper->getCreatedUsers(); |
60
|
|
|
$io->success(sprintf('Import successful. %d users imported', count($createdUsers))); |
61
|
|
|
|
62
|
|
|
return 0; |
63
|
|
|
} |
64
|
|
|
$io->error($error); |
65
|
|
|
|
66
|
|
|
return 1; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|