Completed
Pull Request — master (#30)
by Matthew
18:57 queued 16:20
created

JobManager::runArchive()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 29
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 6.0038

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 20
cts 21
cp 0.9524
rs 8.439
c 0
b 0
f 0
cc 6
eloc 21
nc 5
nop 3
crap 6.0038
1
<?php
2
3
namespace Dtc\QueueBundle\ORM;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\EntityRepository;
7
use Doctrine\ORM\QueryBuilder;
8
use Dtc\QueueBundle\Doctrine\DoctrineJobManager;
9
use Dtc\QueueBundle\Entity\Job;
10
use Dtc\QueueBundle\Model\BaseJob;
11
use Dtc\QueueBundle\Model\RetryableJob;
12
use Dtc\QueueBundle\Model\StallableJob;
13
use Dtc\QueueBundle\Util\Util;
14
use Symfony\Component\Process\Exception\LogicException;
15
16
class JobManager extends DoctrineJobManager
17
{
18
    use CommonTrait;
19
    protected static $saveInsertCalled = null;
20
    protected static $resetInsertCalled = null;
21
22 3
    public function countJobsByStatus($objectName, $status, $workerName = null, $method = null)
23
    {
24
        /** @var EntityManager $objectManager */
25 3
        $objectManager = $this->getObjectManager();
26
27
        $queryBuilder = $objectManager
28 3
            ->createQueryBuilder()
29 3
            ->select('count(a.id)')
30 3
            ->from($objectName, 'a')
31 3
            ->where('a.status = :status');
32
33 3
        if (null !== $workerName) {
34 1
            $queryBuilder->andWhere('a.workerName = :workerName')
35 1
                ->setParameter(':workerName', $workerName);
36
        }
37
38 3
        if (null !== $method) {
39 1
            $queryBuilder->andWhere('a.method = :method')
40 1
                ->setParameter(':method', $workerName);
41
        }
42
43 3
        $count = $queryBuilder->setParameter(':status', $status)
44 3
            ->getQuery()->getSingleScalarResult();
45
46 3
        if (!$count) {
47 1
            return 0;
48
        }
49
50 3
        return $count;
51
    }
52
53
    /**
54
     * @param string|null $workerName
55
     * @param string|null $method
56
     *
57
     * @return int Count of jobs pruned
58
     */
59 1
    public function pruneExceptionJobs($workerName = null, $method = null)
60
    {
61
        /** @var EntityManager $objectManager */
62 1
        $objectManager = $this->getObjectManager();
63 1
        $queryBuilder = $objectManager->createQueryBuilder()->delete($this->getJobArchiveClass(), 'j');
64 1
        $queryBuilder->where('j.status = :status')
65 1
            ->setParameter(':status', BaseJob::STATUS_EXCEPTION);
66
67 1
        $this->addWorkerNameCriterion($queryBuilder, $workerName, $method);
68 1
        $query = $queryBuilder->getQuery();
69
70 1
        return intval($query->execute());
71
    }
72
73 21
    protected function resetSaveOk($function)
74
    {
75 21
        $objectManager = $this->getObjectManager();
76 21
        $splObjectHash = spl_object_hash($objectManager);
77
78 21
        if ('save' === $function) {
79
            $compare = static::$resetInsertCalled;
80
        } else {
81 21
            $compare = static::$saveInsertCalled;
82
        }
83
84 21
        if ($splObjectHash === $compare) {
85
            // Insert SQL is cached...
86
            $msg = "Can't call save and reset within the same process cycle (or using the same EntityManager)";
87
            throw new LogicException($msg);
88
        }
89
90 21
        if ('save' === $function) {
91
            static::$saveInsertCalled = spl_object_hash($objectManager);
92
        } else {
93 21
            static::$resetInsertCalled = spl_object_hash($objectManager);
94
        }
95 21
    }
96
97
    /**
98
     * @param string $workerName
99
     * @param string $method
100
     */
101 13
    protected function addWorkerNameCriterion(QueryBuilder $queryBuilder, $workerName = null, $method = null)
102
    {
103 13
        if (null !== $workerName) {
104 5
            $queryBuilder->andWhere('j.workerName = :workerName')->setParameter(':workerName', $workerName);
105
        }
106
107 13
        if (null !== $method) {
108 4
            $queryBuilder->andWhere('j.method = :method')->setParameter(':method', $method);
109
        }
110 13
    }
111
112 1
    protected function updateExpired($workerName = null, $method = null)
113
    {
114
        /** @var EntityManager $objectManager */
115 1
        $objectManager = $this->getObjectManager();
116 1
        $queryBuilder = $objectManager->createQueryBuilder()->update($this->getJobClass(), 'j');
117 1
        $queryBuilder->set('j.status', ':newStatus');
118 1
        $queryBuilder->where('j.expiresAt <= :expiresAt')
119 1
            ->setParameter(':expiresAt', new \DateTime());
120 1
        $queryBuilder->andWhere('j.status = :status')
121 1
            ->setParameter(':status', BaseJob::STATUS_NEW)
122 1
            ->setParameter(':newStatus', Job::STATUS_EXPIRED);
123
124 1
        $this->addWorkerNameCriterion($queryBuilder, $workerName, $method);
125 1
        $query = $queryBuilder->getQuery();
126
127 1
        return intval($query->execute());
128
    }
129
130
    /**
131
     * Removes archived jobs older than $olderThan.
132
     *
133
     * @param \DateTime $olderThan
134
     */
135 1
    public function pruneArchivedJobs(\DateTime $olderThan)
136
    {
137 1
        return $this->removeOlderThan(
138 1
            $this->getJobArchiveClass(),
139 1
                'updatedAt',
140 1
                $olderThan
141
        );
142
    }
143
144 2
    public function getJobCount($workerName = null, $method = null)
145
    {
146
        /** @var EntityManager $objectManager */
147 2
        $objectManager = $this->getObjectManager();
148 2
        $queryBuilder = $objectManager->createQueryBuilder();
149
150 2
        $queryBuilder = $queryBuilder->select('count(j)')->from($this->getJobClass(), 'j');
151
152 2
        $where = 'where';
153 2
        if (null !== $workerName) {
154
            if (null !== $method) {
155
                $queryBuilder->where($queryBuilder->expr()->andX(
156
                    $queryBuilder->expr()->eq('j.workerName', ':workerName'),
157
                                                $queryBuilder->expr()->eq('j.method', ':method')
158
                ))
159
                    ->setParameter(':method', $method);
160
            } else {
161
                $queryBuilder->where('j.workerName = :workerName');
162
            }
163
            $queryBuilder->setParameter(':workerName', $workerName);
164
            $where = 'andWhere';
165 2
        } elseif (null !== $method) {
166
            $queryBuilder->where('j.method = :method')->setParameter(':method', $method);
167
            $where = 'andWhere';
168
        }
169
170 2
        $dateTime = \DateTime::createFromFormat('U.u', $timeU = Util::getMicrotimeStr());
171 2
        if (false === $dateTime) {
172
            throw new \RuntimeException("Could not create date time from $timeU");
173
        }
174
        // Filter
175
        $queryBuilder
176 2
            ->$where($queryBuilder->expr()->orX(
177 2
                $queryBuilder->expr()->isNull('j.whenUs'),
178 2
                                        $queryBuilder->expr()->lte('j.whenUs', ':whenUs')
179
            ))
180 2
            ->andWhere($queryBuilder->expr()->orX(
181 2
                $queryBuilder->expr()->isNull('j.expiresAt'),
182 2
                $queryBuilder->expr()->gt('j.expiresAt', ':expiresAt')
183
            ))
184 2
            ->setParameter(':whenUs', Util::getMicrotimeDecimalFormat($dateTime))
185 2
            ->setParameter(':expiresAt', $dateTime);
186
187 2
        $query = $queryBuilder->getQuery();
188
189 2
        return $query->getSingleScalarResult();
190
    }
191
192
    /**
193
     * Get Jobs statuses.
194
     */
195 3
    public function getStatus()
196
    {
197 3
        $result = [];
198 3
        $this->getStatusByEntityName($this->getJobClass(), $result);
199 3
        $this->getStatusByEntityName($this->getJobArchiveClass(), $result);
200
201 3
        $finalResult = [];
202 3
        foreach ($result as $key => $item) {
203 1
            ksort($item);
204 1
            foreach ($item as $status => $count) {
205 1
                if (isset($finalResult[$key][$status])) {
206
                    $finalResult[$key][$status] += $count;
207
                } else {
208 1
                    $finalResult[$key][$status] = $count;
209
                }
210
            }
211
        }
212
213 3
        return $finalResult;
214
    }
215
216
    /**
217
     * @param string $entityName
218
     */
219 3
    protected function getStatusByEntityName($entityName, array &$result)
220
    {
221
        /** @var EntityManager $objectManager */
222 3
        $objectManager = $this->getObjectManager();
223 3
        $result1 = $objectManager->getRepository($entityName)->createQueryBuilder('j')->select('j.workerName, j.method, j.status, count(j) as c')
224 3
            ->groupBy('j.workerName, j.method, j.status')->getQuery()->getArrayResult();
225
226 3
        foreach ($result1 as $item) {
227 1
            $method = $item['workerName'].'->'.$item['method'].'()';
228 1
            if (!isset($result[$method])) {
229 1
                $result[$method] = [BaseJob::STATUS_NEW => 0,
230
                    BaseJob::STATUS_RUNNING => 0,
231
                    BaseJob::STATUS_SUCCESS => 0,
232
                    BaseJob::STATUS_FAILURE => 0,
233
                    BaseJob::STATUS_EXCEPTION => 0,
234
                    StallableJob::STATUS_STALLED => 0,
235
                    \Dtc\QueueBundle\Model\Job::STATUS_EXPIRED => 0,
236
                    RetryableJob::STATUS_MAX_FAILURES => 0,
237
                    RetryableJob::STATUS_MAX_EXCEPTIONS => 0,
238
                    StallableJob::STATUS_MAX_STALLS => 0,
239
                    RetryableJob::STATUS_MAX_RETRIES => 0, ];
240
            }
241 1
            $result[$method][$item['status']] += intval($item['c']);
242
        }
243 3
    }
244
245
    /**
246
     * Get the next job to run (can be filtered by workername and method name).
247
     *
248
     * @param string $workerName
249
     * @param string $methodName
250
     * @param bool   $prioritize
251
     * @param int    $runId
252
     *
253
     * @return Job|null
254
     */
255 11
    public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null)
256
    {
257
        do {
258 11
            $queryBuilder = $this->getJobQueryBuilder($workerName, $methodName, $prioritize);
259 11
            $queryBuilder->select('j.id');
260 11
            $queryBuilder->setMaxResults(100);
261
262
            /** @var QueryBuilder $queryBuilder */
263 11
            $query = $queryBuilder->getQuery();
264 11
            $jobs = $query->getResult();
265 11
            if ($jobs) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $jobs of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
266 9
                foreach ($jobs as $job) {
267 9
                    if ($job = $this->takeJob($job['id'], $runId)) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $job is correct as $this->takeJob($job['id'], $runId) (which targets Dtc\QueueBundle\ORM\JobManager::takeJob()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
268 9
                        return $job;
269
                    }
270
                }
271
            }
272 6
        } while ($jobs);
0 ignored issues
show
Bug Best Practice introduced by
The expression $jobs of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
273
274 6
        return null;
275
    }
