FOSElasticaBundle/Propel/Provider.php

57 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}
*/
2015-03-14 09:53:05 +01:00
public function doPopulate($options, \Closure $loggerClosure = null)
{
2015-03-12 11:20:00 +01:00
$queryClass = $this->objectClass.'Query';
$nbObjects = $queryClass::create()->count();
2015-03-14 09:53:05 +01:00
$offset = $options['offset'];
for (; $offset < $nbObjects; $offset += $options['batch_size']) {
$objects = $queryClass::create()
2015-03-14 09:53:05 +01:00
->limit($options['batch_size'])
->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)) {
$this->objectPersister->insertMany($objects);
}
2015-03-14 09:53:05 +01:00
usleep($options['sleep']);
if ($loggerClosure) {
2015-03-14 09:53:05 +01:00
$loggerClosure($options['batch_size'], $nbObjects);
}
}
}
2015-03-14 09:53:05 +01:00
/**
* {@inheritDoc}
*/
protected function disableLogging()
{
}
/**
* {@inheritDoc}
*/
protected function enableLogging($logger)
{
}
}