-
Notifications
You must be signed in to change notification settings - Fork 407
Expand file tree
/
Copy pathclass.ilCommonSetupAgent.php
More file actions
executable file
·193 lines (175 loc) · 6.16 KB
/
class.ilCommonSetupAgent.php
File metadata and controls
executable file
·193 lines (175 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/
declare(strict_types=1);
use ILIAS\Setup;
use ILIAS\Refinery;
use ILIAS\Data;
use ILIAS\Setup\Config;
/**
* Contains common objectives for the setup. Do not make additions here, in
* general all this stuff here is supposed to go elsewhere once we find out
* which service it really belongs to.
*/
class ilCommonSetupAgent implements Setup\Agent
{
private const PHP_MEMORY_LIMIT = "128M";
private const PHP_MIN_VERSION = "8.4.0";
private const PHP_MAX_VERSION = "8.5.999";
protected Refinery\Factory $refinery;
protected Data\Factory $data;
public function __construct(
Refinery\Factory $refinery,
Data\Factory $data
) {
$this->refinery = $refinery;
$this->data = $data;
}
/**
* @inheritdoc
*/
public function hasConfig(): bool
{
return true;
}
/**
* @inheritdoc
*/
public function getArrayToConfigTransformation(): Refinery\Transformation
{
return $this->refinery->custom()->transformation(function ($data) {
$export_hooks_path = null;
if (key_exists("export_hooks_path", $data)) {
$export_hooks_path = $data["export_hooks_path"];
}
$datetimezone = $this->refinery->to()->toNew(\DateTimeZone::class);
return new \ilSetupConfig(
$this->data->clientId($data["client_id"] ?? ''),
$datetimezone->transform([$data["server_timezone"] ?? "UTC"]),
$data["register_nic"] ?? false,
$export_hooks_path
);
});
}
/**
* @inheritdoc
*/
public function getInstallObjective(?Setup\Config $config = null): Setup\Objective
{
return new Setup\Objective\ObjectiveWithPreconditions(
new \ilMakeInstallationAccessibleObjective($config),
new \ilOverwritesExistingInstallationConfirmed($config),
new Setup\ObjectiveCollection(
"Complete common ILIAS objectives.",
false,
new Setup\Condition\PHPVersionCondition(self::PHP_MIN_VERSION, self::PHP_MAX_VERSION, true),
new Setup\Condition\PHPExtensionLoadedCondition("dom"),
new Setup\Condition\PHPExtensionLoadedCondition("xsl"),
new Setup\Condition\PHPExtensionLoadedCondition("gd"),
$this->getPHPMemoryLimitCondition(),
new ilSetupConfigStoredObjective($config),
new ilNICKeyRegisteredObjective($config)
)
);
}
protected function getPHPMemoryLimitCondition(): Setup\Objective
{
return new Setup\Condition\ExternalConditionObjective(
"PHP memory limit >= " . self::PHP_MEMORY_LIMIT,
function (Setup\Environment $env): bool {
$limit = ini_get("memory_limit");
if ($limit == -1) {
return true;
}
$expected = $this->data->dataSize(self::PHP_MEMORY_LIMIT);
$current = $this->data->dataSize($limit);
return $current->inBytes() >= $expected->inBytes();
},
"To properly execute ILIAS, please take care that the PHP memory limit is at least set to 128M."
);
}
/**
* @inheritdoc
*/
public function getUpdateObjective(?Setup\Config $config = null): Setup\Objective
{
$objectives = [
new Setup\Objective\ObjectiveWithPreconditions(
new ilVersionWrittenToSettingsObjective($this->data),
new Setup\Condition\PHPVersionCondition(self::PHP_MIN_VERSION, self::PHP_MAX_VERSION, true),
new ilNoMajorVersionSkippedConditionObjective($this->data),
new ilNoVersionDowngradeConditionObjective($this->data)
)
];
if ($config !== null) {
$objectives[] = new ilSetupConfigStoredObjective($config);
$objectives[] = new ilNICKeyRegisteredObjective($config);
}
return new Setup\ObjectiveCollection(
"Complete common ILIAS objectives.",
false,
...$objectives
);
}
/**
* @inheritdoc
*/
public function getBuildObjective(): Setup\Objective
{
return new Setup\Objective\NullObjective();
}
/**
* @inheritdoc
*/
public function getStatusObjective(Setup\Metrics\Storage $storage): Setup\Objective
{
return new ilSetupMetricsCollectedObjective($storage);
}
/**
* @inheritDoc
*/
public function getMigrations(): array
{
return [];
}
public function getNamedObjectives(?Config $config = null): array
{
return [
"registerNICKey" => new Setup\ObjectiveConstructor(
"Register NIC key",
static function () use ($config): Setup\Objective {
if (is_null($config)) {
throw new \RuntimeException(
"Missing Config for objective 'registerNICKey'."
);
}
return new ilNICKeyRegisteredObjective($config);
}
),
"buildExportZip" => new Setup\ObjectiveConstructor(
"Build ILIAS export zip",
static function () use ($config): Setup\Objective {
if (is_null($config)) {
throw new \RuntimeException(
"Missing Config for objective 'buildExportZip'."
);
}
return new ilExportZipBuiltObjective($config);
}
)
];
}
}