ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroomSetupAgent.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Setup;
25
27{
28 use Setup\Agent\HasNoNamedObjective;
29
30 private const int PORT_MIN = 1;
31 private const int PORT_MAX = 65535;
32
34 public static array $LOG_LEVELS = [
35 'emerg',
36 'alert',
37 'crit',
38 'error',
39 'warning',
40 'notice',
41 'info',
42 'debug',
43 'silly'
44 ];
45
47 public static array $INTERVALS = [
48 'days',
49 'weeks',
50 'months',
51 'years'
52 ];
53
54 public function __construct(protected Refinery\Factory $refinery)
55 {
56 }
57
58 public function hasConfig(): bool
59 {
60 return true;
61 }
62
63 public function getConfigInput(?Setup\Config $config = null): never
64 {
65 throw new LogicException("Not yet implemented.");
66 }
67
69 {
70 $levels = self::$LOG_LEVELS;
71 $intervals = self::$INTERVALS;
72
73 return $this->refinery->custom()->transformation(static function ($data) use (
74 $levels,
75 $intervals
76 ): Setup\Config {
77 if (is_null($data)) {
78 return new Setup\NullConfig();
79 }
80
81 $protocol = 'http';
82 if (isset($data['https']) && is_array($data['https']) && $data['https'] !== []) {
83 $protocol = 'https';
84 }
85
86 $deletion_interval = false;
87 if (
88 isset($data['deletion_interval']) &&
89 is_array($data['deletion_interval']) && $data['deletion_interval'] !== []
90 ) {
91 $deletion_interval = true;
92 }
93
94 $ilias_proxy = false;
95 if (isset($data['ilias_proxy']) && is_array($data['ilias_proxy']) && $data['ilias_proxy'] !== []) {
96 $ilias_proxy = true;
97 }
98
99 $client_proxy = false;
100 if (isset($data['client_proxy']) && is_array($data['client_proxy']) && $data['client_proxy'] !== []) {
101 $client_proxy = true;
102 }
103
104 if (isset($data['address']) && !is_string($data['address'])) {
105 throw new InvalidArgumentException(sprintf(
106 '%s is not a valid value for address (must be a string). Please check your config file.',
107 $data['address'],
108 ));
109 }
110
111 if (
112 isset($data['port']) && (
113 !is_numeric($data['port']) ||
114 ((int) $data['port'] < self::PORT_MIN || (int) $data['port'] > self::PORT_MAX)
115 )
116 ) {
117 throw new InvalidArgumentException(sprintf(
118 '%s is not a valid value for port (must be between %s and %s). Please check your config file.',
119 $data['port'] ?? '',
120 self::PORT_MIN,
121 self::PORT_MAX
122 ));
123 }
124
125 if (isset($data['sub_directory']) && !is_string($data['sub_directory'])) {
126 throw new InvalidArgumentException(sprintf(
127 '%s is not a valid value for sub_directory (must be a string). Please check your config file.',
128 $data['sub_directory'],
129 ));
130 }
131
132 if (isset($data['log']) && !is_string($data['log'])) {
133 throw new InvalidArgumentException(sprintf(
134 '%s is not a valid value for log (must be a string). Please check your config file.',
135 $data['log'],
136 ));
137 }
138
139 if (isset($data['error_log']) && !is_string($data['error_log'])) {
140 throw new InvalidArgumentException(sprintf(
141 '%s is not a valid value for error_log (must be a string). Please check your config file.',
142 $data['error_log'],
143 ));
144 }
145
146 if (
147 isset($data['log']) && $data['log'] !== '' &&
148 !in_array((string) ($data['log_level'] ?? ''), $levels, true)
149 ) {
150 throw new InvalidArgumentException(sprintf(
151 '%s is not a valid value for log_level (must be one of: %s). Please check your config file.',
152 $data['log_level'] ?? '',
153 implode(', ', $levels)
154 ));
155 }
156
157 if ($deletion_interval) {
158 if (!in_array($data['deletion_interval']['deletion_unit'] ?? null, $intervals, true)) {
159 throw new InvalidArgumentException(sprintf(
160 '%s is not a valid value for deletion_unit (must be one of: %s). Please check your config file.',
161 $data['deletion_interval']['deletion_unit'] ?? '',
162 implode(', ', $intervals)
163 ));
164 }
165 if (
166 !isset($data['deletion_interval']['deletion_value']) ||
167 !is_numeric($data['deletion_interval']['deletion_value'])
168 ) {
169 throw new InvalidArgumentException(sprintf(
170 '%s is not a valid value for deletion_value. Please check your config file.',
171 $data['deletion_interval']['deletion_value'] ?? ''
172 ));
173 }
174 if (
175 !isset($data['deletion_interval']['deletion_time']) ||
176 !is_string($data['deletion_interval']['deletion_time']) ||
177 !preg_match('/([01][0-9]|[2][0-3]):[0-5][0-9]/', $data['deletion_interval']['deletion_time'])
178 ) {
179 throw new InvalidArgumentException(sprintf(
180 '%s is not a valid value for deletion_time. Please check your config file.',
181 $data['deletion_interval']['deletion_time'] ?? ''
182 ));
183 }
184 }
185
186 return new ilChatroomSetupConfig(
187 $data['address'] ?? '',
188 (int) ($data['port'] ?? 0),
189 $data['sub_directory'] ?? '',
190 $protocol,
191 $data['https']['cert'] ?? '',
192 $data['https']['key'] ?? '',
193 $data['https']['dhparam'] ?? '',
194 $data['log'] ?? '',
195 $data['log_level'] ?? '',
196 $data['error_log'] ?? '',
197 $ilias_proxy,
198 $data['ilias_proxy']['ilias_url'] ?? '',
199 $client_proxy,
200 $data['client_proxy']['client_url'] ?? '',
201 $deletion_interval,
202 $data['deletion_interval']['deletion_unit'] ?? '',
203 (int) ($data['deletion_interval']['deletion_value'] ?? 0),
204 $data['deletion_interval']['deletion_time'] ?? ''
205 );
206 });
207 }
208
209 public function getInstallObjective(?Setup\Config $config = null): Setup\Objective
210 {
211 // null would not be valid here, because this agents strictly wants to have
212 // a config.
213 if ($config === null || $config instanceof Setup\NullConfig) {
215 }
216
217 return new ilChatroomServerConfigStoredObjective($config);
218 }
219
220 public function getUpdateObjective(?Setup\Config $config = null): Setup\Objective
221 {
222 $objectives = [
224 ];
225
226 // null would be valid here, because our user might just not have passed
227 // one during update.
228 if ($config !== null && !($config instanceof Setup\NullConfig)) {
230 }
231
232 return new ObjectiveCollection('Update chatroom database and server config', false, ...$objectives);
233 }
234
236 {
238 }
239
240 public function getStatusObjective(Setup\Metrics\Storage $storage): Setup\Objective
241 {
242 return new Setup\ObjectiveCollection(
243 'Component Chatroom',
244 true,
247 );
248 }
249
250 public function getMigrations(): array
251 {
252 return [];
253 }
254}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
A configuration with no content.
Definition: NullConfig.php:27
A objective collection is a objective that is achieved once all subobjectives are achieved.
A non-objective, nothing to do to achieve it...
getConfigInput(?Setup\Config $config=null)
getStatusObjective(Setup\Metrics\Storage $storage)
getUpdateObjective(?Setup\Config $config=null)
getInstallObjective(?Setup\Config $config=null)
__construct(protected Refinery\Factory $refinery)
This class attempt to achieve a set of database update steps.
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
Storage is simple key/value store without further schema definition.
Definition: Storage.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$objectives