Browse Source
Fix API breakage by using a new method instead
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/36073/head
Côme Chilliet
3 years ago
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
5 changed files with
25 additions and
6 deletions
-
core/Command/Background/ListCommand.php
-
lib/private/BackgroundJob/JobList.php
-
lib/public/BackgroundJob/IJobList.php
-
tests/lib/BackgroundJob/DummyJobList.php
-
tests/lib/BackgroundJob/JobListTest.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; |
|
|
|
} |
|
|
|
|
|
|
|
@ -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') |
|
|
|
|
|
|
|
@ -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 |
|
|
|
|
|
|
|
@ -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 { |
|
|
|
|
|
|
|
@ -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) { |
|
|
|
|