276
277
    /**
278
     * @param string|null $workerName
279
     * @param string|null $methodName
280
     * @param bool        $prioritize
281
     *
282
     * @return QueryBuilder
283
     */
284 11
    public function getJobQueryBuilder($workerName = null, $methodName = null, $prioritize = true)
285
    {
286
        /** @var EntityRepository $repository */
287 11
        $repository = $this->getRepository();
288 11
        $queryBuilder = $repository->createQueryBuilder('j');
289 11
        $this->addStandardPredicate($queryBuilder);
290 11
        $this->addWorkerNameCriterion($queryBuilder, $workerName, $methodName);
291
292 11
        if ($prioritize) {
293 11
            $queryBuilder->addOrderBy('j.priority', 'DESC');
294 11
            $queryBuilder->addOrderBy('j.whenUs', 'ASC');
295
        } else {
296 1
            $queryBuilder->orderBy('j.whenUs', 'ASC');
297
        }
298
299 11
        return $queryBuilder;
300
    }
301
302 12
    protected function addStandardPredicate(QueryBuilder $queryBuilder)
303
    {
304 12
        $dateTime = new \DateTime();
305
        $queryBuilder
306 12
            ->where('j.status = :status')->setParameter(':status', BaseJob::STATUS_NEW)
307 12
            ->andWhere($queryBuilder->expr()->orX(
308 12
                $queryBuilder->expr()->isNull('j.whenUs'),
309 12
                $queryBuilder->expr()->lte('j.whenUs', ':whenUs')
310
            ))
311 12
            ->andWhere($queryBuilder->expr()->orX(
312 12
                $queryBuilder->expr()->isNull('j.expiresAt'),
313 12
                $queryBuilder->expr()->gt('j.expiresAt', ':expiresAt')
314
            ))
315 12
            ->setParameter(':whenUs', Util::getMicrotimeDecimalFormat($dateTime))
316 12
            ->setParameter(':expiresAt', $dateTime);
317 12
    }
