ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGlobalCacheSetupAgent.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31
33{
34 public function __construct(protected Factory $refinery)
35 {
36 }
37
41 public function hasConfig(): bool
42 {
43 return true;
44 }
45
50 {
51 return $this->refinery->custom()->transformation(function ($data): \ilGlobalCacheSettingsAdapter {
52 $settings = new \ilGlobalCacheSettingsAdapter();
53 if (
54 $data === null ||
55 !isset($data["components"]) ||
56 !$data["components"] ||
57 !isset($data["service"]) ||
58 $data["service"] === "none" ||
59 (
60 $data["service"] === "memcached" &&
61 (!isset($data["memcached_nodes"]) || count($data["memcached_nodes"]) === 0)
62 )
63 ) {
64 $settings->setActive(false);
65 } else {
66 $settings->setActive(true);
67 switch ($data["service"]) {
68 case "xcache": // xcache has been removed in ILIAS 8, we switch to static cache then
69 case "static":
70 $settings->setService(\ILIAS\Cache\Config::PHPSTATIC);
71 break;
72 case "memcached":
73 array_walk($data["memcached_nodes"], function (array $node) use ($settings): void {
74 $settings->addMemcachedNode($this->convertNode($node));
75 });
76 $settings->setService(\ILIAS\Cache\Config::MEMCACHED);
77 break;
78 case "apc":
79 $settings->setService(\ILIAS\Cache\Config::APCU);
80 break;
81 default:
82 throw new \InvalidArgumentException(
83 sprintf("Unknown caching service: '%s'", $data["service"])
84 );
85 }
86 $settings->resetActivatedComponents();
87 if ($data["components"] === "all") {
88 $settings->activateAll();
89 } else {
90 foreach ($data["components"] as $cmp => $active) {
91 if ($active) {
92 $settings->addActivatedComponent($cmp);
93 }
94 }
95 }
96 }
97
98 return $settings;
99 });
100 }
101
102 protected function convertNode(array $node): Node
103 {
104 return new Node(
105 (string) $node["host"],
106 (int) $node["port"],
107 (int) $node["weight"]
108 );
109 }
110
114 public function getInstallObjective(?Config $config = null): Objective
115 {
116 if (!$config instanceof ilGlobalCacheSettingsAdapter) {
117 throw new UnachievableException('wrong config type, expected ilGlobalCacheSettings');
118 }
119 return new ilGlobalCacheConfigStoredObjective($config);
120 }
121
125 public function getUpdateObjective(?Config $config = null): Objective
126 {
127 if ($config instanceof ilGlobalCacheSettingsAdapter) {
128 return new ilGlobalCacheConfigStoredObjective($config);
129 }
130 return new NullObjective();
131 }
132
136 public function getBuildObjective(): Objective
137 {
138 return new NullObjective();
139 }
140
144 public function getStatusObjective(Storage $storage): Objective
145 {
146 return new ilGlobalCacheMetricsCollectedObjective($storage);
147 }
148
152 public function getMigrations(): array
153 {
154 return [];
155 }
156
157 public function getNamedObjectives(?Config $config = null): array
158 {
159 $config ??= new ilGlobalCacheSettingsAdapter();
160 return [
161 'flushAll' => new ObjectiveConstructor(
162 'flushes all GlobalCaches.',
164 )
165 ];
166 }
167}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
A non-objective, nothing to do to achieve it...
Signals that some goal won't be achievable by actions of the system ever.
hasConfig()
Does this agent require a configuration?
__construct(protected Factory $refinery)
getArrayToConfigTransformation()
Agents must be able to tell how to create a configuration from a nested array.
getBuildObjective()
Get the goal the agent wants to achieve to build artifacts.
getUpdateObjective(?Config $config=null)
Get the goal the agent wants to achieve on update.The provided configuration is to be used to change ...
getNamedObjectives(?Config $config=null)
Gets all named objectives The keys of the returned array are the commands.
getInstallObjective(?Config $config=null)
Get the goals the agent wants to achieve on setup.The provided configuration is to be used to set acc...
A transformation is a function from one datatype to another.
A agent is some component that performs part of the setup process.
Definition: Agent.php:30
A configuration for the setup.
Definition: Config.php:27
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.