Completed
Pull Request — master (#30)
by Matthew
13:27 queued 10:46
created

JobManager::takeJob()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 3.0017

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 16
cts 17
cp 0.9412
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 19
nc 4
nop 2
crap 3.0017
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 14
    protected function resetSaveOk($function)
74
    {
75 14
        $objectManager = $this->getObjectManager();
76 14
        $splObjectHash = spl_object_hash($objectManager);
77
78 14
        if ('save' === $function) {
79
            $compare = static::$resetInsertCalled;
80
        } else {
81 14
            $compare = static::$saveInsertCalled;
82
        }
83
84 14
        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 14
        if ('save' === $function) {
91
            static::$saveInsertCalled = spl_object_hash($objectManager);
92
        } else {
93 14
            static::$resetInsertCalled = spl_object_hash($objectManager);
94
        }
95 14
    }
96
97
    /**
98
     * @param string $workerName
99
     * @param string $method
100
     */
101 8
    protected function addWorkerNameCriterion(QueryBuilder $queryBuilder, $workerName = null, $method = null)
102
    {
103 8
        if (null !== $workerName) {
104 4
            $queryBuilder->andWhere('j.workerName = :workerName')->setParameter(':workerName', $workerName);
105
        }
106
107 8
        if (null !== $method) {
108 4
            $queryBuilder->andWhere('j.method = :method')->setParameter(':method', $method);
109
        }
110 8
    }
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 2
        $finalResult = [];
202 2
        foreach ($result as $key => $item) {
203
            ksort($item);
204
            foreach ($item as $status => $count) {
205
                if (isset($finalResult[$key][$status])) {
206
                    $finalResult[$key][$status] += $count;
207
                } else {
208
                    $finalResult[$key][$status] = $count;
209
                }
210
            }
211
        }
212
213 2
        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
                    \Dtc\QueueBundle\Model\Job::STATUS_EXPIRED => 0,
235
                    RetryableJob::STATUS_MAX_FAILURES => 0,
236
                    RetryableJob::STATUS_MAX_EXCEPTIONS => 0,
237
                    StallableJob::STATUS_MAX_STALLS => 0,
238
                    RetryableJob::STATUS_MAX_RETRIES => 0, ];
239
            }
240 1
            $result[$method][$item['status']] += intval($item['c']);
241
        }
242 3
    }
243
244
    /**
245
     * Get the next job to run (can be filtered by workername and method name).
246
     *
247
     * @param string $workerName
248
     * @param string $methodName
249
     * @param bool   $prioritize
250
     * @param int    $runId
251
     *
252
     * @return Job|null
253
     */
254 6
    public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null)
255
    {
256
        do {
257 6
            $queryBuilder = $this->getJobQueryBuilder($workerName, $methodName, $prioritize);
258 6
            $queryBuilder->select('j.id');
259 6
            $queryBuilder->setMaxResults(100);
260
261
            /** @var QueryBuilder $queryBuilder */
262 6
            $query = $queryBuilder->getQuery();
263 6
            $jobs = $query->getResult();
264 6
            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...
265 4
                foreach ($jobs as $job) {
266 4
                    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...
267 4
                        return $job;
268
                    }
269
                }
270
            }
271 5
        } 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...
272
273 5
        return null;
274
    }
275
276
    /**
277
     * @param string|null $workerName
278
     * @param string|null $methodName
279
     * @param bool        $prioritize
280
     *
281
     * @return QueryBuilder
282
     */
283 6
    public function getJobQueryBuilder($workerName = null, $methodName = null, $prioritize = true)
284
    {
285
        /** @var EntityRepository $repository */
286 6
        $repository = $this->getRepository();
287 6
        $queryBuilder = $repository->createQueryBuilder('j');
288 6
        $this->addStandardPredicate($queryBuilder);
289 6
        $this->addWorkerNameCriterion($queryBuilder, $workerName, $methodName);
290
291 6
        if ($prioritize) {
292 6
            $queryBuilder->addOrderBy('j.priority', 'DESC');
293 6
            $queryBuilder->addOrderBy('j.whenUs', 'ASC');
294
        } else {
295 1
            $queryBuilder->orderBy('j.whenUs', 'ASC');
296
        }
297
298 6
        return $queryBuilder;
299
    }
300
301 7
    protected function addStandardPredicate(QueryBuilder $queryBuilder)