318
319 9
    protected function takeJob($jobId, $runId = null)
320
    {
321
        /** @var EntityRepository $repository */
322 9
        $repository = $this->getRepository();
323
        /** @var QueryBuilder $queryBuilder */
324 9
        $queryBuilder = $repository->createQueryBuilder('j');
325
        $queryBuilder
326 9
            ->update()
327 9
            ->set('j.status', ':status')
328 9
            ->setParameter(':status', BaseJob::STATUS_RUNNING);
329 9
        if (null !== $runId) {
330
            $queryBuilder
331 1
                ->set('j.runId', ':runId')
332 1
                ->setParameter(':runId', $runId);
333
        }
334 9
        $queryBuilder->set('j.startedAt', ':startedAt')
335 9
            ->setParameter(':startedAt', new \DateTime());
336 9
        $queryBuilder->where('j.id = :id');
337 9
        $queryBuilder->setParameter(':id', $jobId);
338 9
        $resultCount = $queryBuilder->getQuery()->execute();
339
340 9
        if (1 === $resultCount) {
341 9
            return $repository->find($jobId);
342
        }
343
344
        return null;
345
    }
346
347
    /**
348
     * Tries to update the nearest job as a batch.
349
     *
350
     * @param \Dtc\QueueBundle\Model\Job $job
351
     *
352
     * @return null|Job
353
     */
