diff options
-rw-r--r-- | core/Command/Background/ListCommand.php | 2 | ||||
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 11 | ||||
-rw-r--r-- | lib/public/BackgroundJob/IJobList.php | 14 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/DummyJobList.php | 2 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/JobListTest.php | 2 |
5 files changed, 25 insertions, 6 deletions
diff --git a/core/Command/Background/ListCommand.php b/core/Command/Background/ListCommand.php index 30440b226de..4116bfa0ff1 100644 --- a/core/Command/Background/ListCommand.php +++ b/core/Command/Background/ListCommand.php @@ -67,7 +67,7 @@ class ListCommand extends Base { } protected function execute(InputInterface $input, OutputInterface $output): int { - $jobs = $this->jobList->getJobs($input->getOption('class'), (int)$input->getOption('limit'), (int)$input->getOption('offset')); + $jobs = $this->jobList->getJobsIterator($input->getOption('class'), (int)$input->getOption('limit'), (int)$input->getOption('offset')); $this->writeTableInOutputFormat($input, $output, $this->formatJobs($jobs)); return 0; } diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index 494735ad873..67b736b8dd9 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -157,11 +157,20 @@ class JobList implements IJobList { return (bool) $row; } + public function getJobs($job, ?int $limit, int $offset): array { + $iterable = $this->getJobsIterator($job, $limit, $offset); + if (is_array($iterable)) { + return $iterable; + } else { + return iterator_to_array($iterable); + } + } + /** * @param IJob|class-string<IJob>|null $job * @return iterable<IJob> Avoid to store these objects as they may share a Singleton instance. You should instead use these IJobs instances while looping on the iterable. */ - public function getJobs($job, ?int $limit, int $offset): iterable { + public function getJobsIterator($job, ?int $limit, int $offset): iterable { $query = $this->connection->getQueryBuilder(); $query->select('*') ->from('jobs') diff --git a/lib/public/BackgroundJob/IJobList.php b/lib/public/BackgroundJob/IJobList.php index 0b32607feb6..e8d0380e604 100644 --- a/lib/public/BackgroundJob/IJobList.php +++ b/lib/public/BackgroundJob/IJobList.php @@ -79,10 +79,20 @@ interface IJobList { * Get jobs matching the search * * @param IJob|class-string<IJob>|null $job - * @return iterable<IJob> + * @return array<IJob> * @since 25.0.0 + * @deprecated 26.0.0 Use getJobsIterator instead to avoid duplicated job objects + */ + public function getJobs($job, ?int $limit, int $offset): array; + + /** + * Get jobs matching the search + * + * @param IJob|class-string<IJob>|null $job + * @return iterable<IJob> + * @since 26.0.0 */ - public function getJobs($job, ?int $limit, int $offset): iterable; + public function getJobsIterator($job, ?int $limit, int $offset): iterable; /** * get the next job in the list diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php index 4d14ed9e7db..be48259789a 100644 --- a/tests/lib/BackgroundJob/DummyJobList.php +++ b/tests/lib/BackgroundJob/DummyJobList.php @@ -72,7 +72,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList { return $this->jobs; } - public function getJobs($job, ?int $limit, int $offset): array { + public function getJobsIterator($job, ?int $limit, int $offset): array { if ($job instanceof IJob) { $jobClass = get_class($job); } else { diff --git a/tests/lib/BackgroundJob/JobListTest.php b/tests/lib/BackgroundJob/JobListTest.php index 62f04509068..ea02e1cd8b9 100644 --- a/tests/lib/BackgroundJob/JobListTest.php +++ b/tests/lib/BackgroundJob/JobListTest.php @@ -54,7 +54,7 @@ class JobListTest extends TestCase { } protected function getAllSorted() { - $iterator = $this->instance->getJobs(null, null, 0); + $iterator = $this->instance->getJobsIterator(null, null, 0); $jobs = []; foreach ($iterator as $job) { |