ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
RunActiveJobsCommand.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 use ilCronStartUp;
30 use Exception;
32 
34 {
35  protected static $defaultName = 'run-jobs';
36 
38  private $style;
39 
40  protected function configure(): void
41  {
42  $this->setDescription('Runs cron jobs depending on the respective schedule');
43 
44  $this->addArgument('user', InputArgument::REQUIRED, 'The ILIAS user the script is executed with');
45  $this->addArgument('client_id', InputArgument::REQUIRED, 'The ILIAS client_id');
46  }
47 
48  protected function execute(InputInterface $input, OutputInterface $output): int
49  {
50  $this->style = new SymfonyStyle($input, $output);
51 
52  $cron = new ilCronStartUp(
53  $input->getArgument('client_id'),
54  $input->getArgument('user')
55  );
56 
57  try {
58  $cron->authenticate();
59 
60  $this->withAuthenticated($input, $output);
61 
62  $this->style->success('Success');
63 
64  return 0;
65  } catch (Exception $e) {
66  $this->style->error($e->getMessage());
67  $this->style->error($e->getTraceAsString());
68 
69  return 1;
70  } finally {
71  $cron->logout();
72  }
73  }
74 
75  private function withAuthenticated(InputInterface $input, OutputInterface $output): void
76  {
77  global $DIC;
78 
79  $strictCronManager = new ilStrictCliCronManager(
80  $DIC->cron()->manager()
81  );
82  $strictCronManager->runActiveJobs($DIC->user());
83  }
84 }
withAuthenticated(InputInterface $input, OutputInterface $output)
global $DIC
Definition: feed.php:28
execute(InputInterface $input, OutputInterface $output)
$cron
Definition: cron.php:26