302
    {
303 7
        $dateTime = new \DateTime();
304
        $queryBuilder
305 7
            ->where('j.status = :status')->setParameter(':status', BaseJob::STATUS_NEW)
306 7
            ->andWhere($queryBuilder->expr()->orX(
307 7
                $queryBuilder->expr()->isNull('j.whenUs'),
308 7
                $queryBuilder->expr()->lte('j.whenUs', ':whenUs')
309
            ))
310 7
            ->andWhere($queryBuilder->expr()->orX(
311 7
                $queryBuilder->expr()->isNull('j.expiresAt'),
312 7
                $queryBuilder->expr()->gt('j.expiresAt', ':expiresAt')
313
            ))
314 7
            ->setParameter(':whenUs', Util::getMicrotimeDecimalFormat($dateTime))
315 7
            ->setParameter(':expiresAt', $dateTime);
316 7
    }
317
318 4
    protected function takeJob($jobId, $runId = null)
319
    {
320
        /** @var EntityRepository $repository */
321 4
        $repository = $this->getRepository();
322
        /** @var QueryBuilder $queryBuilder */
323 4
        $queryBuilder = $repository->createQueryBuilder('j');
324
        $queryBuilder
325 4
            ->update()
326 4
            ->set('j.status', ':status')
327 4
            ->setParameter(':status', BaseJob::STATUS_RUNNING);
328 4
        if (null !== $runId) {
329
            $queryBuilder
330 1
                ->set('j.runId', ':runId')
331 1
                ->setParameter(':runId', $runId);
332
        }
333 4
        $queryBuilder->set('j.startedAt', ':startedAt')
334 4
            ->setParameter(':startedAt', new \DateTime());
335 4
        $queryBuilder->where('j.id = :id');
336 4
        $queryBuilder->setParameter(':id', $jobId);
337 4
        $resultCount = $queryBuilder->getQuery()->execute();
338
339 4
        if (1 === $resultCount) {
340 4
            return $repository->find($jobId);
341
        }
342
343
        return null;
344
    }
345
346
    /**
347
     * Tries to update the nearest job as a batch.
348
     *
349
     * @param \Dtc\QueueBundle\Model\Job $job
350
     *
351
     * @return null|Job
352
     */
353 1
    public function updateNearestBatch(\Dtc\QueueBundle\Model\Job $job)
354
    {
355
        /** @var QueryBuilder $queryBuilder */
356 1
        $queryBuilder = $this->getRepository()->createQueryBuilder('j');
357 1
        $queryBuilder->select()
358 1
            ->where('j.crcHash = :crcHash')
359 1
            ->andWhere('j.status = :status')
360 1
            ->setParameter(':status', BaseJob::STATUS_NEW)
361 1
            ->setParameter(':crcHash', $job->getCrcHash())
362 1
            ->orderBy('j.whenUs', 'ASC')
363 1
            ->setMaxResults(1);
364 1
        $existingJobs = $queryBuilder->getQuery()->execute();
365
366 1
        if (empty($existingJobs)) {
367
            return null;
368
        }
369
        /** @var Job $existingJob */
370 1
        $existingJob = $existingJobs[0];
371
372 1
        $newPriority = max($job->getPriority(), $existingJob->getPriority());
373 1
        $newWhenUs = $existingJob->getWhenUs();
374 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...
375 1
        if ($bcResult < 0) {
376 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...
377
        }
378
379 1
        $this->updateBatchJob($existingJob, $newPriority, $newWhenUs);
380
381 1
        return $existingJob;
382
    }
383
384
    /**
385
     * @param int    $newPriority
386
     * @param string $newWhenUs
387
     */
388 1
    protected function updateBatchJob(Job $existingJob, $newPriority, $newWhenUs)
389
    {
390 1
        $existingPriority = $existingJob->getPriority();
391 1
        $existingWhenUs = $existingJob->getWhenUs();
392
393 1
        if ($newPriority !== $existingPriority || $newWhenUs !== $existingWhenUs) {
394
            /** @var EntityRepository $repository */
395 1
            $repository = $this->getRepository();
396
            /** @var QueryBuilder $queryBuilder */
397 1
            $queryBuilder = $repository->createQueryBuilder('j');
398 1
            $queryBuilder->update();
399 1
            if ($newPriority !== $existingPriority) {
400 1
                $existingJob->setPriority($newPriority);
401 1
                $queryBuilder->set('j.priority', ':priority')
402 1
                    ->setParameter(':priority', $newPriority);
403
            }
404 1
            if ($newWhenUs !== $existingWhenUs) {
405 1
                $existingJob->setWhenUs($newWhenUs);
406 1
                $queryBuilder->set('j.whenUs', ':whenUs')
407 1
                    ->setParameter(':whenUs', $newWhenUs);
408
            }
409 1
            $queryBuilder->where('j.id = :id');
410 1
            $queryBuilder->setParameter(':id', $existingJob->getId());
411 1
            $queryBuilder->getQuery()->execute();
412
        }
413
414 1
        return $existingJob;
415
    }
