gruberro /
php-mongo-migrations
| 1 | <?php declare(strict_types=1); |
||||
| 2 | |||||
| 3 | namespace Gruberro\MongoDbMigrations\Console\Command; |
||||
| 4 | |||||
| 5 | use Gruberro\MongoDbMigrations; |
||||
| 6 | use MongoDB\Client; |
||||
| 7 | use Symfony\Component\Console; |
||||
| 8 | |||||
| 9 | class ReleaseLockCommand extends Console\Command\Command |
||||
| 10 | { |
||||
| 11 | /** |
||||
| 12 | * {@inheritdoc} |
||||
| 13 | */ |
||||
| 14 | 2 | protected function configure() |
|||
| 15 | { |
||||
| 16 | $this |
||||
| 17 | 2 | ->setName('php-mongodb-migrations:release-lock') |
|||
| 18 | 2 | ->setDescription('Release current migration lock') |
|||
| 19 | 2 | ->addOption( |
|||
| 20 | 2 | 'server', |
|||
| 21 | 2 | 's', |
|||
| 22 | 2 | Console\Input\InputOption::VALUE_REQUIRED, |
|||
| 23 | 2 | 'The connection string (e.g. mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db)', |
|||
| 24 | 2 | 'mongodb://localhost:27017' |
|||
| 25 | ) |
||||
| 26 | 2 | ->addArgument( |
|||
| 27 | 2 | 'database', |
|||
| 28 | 2 | Console\Input\InputArgument::REQUIRED, |
|||
| 29 | 2 | 'The database to connect to' |
|||
| 30 | ) |
||||
| 31 | ; |
||||
| 32 | 2 | } |
|||
| 33 | |||||
| 34 | /** |
||||
| 35 | * {@inheritdoc} |
||||
| 36 | */ |
||||
| 37 | 2 | protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int |
|||
| 38 | { |
||||
| 39 | 2 | $client = new Client($input->getOption('server')); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 40 | 2 | $db = $client->selectDatabase($input->getArgument('database')); |
|||
|
0 ignored issues
–
show
It seems like
$input->getArgument('database') can also be of type string[]; however, parameter $databaseName of MongoDB\Client::selectDatabase() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 41 | 2 | $output->writeln("<info>✓ Successfully established database connection</info>", $output::VERBOSITY_VERBOSE); |
|||
| 42 | |||||
| 43 | 2 | $databaseMigrationsLockCollection = $db->selectCollection('DATABASE_MIGRATIONS_LOCK'); |
|||
| 44 | 2 | $databaseMigrationsLockCollection->updateOne(['locked' => ['$exists' => true]], ['$set' => ['locked' => false]], ['upsert' => true]); |
|||
| 45 | 2 | $output->writeln("<info>✓ Successfully released migration lock</info>"); |
|||
| 46 | |||||
| 47 | 2 | return 0; |
|||
| 48 | } |
||||
| 49 | } |
||||
| 50 |