ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilBackgroundTasksConfigStoredObjective.php
Go to the documentation of this file.
1 <?php
2 
19 use ILIAS\Setup;
20 
21 class ilBackgroundTasksConfigStoredObjective implements Setup\Objective
22 {
24 
25  public function __construct(
27  ) {
28  $this->config = $config;
29  }
30 
31  public function getHash(): string
32  {
33  return hash("sha256", self::class);
34  }
35 
36  public function getLabel(): string
37  {
38  return "Fill ini with settings for Services/BackgroundTasks";
39  }
40 
41  public function isNotable(): bool
42  {
43  return false;
44  }
45 
49  public function getPreconditions(Setup\Environment $environment): array
50  {
51  return [
53  ];
54  }
55 
56  public function achieve(Setup\Environment $environment): Setup\Environment
57  {
58  $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
59 
60  if (!$ini->groupExists("background_tasks")) {
61  $ini->addGroup("background_tasks");
62  }
63 
64  if ($this->config->getType() === \ilBackgroundTasksSetupConfig::TYPE_ASYNCHRONOUS) {
65  $io = $environment->getResource(Setup\Environment::RESOURCE_ADMIN_INTERACTION);
67  $io->inform('Asynchronous background tasks need SOAP administration to be enabled. Make sure to enable it in your configuarion.');
68  }
69 
70  $ini->setVariable("background_tasks", "concurrency", $this->config->getType());
71  $ini->setVariable("background_tasks", "number_of_concurrent_tasks", $this->config->getMaxCurrentTasks());
72 
73  if (!$ini->write()) {
74  throw new Setup\UnachievableException("Could not write ilias.ini.php");
75  }
76 
77  return $environment;
78  }
79 
83  public function isApplicable(Setup\Environment $environment): bool
84  {
85  $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
86 
87  return
88  !$ini->groupExists("background_tasks") ||
89  $ini->readVariable("background_tasks", "concurrency") !== $this->config->getType() ||
90  $ini->readVariable("background_tasks", "number_of_concurrent_tasks") !== $this->config->getMaxCurrentTasks()
91  ;
92  }
93 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
$ini
Definition: raiseError.php:4