ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilGlobalCacheSetupAgent.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
22 use ILIAS\Refinery;
26 
27 class ilGlobalCacheSetupAgent implements Setup\Agent
28 {
29  protected \ILIAS\Refinery\Factory $refinery;
30 
31  public function __construct(
32  Refinery\Factory $refinery
33  ) {
34  $this->refinery = $refinery;
35  }
36 
40  public function hasConfig(): bool
41  {
42  return true;
43  }
44 
49  {
50  return $this->refinery->custom()->transformation(function ($data): \ilGlobalCacheSettingsAdapter {
51  $settings = new \ilGlobalCacheSettingsAdapter();
52  if (
53  $data === null ||
54  !isset($data["components"]) ||
55  !$data["components"] ||
56  !isset($data["service"]) ||
57  $data["service"] === "none" ||
58  (
59  $data["service"] === "memcached" &&
60  (!isset($data["memcached_nodes"]) || count($data["memcached_nodes"]) === 0)
61  )
62  ) {
63  $settings->setActive(false);
64  } else {
65  $settings->setActive(true);
66  switch ($data["service"]) {
67  case "xcache": // xcache has been removed in ILIAS 8, we switch to static cache then
68  case "static":
69  $settings->setService(\ILIAS\Cache\Config::PHPSTATIC);
70  break;
71  case "memcached":
72  array_walk($data["memcached_nodes"], function (array $node) use ($settings): void {
73  $settings->addMemcachedNode($this->convertNode($node));
74  });
75  $settings->setService(\ILIAS\Cache\Config::MEMCACHED);
76  break;
77  case "apc":
78  $settings->setService(\ILIAS\Cache\Config::APCU);
79  break;
80  default:
81  throw new \InvalidArgumentException(
82  sprintf("Unknown caching service: '%s'", $data["service"])
83  );
84  }
85  $settings->resetActivatedComponents();
86  if ($data["components"] === "all") {
87  $settings->activateAll();
88  } else {
89  foreach ($data["components"] as $cmp => $active) {
90  if ($active) {
91  $settings->addActivatedComponent($cmp);
92  }
93  }
94  }
95  }
96 
97  return $settings;
98  });
99  }
100 
101  protected function convertNode(array $node): Node
102  {
103  return new Node(
104  (string) $node["host"],
105  (int) $node["port"],
106  (int) $node["weight"]
107  );
108  }
109 
113  public function getInstallObjective(Setup\Config $config = null): Setup\Objective
114  {
115  if (!$config instanceof ilGlobalCacheSettingsAdapter) {
116  throw new Setup\UnachievableException('wrong config type, expected ilGlobalCacheSettings');
117  }
118  return new ilGlobalCacheConfigStoredObjective($config);
119  }
120 
124  public function getUpdateObjective(Setup\Config $config = null): Setup\Objective
125  {
126  if ($config instanceof ilGlobalCacheSettingsAdapter) {
127  return new ilGlobalCacheConfigStoredObjective($config);
128  }
129  return new Setup\Objective\NullObjective();
130  }
131 
135  public function getBuildArtifactObjective(): Setup\Objective
136  {
137  return new Setup\Objective\NullObjective();
138  }
139 
143  public function getStatusObjective(Setup\Metrics\Storage $storage): Setup\Objective
144  {
145  return new ilGlobalCacheMetricsCollectedObjective($storage);
146  }
147 
151  public function getMigrations(): array
152  {
153  return [];
154  }
155 
156  public function getNamedObjectives(?Config $config = null): array
157  {
158  $config = $config ?? new ilGlobalCacheSettingsAdapter();
159  return [
160  'flushAll' => new ObjectiveConstructor(
161  'flushes all GlobalCaches.',
162  function () use ($config) {
163  return new ilGlobalCacheAllFlushedObjective($config);
164  }
165  )
166  ];
167  }
168 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:30
getStatusObjective(Setup\Metrics\Storage $storage)
Class ChatMainBarProvider .
getUpdateObjective(Setup\Config $config=null)
__construct(Refinery\Factory $refinery)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getInstallObjective(Setup\Config $config=null)
A transformation is a function from one datatype to another.
A configuration for the setup.
Definition: Config.php:26