diff --git a/lib/Controller/APIController.php b/lib/Controller/APIController.php index 3671c406..1a60efd0 100644 --- a/lib/Controller/APIController.php +++ b/lib/Controller/APIController.php @@ -62,6 +62,9 @@ public function getRetentions(): DataResponse { while ($data = $cursor->fetch()) { $tagIds[] = (string) $data['tag_id']; $hasJob = $this->jobList->has(RetentionJob::class, ['tag' => (int)$data['tag_id']]); + if (!$hasJob) { + $this->jobList->add(RetentionJob::class, ['tag' => (int)$data['tag_id']]); + } $result[] = [ 'id' => (int)$data['id'], @@ -69,7 +72,7 @@ public function getRetentions(): DataResponse { 'timeunit' => (int)$data['time_unit'], 'timeamount' => (int)$data['time_amount'], 'timeafter' => (int)$data['time_after'], - 'hasJob' => $hasJob, + 'hasJob' => true, ]; } $cursor->closeCursor(); @@ -141,7 +144,7 @@ public function deleteRetention(int $id): DataResponse { $qb = $this->db->getQueryBuilder(); $qb->delete('retention') ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); - $qb->execute(); + $qb->executeStatement(); // Remove cronjob $this->jobList->remove(RetentionJob::class, ['tag' => (int)$data['tag_id']]); diff --git a/tests/lib/BackgroundJob/RetentionJobTest.php b/tests/lib/BackgroundJob/RetentionJobTest.php index 3f2958a7..9ae8c984 100644 --- a/tests/lib/BackgroundJob/RetentionJobTest.php +++ b/tests/lib/BackgroundJob/RetentionJobTest.php @@ -109,7 +109,7 @@ protected function setUp(): void { protected function tearDown(): void { $qb = $this->db->getQueryBuilder(); $qb->delete('retention'); - $qb->execute(); + $qb->executeStatement(); parent::tearDown(); } @@ -121,7 +121,7 @@ private function addTag($tagId, $timeunit, $timeamount, $timeafter = 0) { ->setValue('time_unit', $qb->createNamedParameter($timeunit)) ->setValue('time_amount', $qb->createNamedParameter($timeamount)) ->setValue('time_after', $qb->createNamedParameter($timeafter)); - $qb->execute(); + $qb->executeStatement(); } public function deleteTestCases() { diff --git a/tests/lib/Contoller/APIControllerTest.php b/tests/lib/Contoller/APIControllerTest.php index 922451ba..ea811c81 100644 --- a/tests/lib/Contoller/APIControllerTest.php +++ b/tests/lib/Contoller/APIControllerTest.php @@ -78,7 +78,7 @@ protected function setUp(): void { protected function tearDown(): void { $qb = $this->db->getQueryBuilder(); $qb->delete('retention'); - $qb->execute(); + $qb->executeStatement(); parent::tearDown(); } @@ -112,7 +112,7 @@ public function testAddRetention() { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from('retention'); - $cursor = $qb->execute(); + $cursor = $qb->executeQuery(); $data = $cursor->fetchAll(); $cursor->closeCursor(); @@ -164,23 +164,23 @@ public function dataGetRetentions(): array { ], [ [ - ['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => false], + ['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => true], ] ], [ [ - ['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => false], - ['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => false], - ['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => false], - ['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => false], + ['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => true], + ['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => true], + ['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => true], + ['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => true], ] ], [ [ - ['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => false], - ['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => false, 'expected' => false], - ['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => false, 'expected' => false], - ['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => false], + ['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => true], + ['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => true, 'expected' => false], + ['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => true, 'expected' => false], + ['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => true], ], ['2', '3'], ],