blob: 23592a1bac9af9decf84b55c97a0697984744182 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
<?php
namespace Studip\Cli\Commands\Cronjobs;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CronjobExecute extends Command
{
protected static $defaultName = 'cronjobs:execute';
protected function configure(): void
{
$this->setDescription('Execute cronjob task.');
$this->setHelp('This command will execute a cronjob task.');
$this->addArgument('task_id', InputArgument::REQUIRED, 'Id of the desired cron job');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$task_id = $input->getArgument('task_id');
$task = \CronjobTask::find($task_id);
if (!$task) {
$output->writeln('<error>Unknown task id</error>');
return Command::FAILURE;
}
if (!file_exists($GLOBALS['STUDIP_BASE_PATH'] . '/' . $task->filename)) {
$output->writeln(sprintf('<error>Invalid task, unknown filename %s</error>', $task->filename));
return Command::FAILURE;
}
require_once $GLOBALS['STUDIP_BASE_PATH'] . '/' . $task->filename;
if (!class_exists('\\' . $task->class)) {
fwrite(STDOUT, 'Invalid task, unknown class "' . $task->class . '"' . PHP_EOL);
$output->writeln(sprintf('<error>Invalid task, unknown class %s</error>', $task->class));
return Command::FAILURE;
}
$task->engage('');
return Command::SUCCESS;
}
}
|