Code cleaning of Background/ListCommand

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/32552/head
Côme Chilliet 2022-06-27 11:53:10 +07:00 committed by Côme Chilliet (Rebase PR Action)
parent 3d01179907
commit 868d748dbf
3 changed files with 20 additions and 26 deletions

@ -2,9 +2,9 @@
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Joas Schilling <coding@schilljs.com>
* @copyright Copyright (c) 2022, Côme Chilliet <come.chilliet@nextcloud.com>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Côme Chilliet <come.chilliet@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
@ -26,26 +26,17 @@ declare(strict_types=1);
namespace OC\Core\Command\Background;
use OC\Core\Command\Base;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\IJobList;
use OCP\ILogger;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class ListCommand extends Base {
/** @var IJobList */
protected $jobList;
/** @var ILogger */
protected $logger;
protected IJobList $jobList;
public function __construct(IJobList $jobList,
ILogger $logger) {
public function __construct(IJobList $jobList) {
parent::__construct();
$this->jobList = $jobList;
$this->logger = $logger;
}
protected function configure(): void {
@ -83,7 +74,7 @@ class ListCommand extends Base {
protected function formatJobs(array $jobs): array {
return array_map(
fn($job) => [
fn ($job) => [
'id' => $job->getId(),
'class' => get_class($job),
'last_run' => $job->getLastRun(),

@ -40,7 +40,6 @@ use OCP\IConfig;
use OCP\IDBConnection;
class JobList implements IJobList {
protected IDBConnection $connection;
protected IConfig $config;
protected ITimeFactory $timeFactory;
@ -163,12 +162,16 @@ class JobList implements IJobList {
*
* @return IJob[]
* @deprecated 9.0.0 - This method is dangerous since it can cause load and
* memory problems when creating too many instances.
* memory problems when creating too many instances. Use getJobs instead.
*/
public function getAll() {
return $this->getJobs(null, null, 0);
}
/**
* @param IJob|class-string<IJob>|null $job
* @return IJob[]
*/
public function getJobs($job, ?int $limit, int $offset): array {
$query = $this->connection->getQueryBuilder();
$query->select('*')
@ -297,7 +300,7 @@ class JobList implements IJobList {
try {
// Try to load the job as a service
/** @var IJob $job */
$job = \OC::$server->get($row['class']);
$job = \OCP\Server::get($row['class']);
} catch (QueryException $e) {
if (class_exists($row['class'])) {
$class = $row['class'];

@ -47,7 +47,7 @@ interface IJobList {
/**
* Add a job to the list
*
* @param \OCP\BackgroundJob\IJob|string $job
* @param IJob|string $job
* @param mixed $argument The argument to be passed to $job->run() when the job is exectured
* @since 7.0.0
*/
@ -56,7 +56,7 @@ interface IJobList {
/**
* Remove a job from the list
*
* @param \OCP\BackgroundJob\IJob|string $job
* @param IJob|string $job
* @param mixed $argument
* @since 7.0.0
*/
@ -65,7 +65,7 @@ interface IJobList {
/**
* check if a job is in the list
*
* @param \OCP\BackgroundJob\IJob|string $job
* @param IJob|string $job
* @param mixed $argument
* @return bool
* @since 7.0.0
@ -75,18 +75,18 @@ interface IJobList {
/**
* get all jobs in the list
*
* @return \OCP\BackgroundJob\IJob[]
* @return IJob[]
* @since 7.0.0
* @deprecated 9.0.0 - This method is dangerous since it can cause load and
* memory problems when creating too many instances.
* memory problems when creating too many instances. Use getJobs instead.
*/
public function getAll();
/**
* Get jobs matching the search
*
* @param \OCP\BackgroundJob\IJob|class-string<IJob>|null $job
* @return \OCP\BackgroundJob\IJob[]
* @param IJob|class-string<IJob>|null $job
* @return IJob[]
* @since 25.0.0
*/
public function getJobs($job, ?int $limit, int $offset): array;
@ -95,14 +95,14 @@ interface IJobList {
* get the next job in the list
*
* @param bool $onlyTimeSensitive
* @return \OCP\BackgroundJob\IJob|null
* @return IJob|null
* @since 7.0.0 - In 24.0.0 parameter $onlyTimeSensitive got added
*/
public function getNext(bool $onlyTimeSensitive = false): ?IJob;
/**
* @param int $id
* @return \OCP\BackgroundJob\IJob|null
* @return IJob|null
* @since 7.0.0
*/
public function getById($id);