1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace Db3v4l\Command; |
||
4 | |||
5 | 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 ![]() |
|||
6 | 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 ![]() |
|||
7 | 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 ![]() |
|||
8 | |||
9 | class DatabaseDrop extends DatabaseManagingCommand |
||
0 ignored issues
–
show
|
|||
10 | { |
||
11 | protected static $defaultName = 'db3v4l:database:drop'; |
||
12 | |||
13 | protected function configure() |
||
0 ignored issues
–
show
|
|||
14 | { |
||
15 | $this |
||
16 | ->setDescription('Drops a database & associated user in parallel on all configured database instances') |
||
17 | ->addOption('database', 'd', InputOption::VALUE_REQUIRED, 'The name of the database to drop') |
||
18 | ->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'The name of a user to drop. If omitted, no user will be dropped') |
||
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 | $dbName = $input->getOption('database'); |
||
44 | |||
45 | // BC api |
||
46 | if ($dbName == null && $userName != null) { |
||
47 | $dbName = $userName; |
||
48 | } |
||
49 | |||
50 | if ($dbName == null) { |
||
51 | throw new \Exception("Please provide a database name"); |
||
52 | } |
||
53 | |||
54 | if ($this->outputFormat === 'text') { |
||
55 | $this->writeln('<info>Dropping databases...</info>'); |
||
56 | } |
||
57 | |||
58 | $dbToDropSpecs = []; |
||
59 | foreach($instanceList as $instanceName => $instanceSpecs) { |
||
0 ignored issues
–
show
|
|||
60 | $dbToDropSpecs[$instanceName] = [ |
||
61 | 'dbname' => $dbName |
||
62 | ]; |
||
63 | if ($userName != null) { |
||
64 | $dbToDropSpecs[$instanceName]['user'] = $userName; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | $results = $this->dropDatabases($instanceList, $dbToDropSpecs); |
||
69 | |||
70 | // q: shall we print something more useful? |
||
71 | $results['data'] = null; |
||
72 | |||
73 | $time = microtime(true) - $start; |
||
74 | |||
75 | $this->writeResults($results, $time); |
||
76 | |||
77 | return (int)$results['failed']; |
||
78 | } |
||
79 | } |
||
80 |