1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace Db3v4l\Command; |
||
4 | |||
5 | use Db3v4l\Core\DatabaseSchemaManager; |
||
0 ignored issues
–
show
The type
Db3v4l\Core\DatabaseSchemaManager was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
6 | use Symfony\Component\Console\Input\InputInterface; |
||
0 ignored issues
–
show
The type
Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
7 | use Symfony\Component\Console\Input\InputOption; |
||
0 ignored issues
–
show
The type
Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
8 | use Symfony\Component\Console\Output\OutputInterface; |
||
0 ignored issues
–
show
The type
Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
9 | |||
10 | class UserDrop extends DatabaseManagingCommand |
||
0 ignored issues
–
show
|
|||
11 | { |
||
12 | protected static $defaultName = 'db3v4l:user:drop'; |
||
13 | |||
14 | protected function configure() |
||
0 ignored issues
–
show
|
|||
15 | { |
||
16 | $this |
||
17 | ->setDescription('Drops a database user in parallel on all configured database instances') |
||
18 | ->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'The name of the user to drop') |
||
19 | ->addCommonOptions() |
||
0 ignored issues
–
show
|
|||
20 | ; |
||
21 | } |
||
22 | |||
23 | /** |
||
0 ignored issues
–
show
|
|||
24 | * @param InputInterface $input |
||
0 ignored issues
–
show
|
|||
25 | * @param OutputInterface $output |
||
0 ignored issues
–
show
|
|||
26 | * @return int |
||
0 ignored issues
–
show
|
|||
27 | * @throws \Exception |
||
0 ignored issues
–
show
|
|||
28 | */ |
||
29 | protected function execute(InputInterface $input, OutputInterface $output) |
||
30 | { |
||
31 | $start = microtime(true); |
||
32 | |||
33 | // as per https://www.php.net/manual/en/function.ignore-user-abort.php: for cli scripts, it is probably a good idea |
||
34 | // to use ignore_user_abort |
||
35 | ignore_user_abort(true); |
||
36 | |||
37 | $this->setOutput($output); |
||
38 | $this->setVerbosity($output->getVerbosity()); |
||
39 | |||
40 | $instanceList = $this->parseCommonOptions($input); |
||
41 | |||
42 | $userName = $input->getOption('user'); |
||
43 | |||
44 | if ($userName == null) { |
||
45 | throw new \Exception("Please provide a username"); |
||
46 | } |
||
47 | |||
48 | if ($this->outputFormat === 'text') { |
||
49 | $this->writeln('<info>Dropping users...</info>'); |
||
50 | } |
||
51 | |||
52 | $userToDropSpecs = []; |
||
53 | foreach($instanceList as $instanceName => $instanceSpecs) { |
||
0 ignored issues
–
show
|
|||
54 | $userToDropSpecs[$instanceName] = [ |
||
55 | 'user' => $userName |
||
56 | ]; |
||
57 | } |
||
58 | $results = $this->dropUsers($instanceList, $userToDropSpecs); |
||
59 | |||
60 | // BC with versions < 0.8 |
||
61 | $results['data'] = null; |
||
62 | |||
63 | $time = microtime(true) - $start; |
||
64 | |||
65 | $this->writeResults($results, $time); |
||
66 | |||
67 | return (int)$results['failed']; |
||
68 | } |
||
69 | |||
70 | /** |
||
0 ignored issues
–
show
|
|||
71 | * @param $instanceList |
||
0 ignored issues
–
show
|
|||
72 | * @param $userToDropSpecs |
||
0 ignored issues
–
show
|
|||
73 | * @param bool $ifExists |
||
0 ignored issues
–
show
|
|||
74 | * @return array |
||
0 ignored issues
–
show
|
|||
75 | * @throws \Exception |
||
0 ignored issues
–
show
|
|||
76 | */ |
||
77 | protected function dropUsers($instanceList, $userToDropSpecs, $ifExists = false) |
||
78 | { |
||
79 | return $this->executeSqlAction( |
||
80 | $instanceList, |
||
81 | 'Dropping of user', |
||
82 | function ($schemaManager, $instanceName) use ($userToDropSpecs, $ifExists) { |
||
83 | $dbConnectionSpec = $userToDropSpecs[$instanceName]; |
||
84 | /** @var DatabaseSchemaManager $schemaManager */ |
||
0 ignored issues
–
show
|
|||
85 | return $schemaManager->getDropUserSqlAction( |
||
86 | $dbConnectionSpec['user'], |
||
87 | $ifExists |
||
88 | ); |
||
89 | } |
||
90 | ); |
||
91 | } |
||
92 | } |
||
93 |