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