354 1
    public function updateNearestBatch(\Dtc\QueueBundle\Model\Job $job)
355
    {
356
        /** @var QueryBuilder $queryBuilder */
357 1
        $queryBuilder = $this->getRepository()->createQueryBuilder('j');
358 1
        $queryBuilder->select()
359 1
            ->where('j.crcHash = :crcHash')
360 1
            ->andWhere('j.status = :status')
361 1
            ->setParameter(':status', BaseJob::STATUS_NEW)
362 1
            ->setParameter(':crcHash', $job->getCrcHash())
363 1
            ->orderBy('j.whenUs', 'ASC')
364 1
            ->setMaxResults(1);
365 1
        $existingJobs = $queryBuilder->getQuery()->execute();
366
367 1
        if (empty($existingJobs)) {
368
            return null;
369
        }
370
        /** @var Job $existingJob */
371 1
        $existingJob = $existingJobs[0];
372
373 1
        $newPriority = max($job->getPriority(), $existingJob->getPriority());
374 1
        $newWhenUs = $existingJob->getWhenUs();
375 1
        $bcResult = bccomp($job->getWhenUs(), $existingJob->getWhenUs());
0 ignored issues
show
Documentation Bug introduced by
The method getWhenUs does not exist on object<Dtc\QueueBundle\Model\Job>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
376 1
        if ($bcResult < 0) {
377 1
            $newWhenUs = $job->getWhenUs();
0 ignored issues
show
Documentation Bug introduced by
The method getWhenUs does not exist on object<Dtc\QueueBundle\Model\Job>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
378
        }
379
380 1
        $this->updateBatchJob($existingJob, $newPriority, $newWhenUs);
381
382 1
        return $existingJob;
383
    }
384
385
    /**
386
     * @param int    $newPriority
387
     * @param string $newWhenUs
388
     */
389 1
    protected function updateBatchJob(Job $existingJob, $newPriority, $newWhenUs)
390
    {
391 1
        $existingPriority = $existingJob->getPriority();
392 1
        $existingWhenUs = $existingJob->getWhenUs();
393
394 1
        if ($newPriority !== $existingPriority || $newWhenUs !== $existingWhenUs) {
395
            /** @var EntityRepository $repository */
396 1
            $repository = $this->getRepository();
397
            /** @var QueryBuilder $queryBuilder */
398 1
            $queryBuilder = $repository->createQueryBuilder('j');
399 1
            $queryBuilder->update();
400 1
            if ($newPriority !== $existingPriority) {
401 1
                $existingJob->setPriority($newPriority);
402 1
                $queryBuilder->set('j.priority', ':priority')
403 1
                    ->setParameter(':priority', $newPriority);
404
            }
405 1
            if ($newWhenUs !== $existingWhenUs) {
406 1
                $existingJob->setWhenUs($newWhenUs);
407 1
                $queryBuilder->set('j.whenUs', ':whenUs')
408 1
                    ->setParameter(':whenUs', $newWhenUs);
409
            }
410 1
            $queryBuilder->where('j.id = :id');
411 1
            $queryBuilder->setParameter(':id', $existingJob->getId());
412 1
            $queryBuilder->getQuery()->execute();
413
        }
414
415 1
        return $existingJob;
416
    }
