ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilChatroomSetupAgent.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 /* Copyright (c) 2020 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 use ILIAS\Setup;
7 use ILIAS\UI;
8 
9 class ilChatroomSetupAgent implements Setup\Agent
10 {
12 
13  const PORT_MIN = 1;
14  const PORT_MAX = 65535;
15 
16  public static $LOG_LEVELS = [
17  'emerg',
18  'alert',
19  'crit',
20  'error',
21  'warning',
22  'notice',
23  'info',
24  'debug',
25  'silly'
26  ];
27 
28  public static $INTERVALS = [
29  'days',
30  'weeks',
31  'months',
32  'years'
33  ];
34 
38  protected $refinery;
39 
41  {
42  $this->refinery = $refinery;
43  }
44 
48  public function hasConfig() : bool
49  {
50  return true;
51  }
52 
56  public function getConfigInput(Setup\Config $config = null) : UI\Component\Input\Field\Input
57  {
58  throw new \LogicException("Not yet implemented.");
59  }
60 
65  {
66  $levels = self::$LOG_LEVELS;
67  $intervals = self::$INTERVALS;
68  // TODO: clean this up
69  return $this->refinery->custom()->transformation(function ($data) use ($levels, $intervals) {
70  if (is_null($data)) {
71  return new Setup\NullConfig();
72  }
73 
74  $protocol = 'http';
75  if (isset($data['https']) && count($data['https']) > 0) {
76  $protocol = 'https';
77  }
78 
79  $deletion_interval = false;
80  if (isset($data['deletion_interval']) && count($data['deletion_interval']) > 0) {
81  $deletion_interval = true;
82  }
83 
84  $ilias_proxy = false;
85  if (isset($data['ilias_proxy']) && count($data['ilias_proxy']) > 0) {
86  $ilias_proxy = true;
87  }
88 
89  $client_proxy = false;
90  if (isset($data['client_proxy']) && count($data['client_proxy']) > 0) {
91  $client_proxy = true;
92  }
93 
94  if (!is_null($data['port']) && (int) $data['port'] < self::PORT_MIN || (int) $data['port'] > self::PORT_MAX) {
95  throw new InvalidArgumentException(
96  $data['port'] . ' is not a valid value for port. Please check your config file.'
97  );
98  }
99 
100  if ($data['log'] != '') {
101  if (!in_array($data['log_level'], $levels)) {
102  throw new InvalidArgumentException(
103  $data['log_level'] . ' is not a valid value for log_level. Please check your config file.'
104  );
105  }
106  }
107 
108  if ($deletion_interval) {
109  if (!in_array($data['deletion_interval']['deletion_unit'], $intervals)) {
110  throw new InvalidArgumentException(
111  $data['deletion_interval']['deletion_unit'] . ' is not a valid value for deletion_unit. Please check your config file.'
112  );
113  }
114  if (!is_numeric($data['deletion_interval']['deletion_value'])) {
115  throw new InvalidArgumentException(
116  $data['deletion_interval']['deletion_value'] . ' is not a valid value for deletion_value. Please check your config file.'
117  );
118  }
119  if (!preg_match_all('/([01][0-9]|[2][0-3]):[0-5][0-9]/', $data['deletion_interval']['deletion_time'])) {
120  throw new InvalidArgumentException(
121  $data['deletion_interval']['deletion_time'] . ' is not a valid value for deletion_time. Please check your config file.'
122  );
123  }
124  }
125 
126  return new \ilChatroomSetupConfig(
127  $data['address'] ?? '',
128  (int) $data['port'] ?? 0,
129  $data['sub_directory'] ?? '',
130  $protocol,
131  $data['https']['cert'] ?? '',
132  $data['https']['key'] ?? '',
133  $data['https']['dhparam'] ?? '',
134  $data['log'] ?? '',
135  $data['log_level'] ?? '',
136  $data['error_log'] ?? '',
137  $ilias_proxy,
138  $data['ilias_proxy']['ilias_url'] ?? '',
139  $client_proxy,
140  $data['client_proxy']['client_url'] ?? '',
141  $deletion_interval,
142  $data['deletion_interval']['deletion_unit'] ?? '',
143  (int) $data['deletion_interval']['deletion_value'] ?? 0,
144  $data['deletion_interval']['deletion_time'] ?? ''
145  );
146  });
147  }
148 
152  public function getInstallObjective(Setup\Config $config = null) : Setup\Objective
153  {
154  // null would not be valid here, because this agents strictly wants to have
155  // a config.
156  if ($config instanceof Setup\NullConfig) {
157  return new Setup\Objective\NullObjective();
158  }
159 
161  }
162 
166  public function getUpdateObjective(Setup\Config $config = null) : Setup\Objective
167  {
168  // null would be valid here, because our user might just not have passed
169  // one during update.
170  if ($config === null || $config instanceof Setup\NullConfig) {
171  return new Setup\Objective\NullObjective();
172  }
173 
175  }
176 
180  public function getBuildArtifactObjective() : Setup\Objective
181  {
182  return new Setup\Objective\NullObjective();
183  }
184 
188  public function getStatusObjective(Setup\Metrics\Storage $storage) : Setup\Objective
189  {
190  return new ilChatroomMetricsCollectedObjective($storage);
191  }
192 
196  public function getMigrations() : array
197  {
198  return [];
199  }
200 }
Class Factory.
$data
Definition: storeScorm.php:23
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:14
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
getUpdateObjective(Setup\Config $config=null)
__construct(Refinery\Factory $refinery)
getStatusObjective(Setup\Metrics\Storage $storage)
Builds data types.
Definition: Factory.php:19
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.
getInstallObjective(Setup\Config $config=null)
A configuration for the setup.
Definition: Config.php:10
A configuration with no content.
Definition: NullConfig.php:10