FOSElasticaBundle/Propel/Provider.php

45 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace FOS\ElasticaBundle\Propel;
use FOS\ElasticaBundle\Provider\AbstractProvider;
/**
2015-03-12 11:20:00 +01:00
* Propel provider.
*
* @author William Durand <william.durand1@gmail.com>
*/
class Provider extends AbstractProvider
{
/**
* {@inheritDoc}
*/
public function populate(\Closure $loggerClosure = null, array $options = array())
{
2015-03-12 11:20:00 +01:00
$queryClass = $this->objectClass.'Query';
$nbObjects = $queryClass::create()->count();
$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'];
for (; $offset < $nbObjects; $offset += $batchSize) {
$objects = $queryClass::create()
->limit($batchSize)
->offset($offset)
2014-06-17 02:41:11 +02:00
->find()
->getArrayCopy();
$objects = array_filter($objects, array($this, 'isObjectIndexable'));
2015-03-13 09:34:56 +01:00
if (!empty($objects)) {
$this->objectPersister->insertMany($objects);
}
usleep($sleep);
if ($loggerClosure) {
$loggerClosure($batchSize, $nbObjects);
}
}
}
}