417
418 1
    public function getWorkersAndMethods()
419
    {
420
        /** @var EntityRepository $repository */
421 1
        $repository = $this->getRepository();
422 1
        $queryBuilder = $repository->createQueryBuilder('j');
423 1
        $this->addStandardPredicate($queryBuilder);
424
        $queryBuilder
425 1
            ->select('DISTINCT j.workerName, j.method');
426
427 1
        $results = $queryBuilder->getQuery()->getArrayResult();
428 1
        if (!$results) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $results of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
429 1
            return [];
430
        }
431
        $workerMethods = [];
432
        foreach ($results as $result) {
433
            $workerMethods[$result['workerName']][] = $result['method'];
434
        }
435
436
        return $workerMethods;
437
    }
438
439
    /**
440
     * @param string $workerName
441
     * @param string $methodName
442
     */
443 2
    public function countLiveJobs($workerName = null, $methodName = null)
444
    {
445
        /** @var EntityRepository $repository */
446 2
        $repository = $this->getRepository();
447 2
        $queryBuilder = $repository->createQueryBuilder('j');
448 2
        $this->addStandardPredicate($queryBuilder);
449 2
        $this->addWorkerNameCriterion($queryBuilder, $workerName, $methodName);
450 2
        $queryBuilder->select('count(j.id)');
451
452 2
        return $queryBuilder->getQuery()->getSingleScalarResult();
453
    }
454
455
    /**
456
     * @param string   $workerName
457
     * @param string   $methodName
458
     * @param \Closure $progressCallback
459
     */
460 1
    public function archiveAllJobs($workerName = null, $methodName = null, $progressCallback)
461
    {
462
        // First mark all Live non-running jobs as Archive
463 1
        $repository = $this->getRepository();
464
        /** @var QueryBuilder $queryBuilder */
465 1
        $queryBuilder = $repository->createQueryBuilder('j');
466 1
        $queryBuilder->update($this->getJobClass(), 'j')
467 1
            ->set('j.status', ':statusArchive')
468 1
            ->setParameter(':statusArchive', Job::STATUS_ARCHIVE);
469 1
        $this->addStandardPredicate($queryBuilder);
470 1
        $this->addWorkerNameCriterion($queryBuilder, $workerName, $methodName);
471 1
        $resultCount = $queryBuilder->getQuery()->execute();
472
473 1
        if ($resultCount) {
474 1
            $this->runArchive($workerName, $methodName, $progressCallback);
475
        }
476 1
    }
477
478
    /**
479
     * Move jobs in 'archive' status to the archive table.
480
     *
481
     *  This is a bit of a hack to run a lower level query so as to process the INSERT INTO SELECT
482
     *   All on the server as "INSERT INTO SELECT" is not supported natively in Doctrine.
483
     *
484
     * @param string|null $workerName
485
     * @param string|null $methodName
486
     * @param \Closure    $progressCallback
487
     */
488 1
    protected function runArchive($workerName = null, $methodName = null, $progressCallback)
0 ignored issues
show
Unused Code introduced by
The parameter $workerName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $methodName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
489
    {
490
        /** @var EntityManager $entityManager */
491 1
        $entityManager = $this->getObjectManager();
492 1
        $count = 0;
493
        do {
494
            /** @var EntityRepository $repository */
495 1
            $repository = $this->getRepository();
496 1
            $queryBuilder = $repository->createQueryBuilder('j');
497 1
            $queryBuilder->where('j.status = :status')
498 1
                ->setParameter(':status', Job::STATUS_ARCHIVE)
499 1
                ->setMaxResults(10000);
500
501 1
            $results = $queryBuilder->getQuery()->getArrayResult();
502 1
            foreach ($results as $jobRow) {
503 1
                $job = $repository->find($jobRow['id']);
504 1
                if ($job) {
505 1
                    $entityManager->remove($job);
506
                }
507 1
                ++$count;
508 1
                if (0 == $count % 10) {
509
                    $this->flush();
510 1
                    $progressCallback($count);
511
                }
512
            }
513 1
            $this->flush();
514 1
            $progressCallback($count);
515 1
        } while ($results && 10000 == count($results));
0 ignored issues
show
Bug Best Practice introduced by
The expression $results of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
516 1
    }
517
}
518