Skip to content

Commit bd3df75

Browse files
committed
occ background-job:delete
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 2560f6e commit bd3df75

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

core/Command/Background/Delete.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2024, Maxence Lange <maxence@artificial-owl.com>
6+
*
7+
* @author Maxence Lange <maxence@artificial-owl.com>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OC\Core\Command\Background;
27+
28+
use OC\Core\Command\Base;
29+
use OCP\BackgroundJob\IJobList;
30+
use Symfony\Component\Console\Input\InputArgument;
31+
use Symfony\Component\Console\Input\InputInterface;
32+
use Symfony\Component\Console\Output\OutputInterface;
33+
use Symfony\Component\Console\Question\ConfirmationQuestion;
34+
35+
class Delete extends Base {
36+
public function __construct(
37+
protected IJobList $jobList,
38+
) {
39+
parent::__construct();
40+
}
41+
42+
protected function configure(): void {
43+
$this
44+
->setName('background-job:delete')
45+
->setDescription('Remove a background job from database')
46+
->addArgument(
47+
'job-id',
48+
InputArgument::REQUIRED,
49+
'The ID of the job in the database'
50+
);
51+
}
52+
53+
protected function execute(InputInterface $input, OutputInterface $output): int {
54+
$jobId = (int) $input->getArgument('job-id');
55+
56+
$job = $this->jobList->getById($jobId);
57+
if ($job === null) {
58+
$output->writeln('<error>Job with ID ' . $jobId . ' could not be found in the database</error>');
59+
return 1;
60+
}
61+
62+
$output->writeln('Job class: ' . get_class($job));
63+
$output->writeln('Arguments: ' . json_encode($job->getArgument()));
64+
$output->writeln('');
65+
66+
$question = new ConfirmationQuestion(
67+
'<comment>Do you really want to delete this background job ? It could create some misbehaviours in Nextcloud.</comment> (y/N) ', false,
68+
'/^(y|Y)/i'
69+
);
70+
71+
$helper = $this->getHelper('question');
72+
if (!$helper->ask($input, $output, $question)) {
73+
$output->writeln('aborted.');
74+
return 0;
75+
}
76+
77+
$this->jobList->remove($job, $job->getArgument());
78+
return 0;
79+
}
80+
}

core/register_command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
$application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig()));
9393
$application->add(new OC\Core\Command\Background\Job(\OC::$server->getJobList(), \OC::$server->getLogger()));
9494
$application->add(new OC\Core\Command\Background\ListCommand(\OC::$server->getJobList()));
95+
$application->add(\OCP\Server::get(\OC\Core\Command\Background\Delete::class));
9596

9697
$application->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class));
9798

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@
10231023
'OC\\Core\\Command\\Background\\Ajax' => $baseDir . '/core/Command/Background/Ajax.php',
10241024
'OC\\Core\\Command\\Background\\Base' => $baseDir . '/core/Command/Background/Base.php',
10251025
'OC\\Core\\Command\\Background\\Cron' => $baseDir . '/core/Command/Background/Cron.php',
1026+
'OC\\Core\\Command\\Background\\Delete' => $baseDir . '/core/Command/Background/Delete.php',
10261027
'OC\\Core\\Command\\Background\\Job' => $baseDir . '/core/Command/Background/Job.php',
10271028
'OC\\Core\\Command\\Background\\ListCommand' => $baseDir . '/core/Command/Background/ListCommand.php',
10281029
'OC\\Core\\Command\\Background\\WebCron' => $baseDir . '/core/Command/Background/WebCron.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
10561056
'OC\\Core\\Command\\Background\\Ajax' => __DIR__ . '/../../..' . '/core/Command/Background/Ajax.php',
10571057
'OC\\Core\\Command\\Background\\Base' => __DIR__ . '/../../..' . '/core/Command/Background/Base.php',
10581058
'OC\\Core\\Command\\Background\\Cron' => __DIR__ . '/../../..' . '/core/Command/Background/Cron.php',
1059+
'OC\\Core\\Command\\Background\\Delete' => __DIR__ . '/../../..' . '/core/Command/Background/Delete.php',
10591060
'OC\\Core\\Command\\Background\\Job' => __DIR__ . '/../../..' . '/core/Command/Background/Job.php',
10601061
'OC\\Core\\Command\\Background\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/Background/ListCommand.php',
10611062
'OC\\Core\\Command\\Background\\WebCron' => __DIR__ . '/../../..' . '/core/Command/Background/WebCron.php',

0 commit comments

Comments
 (0)