summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Scherzinger <info@andy-scherzinger.de>2024-07-10 22:26:43 +0200
committerGitHub <noreply@github.com>2024-07-10 22:26:43 +0200
commite57dd3484654593ae19cd855efe99e19f53796b3 (patch)
tree300b4e54c1ad8d695604452f598f69719680e770 /tests
parent7a3805607ecce37c5849d73918473342c4f7a39d (diff)
parent1b346aa9a4c3d73919e6fa5123e4a3fb394aa8d6 (diff)
downloadnextcloud-server-e57dd3484654593ae19cd855efe99e19f53796b3.tar.gz
nextcloud-server-e57dd3484654593ae19cd855efe99e19f53796b3.zip
Merge pull request #45920 from nextcloud/backport/45582/stable28
[stable28] delete background jobs by id when cleaning up
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/BackgroundJob/DummyJobList.php22
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php
index 7886e8f877c..5d393aaf13a 100644
--- a/tests/lib/BackgroundJob/DummyJobList.php
+++ b/tests/lib/BackgroundJob/DummyJobList.php
@@ -27,6 +27,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
private array $reserved = [];
private int $last = 0;
+ private int $lastId = 0;
public function __construct() {
}
@@ -41,6 +42,8 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
$job = \OCP\Server::get($job);
}
$job->setArgument($argument);
+ $job->setId($this->lastId);
+ $this->lastId++;
if (!$this->has($job, null)) {
$this->jobs[] = $job;
}
@@ -55,9 +58,20 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
* @param mixed $argument
*/
public function remove($job, $argument = null): void {
- $index = array_search($job, $this->jobs);
- if ($index !== false) {
- unset($this->jobs[$index]);
+ foreach ($this->jobs as $index => $listJob) {
+ if (get_class($job) === get_class($listJob) && $job->getArgument() == $listJob->getArgument()) {
+ unset($this->jobs[$index]);
+ return;
+ }
+ }
+ }
+
+ public function removeById(int $id): void {
+ foreach ($this->jobs as $index => $listJob) {
+ if ($listJob->getId() === $id) {
+ unset($this->jobs[$index]);
+ return;
+ }
}
}
@@ -127,7 +141,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList {
}
}
- public function getById(int $id): IJob {
+ public function getById(int $id): ?IJob {
foreach ($this->jobs as $job) {
if ($job->getId() === $id) {
return $job;