ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
class.ilBackgroundTasksConfigStoredObjective.php
Go to the documentation of this file.
1 <?php
2 
22 
24 {
25  public function __construct(protected ilBackgroundTasksSetupConfig $config)
26  {
27  }
28 
29  public function getHash(): string
30  {
31  return hash("sha256", self::class);
32  }
33 
34  public function getLabel(): string
35  {
36  return "Fill ini with settings for components/ILIAS/BackgroundTasks_";
37  }
38 
39  public function isNotable(): bool
40  {
41  return false;
42  }
43 
47  public function getPreconditions(Environment $environment): array
48  {
49  return [
51  ];
52  }
53 
54  public function achieve(Environment $environment): Environment
55  {
56  $ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
57 
58  if (!$ini->groupExists("background_tasks")) {
59  $ini->addGroup("background_tasks");
60  }
61 
62  if ($this->config->getType() === \ilBackgroundTasksSetupConfig::TYPE_ASYNCHRONOUS) {
63  $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
65  $io->inform('Asynchronous background tasks need SOAP administration to be enabled. Make sure to enable it in your configuarion.');
66  }
67 
68  $ini->setVariable("background_tasks", "concurrency", $this->config->getType());
69  $ini->setVariable("background_tasks", "number_of_concurrent_tasks", $this->config->getMaxCurrentTasks());
70 
71  if (!$ini->write()) {
72  throw new UnachievableException("Could not write ilias.ini.php");
73  }
74 
75  return $environment;
76  }
77 
81  public function isApplicable(Environment $environment): bool
82  {
83  $ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
84  if (!$ini->groupExists("background_tasks")) {
85  return true;
86  }
87  if ($ini->readVariable("background_tasks", "concurrency") !== $this->config->getType()) {
88  return true;
89  }
90  return $ini->readVariable("background_tasks", "number_of_concurrent_tasks") !== $this->config->getMaxCurrentTasks();
91  }
92 }
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:30
__construct(protected ilBackgroundTasksSetupConfig $config)
Signals that some goal won&#39;t be achievable by actions of the system ever.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
achieve(Environment $environment)
Objectives can be achieved.
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
isNotable()
Get to know if this is an interesting objective for a human.
$ini
Definition: raiseError.php:20