2011-12-20 17:44:39 +01:00
|
|
|
<?php
|
|
|
|
|
2013-03-27 18:44:06 +01:00
|
|
|
namespace FOS\ElasticaBundle\Propel;
|
2011-12-20 17:44:39 +01:00
|
|
|
|
2013-03-27 18:44:06 +01:00
|
|
|
use FOS\ElasticaBundle\Provider\AbstractProvider;
|
2011-12-20 17:44:39 +01:00
|
|
|
|
|
|
|
/**
|
2015-03-12 11:20:00 +01:00
|
|
|
* Propel provider.
|
2011-12-20 17:44:39 +01:00
|
|
|
*
|
|
|
|
* @author William Durand <william.durand1@gmail.com>
|
|
|
|
*/
|
2012-03-10 00:51:08 +01:00
|
|
|
class Provider extends AbstractProvider
|
2011-12-20 17:44:39 +01:00
|
|
|
{
|
|
|
|
/**
|
2015-01-22 01:18:51 +01:00
|
|
|
* {@inheritDoc}
|
2011-12-20 17:44:39 +01:00
|
|
|
*/
|
2015-03-14 09:53:05 +01:00
|
|
|
public function doPopulate($options, \Closure $loggerClosure = null)
|
2011-12-20 17:44:39 +01:00
|
|
|
{
|
2015-03-12 11:20:00 +01:00
|
|
|
$queryClass = $this->objectClass.'Query';
|
2012-03-10 00:51:08 +01:00
|
|
|
$nbObjects = $queryClass::create()->count();
|
2011-12-20 17:44:39 +01:00
|
|
|
|
2015-03-14 09:53:05 +01:00
|
|
|
$offset = $options['offset'];
|
|
|
|
|
|
|
|
for (; $offset < $nbObjects; $offset += $options['batch_size']) {
|
2011-12-20 17:44:39 +01:00
|
|
|
$objects = $queryClass::create()
|
2015-03-14 09:53:05 +01:00
|
|
|
->limit($options['batch_size'])
|
2011-12-20 17:44:39 +01:00
|
|
|
->offset($offset)
|
2014-06-17 02:41:11 +02:00
|
|
|
->find()
|
|
|
|
->getArrayCopy();
|
2015-03-14 09:53:05 +01:00
|
|
|
$objects = $this->filterObjects($options, $objects);
|
2015-03-13 09:34:56 +01:00
|
|
|
if (!empty($objects)) {
|
2015-01-22 01:18:51 +01:00
|
|
|
$this->objectPersister->insertMany($objects);
|
2014-06-19 03:14:13 +02:00
|
|
|
}
|
2011-12-20 17:44:39 +01:00
|
|
|
|
2015-03-14 09:53:05 +01:00
|
|
|
usleep($options['sleep']);
|
2013-10-08 12:00:04 +02:00
|
|
|
|
2015-01-22 01:18:51 +01:00
|
|
|
if ($loggerClosure) {
|
2015-03-14 09:53:05 +01:00
|
|
|
$loggerClosure($options['batch_size'], $nbObjects);
|
2012-03-10 00:51:08 +01:00
|
|
|
}
|
2011-12-20 17:44:39 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-14 09:53:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected function disableLogging()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected function enableLogging($logger)
|
|
|
|
{
|
|
|
|
}
|
2011-12-20 17:44:39 +01:00
|
|
|
}
|