Completed
Pull Request — master (#24551)
by Thomas
19:32 queued 48s
created

Delete::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace OC\Core\Command\Background\Queue;
4
5
use OCP\BackgroundJob\IJobList;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class Delete extends Command {
12
13
	/** @var \OCP\BackgroundJob\IJobList */
14
	private $jobList;
15
16
	public function __construct(IJobList $jobList) {
17
		$this->jobList = $jobList;
18
		parent::__construct();
19
	}
20
21
	protected function configure() {
22
		$this
23
			->setName('background:queue:delete')
24
			->setDescription('Delete a job from the queue')
25
			->addArgument('id', InputArgument::REQUIRED, 'id of the job to be deleted');
26
	}
27
28
	/**
29
	 * @param InputInterface $input
30
	 * @param OutputInterface $output
31
	 * @return void
32
	 */
33
	protected function execute(InputInterface $input, OutputInterface $output) {
34
		$id = $input->getArgument('id');
35
36
		$job = $this->jobList->getById($id);
37
		if ($job === null) {
38
			$output->writeln("Job with id <$id> is not known.");
39
			return;
40
		}
41
42
		$this->jobList->removeById($id);
43
		$output->writeln('Job has been deleted.');
44
	}
45
}
46