Completed
Branch feature/redis (23fb44)
by Matthew
05:31
created

JobManager::updateExpired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

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