Skip to content

Commit

Permalink
Deprecate timeout options in schema commands (doctrine#1910)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Jan 14, 2019
1 parent b01cd0a commit b659ee7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
6 changes: 6 additions & 0 deletions UPGRADE-1.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ set.
available.
* The `eager` option in `Doctrine\ODM\MongoDB\Query\Query` was deprecated and
will be dropped in 2.0. This functionality is no longer available.

## Schema manager

* The `timeout` option in the `odm:schema:create` and `odm:schema:update`
commands was deprecated and will be dropped in 2.0. Use the `maxTimeMs`
option instead.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

use Doctrine\ODM\MongoDB\SchemaManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;

abstract class AbstractCommand extends Command
{
Expand Down Expand Up @@ -63,4 +65,34 @@ protected function getMetadataFactory()
{
return $this->getDocumentManager()->getMetadataFactory();
}

protected function addTimeoutOptions()
{
$this
->addOption('timeout', 't', InputOption::VALUE_OPTIONAL, 'Timeout (ms) for acknowledged commands. This option is deprecated and will be dropped in 2.0. Use the maxTimeMs option instead.')
->addOption('maxTimeMs', null, InputOption::VALUE_REQUIRED, 'An optional maxTimeMs that will be used for all schema operations.');

return $this;
}

/**
* Returns the appropriate timeout value
*
* @return int|null
*/
protected function getTimeout(InputInterface $input)
{
$maxTimeMs = $input->getOption('maxTimeMs');
$timeout = $input->getOption('timeout');

if (isset($maxTimeMs)) {
return (int) $maxTimeMs;
} elseif (! isset($timeout)) {
return null;
}

@trigger_error(sprintf('The "timeout" option for command "%s" is deprecated and will be removed in 2.0. Use the maxTimeMs option instead.', static::class), E_USER_DEPRECATED);

return (int) $timeout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function configure()
$this
->setName('odm:schema:create')
->addOption('class', 'c', InputOption::VALUE_REQUIRED, 'Document class to process (default: all classes)')
->addOption('timeout', 't', InputOption::VALUE_OPTIONAL, 'Timeout (ms) for acknowledged index creation')
->addTimeoutOptions()
->addOption(self::DB, null, InputOption::VALUE_NONE, 'Create databases')
->addOption(self::COLLECTION, null, InputOption::VALUE_NONE, 'Create collections')
->addOption(self::INDEX, null, InputOption::VALUE_NONE, 'Create indexes')
Expand All @@ -61,8 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$class = $input->getOption('class');

$timeout = $input->getOption('timeout');
$this->timeout = isset($timeout) ? (int) $timeout : null;
$this->timeout = $this->getTimeout($input);

$sm = $this->getSchemaManager();
$isErrored = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function configure()
$this
->setName('odm:schema:update')
->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'Document class to process (default: all classes)')
->addOption('timeout', 't', InputOption::VALUE_OPTIONAL, 'Timeout (ms) for acknowledged index creation')
->addTimeoutOptions()
->setDescription('Update indexes for your documents')
;
}
Expand All @@ -47,8 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$class = $input->getOption('class');

$timeout = $input->getOption('timeout');
$this->timeout = isset($timeout) ? (int) $timeout : null;
$this->timeout = $this->getTimeout($input);

$sm = $this->getSchemaManager();
$isErrored = false;
Expand Down

0 comments on commit b659ee7

Please sign in to comment.