Skip to content

Commit 929ff10

Browse files
Merge pull request #461 from nextcloud/bugfix/390/create-background-job-again
fix(retention): Recreate retention job when loading admin settings
2 parents ed70bd7 + fb7e5aa commit 929ff10

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

lib/Controller/APIController.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@ public function getRetentions(): DataResponse {
6262
while ($data = $cursor->fetch()) {
6363
$tagIds[] = (string) $data['tag_id'];
6464
$hasJob = $this->jobList->has(RetentionJob::class, ['tag' => (int)$data['tag_id']]);
65+
if (!$hasJob) {
66+
$this->jobList->add(RetentionJob::class, ['tag' => (int)$data['tag_id']]);
67+
}
6568

6669
$result[] = [
6770
'id' => (int)$data['id'],
6871
'tagid' => (int)$data['tag_id'],
6972
'timeunit' => (int)$data['time_unit'],
7073
'timeamount' => (int)$data['time_amount'],
7174
'timeafter' => (int)$data['time_after'],
72-
'hasJob' => $hasJob,
75+
'hasJob' => true,
7376
];
7477
}
7578
$cursor->closeCursor();
@@ -141,7 +144,7 @@ public function deleteRetention(int $id): DataResponse {
141144
$qb = $this->db->getQueryBuilder();
142145
$qb->delete('retention')
143146
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
144-
$qb->execute();
147+
$qb->executeStatement();
145148

146149
// Remove cronjob
147150
$this->jobList->remove(RetentionJob::class, ['tag' => (int)$data['tag_id']]);

tests/lib/BackgroundJob/RetentionJobTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected function setUp(): void {
109109
protected function tearDown(): void {
110110
$qb = $this->db->getQueryBuilder();
111111
$qb->delete('retention');
112-
$qb->execute();
112+
$qb->executeStatement();
113113

114114
parent::tearDown();
115115
}
@@ -121,7 +121,7 @@ private function addTag($tagId, $timeunit, $timeamount, $timeafter = 0) {
121121
->setValue('time_unit', $qb->createNamedParameter($timeunit))
122122
->setValue('time_amount', $qb->createNamedParameter($timeamount))
123123
->setValue('time_after', $qb->createNamedParameter($timeafter));
124-
$qb->execute();
124+
$qb->executeStatement();
125125
}
126126

127127
public function deleteTestCases() {

tests/lib/Contoller/APIControllerTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function setUp(): void {
7878
protected function tearDown(): void {
7979
$qb = $this->db->getQueryBuilder();
8080
$qb->delete('retention');
81-
$qb->execute();
81+
$qb->executeStatement();
8282

8383
parent::tearDown();
8484
}
@@ -112,7 +112,7 @@ public function testAddRetention() {
112112
$qb = $this->db->getQueryBuilder();
113113
$qb->select('*')
114114
->from('retention');
115-
$cursor = $qb->execute();
115+
$cursor = $qb->executeQuery();
116116
$data = $cursor->fetchAll();
117117
$cursor->closeCursor();
118118

@@ -164,23 +164,23 @@ public function dataGetRetentions(): array {
164164
],
165165
[
166166
[
167-
['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => false],
167+
['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => true],
168168
]
169169
],
170170
[
171171
[
172-
['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => false],
173-
['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => false],
174-
['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => false],
175-
['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => false],
172+
['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => true],
173+
['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => true],
174+
['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => true],
175+
['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => true],
176176
]
177177
],
178178
[
179179
[
180-
['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => false],
181-
['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => false, 'expected' => false],
182-
['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => false, 'expected' => false],
183-
['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => false],
180+
['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => true],
181+
['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => true, 'expected' => false],
182+
['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => true, 'expected' => false],
183+
['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => true],
184184
],
185185
['2', '3'],
186186
],

0 commit comments

Comments
 (0)