Completed
Pull Request — master (#1043)
by Sebastian
07:23 queued 11s
created

Provider::doPopulate()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 26
ccs 0
cts 22
cp 0
rs 8.5806
cc 4
eloc 17
nc 5
nop 2
crap 20
1
<?php
2
3
namespace FOS\ElasticaBundle\Propel;
4
5
use FOS\ElasticaBundle\Provider\AbstractProvider;
6
7
/**
8
 * Propel provider.
9
 *
10
 * @author William Durand <[email protected]>
11
 */
12
class Provider extends AbstractProvider
13
{
14
    /**
15
     * {@inheritDoc}
16
     */
17
    public function doPopulate($options, \Closure $loggerClosure = null)
18
    {
19
        $queryClass = $this->objectClass.'Query';
20
        $nbObjects = $queryClass::create()->count();
21
22
        $offset = $options['offset'];
23
24
        for (; $offset < $nbObjects; $offset += $options['batch_size']) {
25
            $objects = $queryClass::create()
26
                ->limit($options['batch_size'])
27
                ->offset($offset)
28
                ->find()
29
                ->getArrayCopy();
30
            $sliceSize = count($objects);
31
            $objects = $this->filterObjects($options, $objects);
32
            if (!empty($objects)) {
33
                $this->objectPersister->insertMany($objects);
34
            }
35
36
            usleep($options['sleep']);
37
38
            if ($loggerClosure) {
39
                $loggerClosure($sliceSize, $nbObjects);
40
            }
41
        }
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    protected function disableLogging()
48
    {
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    protected function enableLogging($logger)
55
    {
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 View Code Duplication
    protected function configureOptions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        parent::configureOptions();
64
65
        $this->resolver->setDefaults(array(
66
            'clear_object_manager' => true,
67
            'debug_logging'        => false,
68
            'ignore_errors'        => false,
69
            'offset'               => 0,
70
            'query_builder_method' => 'createQueryBuilder',
71
            'sleep'                => 0
72
        ));
73
    }
74
}
75