Skip to content

Commit cb3dfd6

Browse files
authored
Merge pull request #47727 from nextcloud/backport/47155/stable29
2 parents ffd220d + 89c71aa commit cb3dfd6

1 file changed

Lines changed: 16 additions & 37 deletions

File tree

lib/private/BackgroundJob/JobList.php

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,20 @@
4747
use function strlen;
4848

4949
class JobList implements IJobList {
50-
protected IDBConnection $connection;
51-
protected IConfig $config;
52-
protected ITimeFactory $timeFactory;
53-
protected LoggerInterface $logger;
54-
55-
public function __construct(IDBConnection $connection, IConfig $config, ITimeFactory $timeFactory, LoggerInterface $logger) {
56-
$this->connection = $connection;
57-
$this->config = $config;
58-
$this->timeFactory = $timeFactory;
59-
$this->logger = $logger;
50+
public function __construct(
51+
protected IDBConnection $connection,
52+
protected IConfig $config,
53+
protected ITimeFactory $timeFactory,
54+
protected LoggerInterface $logger
55+
) {
6056
}
6157

6258
public function add($job, $argument = null, ?int $firstCheck = null): void {
6359
if ($firstCheck === null) {
6460
$firstCheck = $this->timeFactory->getTime();
6561
}
66-
if ($job instanceof IJob) {
67-
$class = get_class($job);
68-
} else {
69-
$class = $job;
70-
}
62+
63+
$class = ($job instanceof IJob) ? get_class($job) : $job;
7164

7265
$argumentJson = json_encode($argument);
7366
if (strlen($argumentJson) > 4000) {
@@ -104,11 +97,7 @@ public function scheduleAfter(string $job, int $runAfter, $argument = null): voi
10497
* @param mixed $argument
10598
*/
10699
public function remove($job, $argument = null): void {
107-
if ($job instanceof IJob) {
108-
$class = get_class($job);
109-
} else {
110-
$class = $job;
111-
}
100+
$class = ($job instanceof IJob) ? get_class($job) : $job;
112101

113102
$query = $this->connection->getQueryBuilder();
114103
$query->delete('jobs')
@@ -127,11 +116,11 @@ public function remove($job, $argument = null): void {
127116
$query->setMaxResults($max);
128117

129118
do {
130-
$deleted = $query->execute();
119+
$deleted = $query->executeStatement();
131120
} while ($deleted === $max);
132121
} else {
133122
// Dont use chunked delete - let the DB handle the large row count natively
134-
$query->execute();
123+
$query->executeStatement();
135124
}
136125
}
137126

@@ -149,11 +138,7 @@ public function removeById(int $id): void {
149138
* @param mixed $argument
150139
*/
151140
public function has($job, $argument): bool {
152-
if ($job instanceof IJob) {
153-
$class = get_class($job);
154-
} else {
155-
$class = $job;
156-
}
141+
$class = ($job instanceof IJob) ? get_class($job) : $job;
157142
$argument = json_encode($argument);
158143

159144
$query = $this->connection->getQueryBuilder();
@@ -172,11 +157,9 @@ public function has($job, $argument): bool {
172157

173158
public function getJobs($job, ?int $limit, int $offset): array {
174159
$iterable = $this->getJobsIterator($job, $limit, $offset);
175-
if (is_array($iterable)) {
176-
return $iterable;
177-
} else {
178-
return iterator_to_array($iterable);
179-
}
160+
return (is_array($iterable))
161+
? $iterable
162+
: iterator_to_array($iterable);
180163
}
181164

182165
/**
@@ -191,11 +174,7 @@ public function getJobsIterator($job, ?int $limit, int $offset): iterable {
191174
->setFirstResult($offset);
192175

193176
if ($job !== null) {
194-
if ($job instanceof IJob) {
195-
$class = get_class($job);
196-
} else {
197-
$class = $job;
198-
}
177+
$class = ($job instanceof IJob) ? get_class($job) : $job;
199178
$query->where($query->expr()->eq('class', $query->createNamedParameter($class)));
200179
}
201180

0 commit comments

Comments
 (0)