ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilPluginInfo.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
30 protected string $id;
31 protected string $name;
32 protected string $type;
33 protected bool $activated;
35 protected ?int $current_db_version;
39 protected string $responsible;
40 protected string $responsible_mail;
42 protected bool $supports_export;
43 protected bool $supports_cli_setup;
44
45 public function __construct(
48 string $id,
49 string $name,
50 string $type,
51 bool $activated,
57 string $responsible,
58 string $responsible_mail,
62 ) {
63 if ($current_version === null && $current_db_version !== null) {
64 throw new \InvalidArgumentException(
65 "If there is no current version for the plugin, we also should not " .
66 "have a db-version."
67 );
68 }
69 $this->actual_ilias_version = $actual_ilias_version;
70 $this->pluginslot = $pluginslot;
71 $this->id = $id;
72 $this->name = $name;
73 $this->type = $type;
74 $this->activated = $activated;
75 $this->current_version = $current_version;
76 $this->current_db_version = $current_db_version;
77 $this->available_version = $available_version;
78 $this->minimum_ilias_version = $minimum_ilias_version;
79 $this->maximum_ilias_version = $maximum_ilias_version;
80 $this->responsible = $responsible;
81 $this->responsible_mail = $responsible_mail;
82 $this->supports_learning_progress = $supports_learning_progress;
83 $this->supports_export = $supports_export;
84 $this->supports_cli_setup = $supports_cli_setup;
85 }
86
88 {
89 return $this->pluginslot;
90 }
91
92 public function getComponent(): ilComponentInfo
93 {
94 return $this->pluginslot->getComponent();
95 }
96
97 public function getId(): string
98 {
99 return $this->id;
100 }
101
102 public function getName(): string
103 {
104 return $this->name;
105 }
106
107 public function getType(): string
108 {
109 return $this->type;
110 }
111
112 public function getPath(): string
113 {
114 return $this->normalizePath(
115 implode('/', [
117 $this->getType(),
118 $this->getComponent()->getName(),
119 $this->getPluginSlot()->getName(),
120 $this->getName()
121 ])
122 );
123 }
124
132 protected function normalizePath(string $path): string
133 {
134 $segments = [];
135 foreach (explode('/', $path) as $segment) {
136 if ($segment === '' || $segment === '.') {
137 continue;
138 }
139 if ($segment === '..' && $segments !== [] && end($segments) !== '..') {
140 array_pop($segments);
141 continue;
142 }
143 $segments[] = $segment;
144 }
145
146 return (str_starts_with($path, '/') ? '/' : '') . implode('/', $segments);
147 }
148
149 public function getClassName(): string
150 {
151 return "il" . $this->getName() . "Plugin";
152 }
153
154 public function getConfigGUIClassName(): string
155 {
156 return "il" . $this->getName() . "ConfigGUI";
157 }
158
163 public function isActivated(): bool
164 {
165 return $this->activated;
166 }
167
168 public function getCurrentVersion(): ?Version
169 {
171 }
172
173 public function getCurrentDBVersion(): ?int
174 {
176 }
177
178 public function getAvailableVersion(): Version
179 {
181 }
182
184 {
186 }
187
189 {
191 }
192
193 public function getResponsible(): string
194 {
195 return $this->responsible;
196 }
197
198 public function getResponsibleMail(): string
199 {
201 }
202
203 public function supportsLearningProgress(): bool
204 {
206 }
207
208 public function supportsExport(): bool
209 {
211 }
212
213 public function supportsCLISetup(): bool
214 {
216 }
217
221 public function isInstalled(): bool
222 {
223 return $this->current_version !== null;
224 }
225
229 public function isUpdateRequired(): bool
230 {
231 return $this->isInstalled() && !$this->current_version->equals($this->available_version);
232 }
233
238 public function isVersionToOld(): bool
239 {
240 return $this->current_version->isGreaterThan($this->available_version);
241 }
242
247 public function isCompliantToILIAS(): bool
248 {
249 return
250 $this->actual_ilias_version->isGreaterThanOrEquals($this->minimum_ilias_version)
251 && $this->actual_ilias_version->isSmallerThanOrEquals($this->maximum_ilias_version);
252 }
253
257 public function isActivationPossible(): bool
258 {
259 return $this->isCompliantToILIAS()
260 && $this->isInstalled()
261 && !$this->isVersionToOld()
262 && !$this->isUpdateRequired();
263 }
264
268 public function isActive(): bool
269 {
270 return $this->isActivationPossible()
271 && $this->isActivated();
272 }
273
280 public function getReasonForInactivity(): string
281 {
282 if ($this->isActive()) {
283 throw new \LogicException(
284 "Plugin is active, so no reason for inactivity."
285 );
286 }
287
288 if (!$this->isCompliantToILIAS()) {
289 return "cmps_needs_matching_ilias_version";
290 }
291
292 if (!$this->isInstalled()) {
293 return "cmps_must_installed";
294 }
295
296 if ($this->isVersionToOld()) {
297 return "cmps_needs_upgrade";
298 }
299
300 if ($this->isUpdateRequired()) {
301 return "cmps_needs_update";
302 }
303
304 if (!$this->isActivated()) {
305 return "cmps_not_activated";
306 }
307
308 throw new \LogicException(
309 "Unknown reason for inactivity of the plugin."
310 );
311 }
312}
A version number that consists of three numbers (major, minor, patch).
Definition: Version.php:27
Simple value class for basic information about a component.
Simple value class for information about a plugin.
isInstalled()
"Installed" tells if the plugin has some installed version.
isActive()
Is this plugin active right now?
getReasonForInactivity()
Which is the reason for the inactivity?
Version $maximum_ilias_version
isCompliantToILIAS()
"ILIAS Version compliance" tells if the plugin can be operated with the given ILIAS version.
isActivationPossible()
Can this plugin be activated right now.
Version $available_version
bool $supports_learning_progress
ilPluginSlotInfo $pluginslot
Version $current_version
isUpdateRequired()
"Update required" tells if the plugin needs an update.
normalizePath(string $path)
Resolves "." and ".." segments without touching the file system, so it also works for plugins which a...
Version $minimum_ilias_version
isActivated()
"activated" tells if the administrator of the installation wants the plugin to be effective.
__construct(Version $actual_ilias_version, ilPluginSlotInfo $pluginslot, string $id, string $name, string $type, bool $activated, ?Version $current_version, ?int $current_db_version, Version $available_version, Version $minimum_ilias_version, Version $maximum_ilias_version, string $responsible, string $responsible_mail, bool $supports_learning_progress, bool $supports_export, bool $supports_cli_setup)
Version $actual_ilias_version
isVersionToOld()
"Version to old" tells if the plugin code has a version that is below the version that was updated la...
Simple value class for basic information about a pluginslot.