Fixed issues in #426

This commit is contained in:
Karel Souffriau 2014-02-19 11:01:54 +01:00
parent d03d494d30
commit 41bf07ec59
3 changed files with 9 additions and 5 deletions

View file

@ -45,7 +45,7 @@ class PopulateCommand extends ContainerAwareCommand
->addOption('offset', null, InputOption::VALUE_REQUIRED, 'Start indexing at offset', 0)
->addOption('sleep', null, InputOption::VALUE_REQUIRED, 'Sleep time between persisting iterations (microseconds)', 0)
->addOption('batch-size', null, InputOption::VALUE_REQUIRED, 'Index packet size (overrides provider config option)')
->addOption('no-stop-on-error', null, InputOption::VALUE_NONE, 'Do not stop on errors')
->addOption('ignore-errors', null, InputOption::VALUE_NONE, 'Do not stop on errors')
->setDescription('Populates search indexes from providers')
;
}
@ -70,6 +70,8 @@ class PopulateCommand extends ContainerAwareCommand
$reset = $input->getOption('no-reset') ? false : true;
$options = $input->getOptions();
$options['ignore-errors'] = $input->hasOption('ignore-errors');
if ($input->isInteractive() && $reset && $input->getOption('offset')) {
/** @var DialogHelper $dialog */
$dialog = $this->getHelperSet()->get('dialog');

View file

@ -23,8 +23,8 @@ abstract class AbstractProvider extends BaseAbstractProvider
{
parent::__construct($objectPersister, $objectClass, array_merge(array(
'clear_object_manager' => true,
'ignore_errors' => false,
'query_builder_method' => 'createQueryBuilder',
'stop_on_error' => true,
), $options));
$this->managerRegistry = $managerRegistry;
@ -40,7 +40,7 @@ abstract class AbstractProvider extends BaseAbstractProvider
$offset = isset($options['offset']) ? intval($options['offset']) : 0;
$sleep = isset($options['sleep']) ? intval($options['sleep']) : 0;
$batchSize = isset($options['batch-size']) ? intval($options['batch-size']) : $this->options['batch_size'];
$stopOnError = isset($options['no-stop-on-error']) ? empty($options['no-stop-on-error']) : $this->options['stop_on_error'];
$ignoreErrors = isset($options['ignore-errors']) ? $options['ignore-errors'] : $this->options['ignore_errors'];
for (; $offset < $nbObjects; $offset += $batchSize) {
if ($loggerClosure) {
@ -48,7 +48,7 @@ abstract class AbstractProvider extends BaseAbstractProvider
}
$objects = $this->fetchSlice($queryBuilder, $batchSize, $offset);
if (!$stopOnError) {
if (!$ignoreErrors) {
$this->objectPersister->insertMany($objects);
} else {
try {

View file

@ -154,7 +154,9 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase
->method('insertMany')
->will($this->throwException($this->getMockBulkResponseException()));
$provider->populate(null, array('no-stop-on-error' => true));
$this->setExpectedException('Elastica\Exception\Bulk\ResponseException');
$provider->populate(null, array('ignore-errors' => false));
}
/**