416
417 1
    public function getWorkersAndMethods()
418
    {
419
        /** @var EntityRepository $repository */
420 1
        $repository = $this->getRepository();
421 1
        $queryBuilder = $repository->createQueryBuilder('j');
422 1
        $this->addStandardPredicate($queryBuilder);
423
        $queryBuilder
424 1
            ->select('DISTINCT j.workerName, j.method');
425
426 1
        $results = $queryBuilder->getQuery()->getArrayResult();
427 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...
428 1
            return [];
429
        }
430
        $workerMethods = [];
431
        foreach ($results as $result) {
432
            $workerMethods[$result['workerName']][] = $result['method'];
433
        }
434
435
        return $workerMethods;
436
    }
437
438
    /**
439
     * @param string $workerName
440
     * @param string $methodName
441
     */
442 2
    public function countLiveJobs($workerName = null, $methodName = null)
443
    {
444
        /** @var EntityRepository $repository */
445 2
        $repository = $this->getRepository();
446 2
        $queryBuilder = $repository->createQueryBuilder('j');
447 2
        $this->addStandardPredicate($queryBuilder);
448 2
        $this->addWorkerNameCriterion($queryBuilder, $workerName, $methodName);
449 2
        $queryBuilder->select('count(j.id)');
450
451 2
        return $queryBuilder->getQuery()->getSingleScalarResult();
452
    }
453
454
    /**
455
     * @param string   $workerName
456
     * @param string   $methodName
457
     * @param \Closure $progressCallback
458
     */
459 1
    public function archiveAllJobs($workerName = null, $methodName = null, $progressCallback)
460
    {
461
        // First mark all Live non-running jobs as Archive
462 1
        $repository = $this->getRepository();
463
        /** @var QueryBuilder $queryBuilder */
464 1
        $queryBuilder = $repository->createQueryBuilder('j');
465 1
        $queryBuilder->update($this->getJobClass(), 'j')
466 1
            ->set('j.status', ':statusArchive')
467 1
            ->setParameter(':statusArchive', Job::STATUS_ARCHIVE);
468 1
        $this->addStandardPredicate($queryBuilder);
469 1
        $this->addWorkerNameCriterion($queryBuilder, $workerName, $methodName);
470 1
        $resultCount = $queryBuilder->getQuery()->execute();
471
472 1
        if ($resultCount) {
473 1
            $this->runArchive($workerName, $methodName, $progressCallback);
474
        }
475 1
    }
476
477
    /**
478
     * Move jobs in 'archive' status to the archive table.
479
     *
480
     *  This is a bit of a hack to run a lower level query so as to process the INSERT INTO SELECT
481
     *   All on the server as "INSERT INTO SELECT" is not supported natively in Doctrine.
482
     *
483
     * @param string|null $workerName
484
     * @param string|null $methodName
485
     * @param \Closure $progressCallback
486
     */
487 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...
488
    {
489
        /** @var EntityManager $entityManager */
490 1
        $entityManager = $this->getObjectManager();
491 1
        $count = 0;
492
        do {
493
            /** @var EntityRepository $repository */
494 1
            $repository = $this->getRepository();
495 1
            $queryBuilder = $repository->createQueryBuilder('j');
496 1
            $queryBuilder->where('j.status = :status')
497 1
                ->setParameter(':status', Job::STATUS_ARCHIVE)
498 1
                ->setMaxResults(10000);
499
500 1
            $results = $queryBuilder->getQuery()->getArrayResult();
501 1
            foreach ($results as $jobRow) {
502 1
                $job = $repository->find($jobRow['id']);
503 1
                if ($job) {
504 1
                    $entityManager->remove($job);
505
                }
506 1
                ++$count;
507 1
                if (0 == $count % 10) {
508
                    $this->flush();
509 1
                    $progressCallback($count);
510
                }
511
            }
512 1
            $this->flush();
513 1
            $progressCallback($count);
514 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...
515 1
    }
516
}
517