diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2024-07-10 22:26:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-10 22:26:43 +0200 |
commit | e57dd3484654593ae19cd855efe99e19f53796b3 (patch) | |
tree | 300b4e54c1ad8d695604452f598f69719680e770 /tests | |
parent | 7a3805607ecce37c5849d73918473342c4f7a39d (diff) | |
parent | 1b346aa9a4c3d73919e6fa5123e4a3fb394aa8d6 (diff) | |
download | nextcloud-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.php | 22 |
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; |