ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPluginAdmin.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Component/classes/class.ilComponent.php");
6
18{
19
23 protected $data;
27 protected $got_data = false;
33 public static $active_plugins = array();
39 protected static $plugin_objects = array();
43 protected $lng;
44
45
49 public function __construct()
50 {
51 global $DIC;
52 $this->lng = $DIC->language();
53 $this->lng->loadLanguageModule("cmps");
54 }
55
56
67 private function getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname)
68 {
69 if (!isset($this->got_data[$a_ctype][$a_cname][$a_slot_id][$a_pname])) {
70 $slot_name = ilPluginSlot::lookupSlotName($a_ctype, $a_cname, $a_slot_id);
71
72 $plugin_php_file = "./Customizing/global/plugins/" . $a_ctype . "/" . $a_cname . "/" . $slot_name . "/" . $a_pname . "/plugin.php";
73
74 if (!is_file($plugin_php_file)) {
75 throw new ilPluginException("No plugin.php file found for Plugin :" . $a_pname . ".");
76 }
77
78 $plugin_db_data = ilPlugin::getPluginRecord($a_ctype, $a_cname, $a_slot_id, $a_pname);
79 $plugin_data = $this->parsePluginPhp($plugin_php_file);
80
81 if ($plugin_db_data["plugin_id"] === null) {
82 $this->setMustInstall($plugin_data);
83 } else {
84 $this->setCurrentState($plugin_data, (bool) $plugin_db_data["active"]);
85 if ($this->pluginSupportCurrentILIAS($plugin_data)) {
86 $this->updateRequired($plugin_data, $plugin_db_data["last_update_version"]);
87 }
88 }
89
90 $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname] = $plugin_data;
91 $this->got_data[$a_ctype][$a_cname][$a_slot_id][$a_pname] = true;
92 }
93 }
94
95
103 protected function pluginSupportCurrentILIAS(array &$plugin_data)
104 {
105 if (ilComponent::isVersionGreaterString($plugin_data["ilias_min_version"], ILIAS_VERSION_NUMERIC)) {
106 $plugin_data["is_active"] = false;
107 $plugin_data["needs_update"] = false;
108 $plugin_data["activation_possible"] = false;
109
110 if ($this->lng instanceof ilLanguage) {
111 $inactive_reason = $this->lng->txt("cmps_needs_newer_ilias_version");
112 } else {
113 $inactive_reason = "Plugin needs a newer version of ILIAS.";
114 }
115 $plugin_data["inactive_reason"] = $inactive_reason;
116
117 return false;
118 }
119
120 if (ilComponent::isVersionGreaterString(ILIAS_VERSION_NUMERIC, $plugin_data["ilias_max_version"])) {
121 $plugin_data["is_active"] = false;
122 $plugin_data["needs_update"] = false;
123 $plugin_data["activation_possible"] = false;
124 if ($this->lng instanceof ilLanguage) {
125 $inactive_reason = $this->lng->txt("cmps_needs_newer_plugin_version");
126 } else {
127 $inactive_reason = "Plugin does not support current version of ILIAS. Newer version of plugin needed.";
128 }
129 $plugin_data["inactive_reason"] = $inactive_reason;
130
131 return false;
132 }
133
134 return true;
135 }
136
137
146 protected function updateRequired(array &$plugin_data, $last_update_version)
147 {
148 if ($last_update_version == "") {
149 $plugin_data["is_active"] = false;
150 if ($this->lng instanceof ilLanguage) {
151 $inactive_reason = $this->lng->txt("cmps_needs_update");
152 } else {
153 $inactive_reason = "Update needed.";
154 }
155 $plugin_data["inactive_reason"] = $inactive_reason;
156 $plugin_data["needs_update"] = true;
157 $plugin_data["activation_possible"] = false;
158 } else {
159 if (ilComponent::isVersionGreaterString($last_update_version, $plugin_data["version"])) {
160 $plugin_data["is_active"] = false;
161 if ($this->lng instanceof ilLanguage) {
162 $inactive_reason = $this->lng->txt("cmps_needs_upgrade");
163 } else {
164 $inactive_reason = "Upgrade needed.";
165 }
166 $plugin_data["inactive_reason"] = $inactive_reason;
167 $plugin_data["activation_possible"] = false;
168 } else {
169 if ($last_update_version != $plugin_data["version"]) {
170 $plugin_data["is_active"] = false;
171 if ($this->lng instanceof ilLanguage) {
172 $inactive_reason = $this->lng->txt("cmps_needs_update");
173 } else {
174 $inactive_reason = "Update needed.";
175 }
176 $plugin_data["inactive_reason"] = $inactive_reason;
177 $plugin_data["needs_update"] = true;
178 $plugin_data["activation_possible"] = false;
179 }
180 }
181 }
182 }
183
184
192 protected function setMustInstall(array &$plugin_data)
193 {
194 $plugin_data["must_install"] = true;
195 $plugin_data["is_active"] = false;
196 $plugin_data["needs_update"] = false;
197 $plugin_data["activation_possible"] = false;
198
199 if ($this->lng instanceof ilLanguage) {
200 $inactive_reason = $this->lng->txt("cmps_must_installed");
201 } else {
202 $inactive_reason = "Plugin must be installed.";
203 }
204 $plugin_data["inactive_reason"] = $inactive_reason;
205 }
206
207
218 protected function setCurrentState(array &$plugin_data, $active)
219 {
220 $plugin_data["is_active"] = $active;
221 $plugin_data["activation_possible"] = !$active;
222 $plugin_data["must_install"] = false;
223 $plugin_data["needs_update"] = false;
224 $plugin_data["inactive_reason"] = "";
225 }
226
227
235 protected function parsePluginPhp($plugin_php_file)
236 {
237 include($plugin_php_file);
238
239 $values = [
240 "version" => $version,
241 "id" => $id,
242 "ilias_min_version" => $ilias_min_version,
243 "ilias_max_version" => $ilias_max_version,
244 "responsible" => $responsible,
245 "responsible_mail" => $responsible_mail,
246 "learning_progress" => (bool) $learning_progress,
247 "supports_export" => (bool) $supports_export,
248 ];
249
250 return $values;
251 }
252
253
265 public function getVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
266 {
267 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
268
269 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["version"];
270 }
271
272
284 public function getIliasMinVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
285 {
286 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
287
288 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["ilias_min_version"];
289 }
290
291
303 public function getIliasMaxVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
304 {
305 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
306
307 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["ilias_max_version"];
308 }
309
310
322 public function getId($a_ctype, $a_cname, $a_slot_id, $a_pname)
323 {
324 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
325
326 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["id"];
327 }
328
329
340 public function isActive($a_ctype, $a_cname, $a_slot_id, $a_pname)
341 {
342 try {
343 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
344 } catch (ilPluginException $e) {
345 return false;
346 }
347
348 return (bool) $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["is_active"];
349 }
350
351
363 public function exists($a_ctype, $a_cname, $a_slot_id, $a_pname)
364 {
365 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
366
367 return isset($this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]);
368 }
369
370
382 public function needsUpdate($a_ctype, $a_cname, $a_slot_id, $a_pname)
383 {
384 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
385
386 return (bool) $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["needs_update"];
387 }
388
389
401 public function getAllData($a_ctype, $a_cname, $a_slot_id, $a_pname)
402 {
403 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
404
405 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname];
406 }
407
408
418 public static function getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
419 {
420 // cache the list of active plugins
421 if (!isset(self::$active_plugins[$a_ctype][$a_cname][$a_slot_id])) {
422 self::$active_plugins[$a_ctype][$a_cname][$a_slot_id]
423 = ilPlugin::getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id);
424 }
425
426 return self::$active_plugins[$a_ctype][$a_cname][$a_slot_id];
427 }
428
429
440 public static function getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
441 {
442 // cache the plugin objects
443 if (!isset(self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname])) {
444 self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname]
445 = ilPlugin::getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname);
446 }
447
448 return self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname];
449 }
450
451
464 public static function includeClass($a_ctype, $a_cname, $a_slot_id, $a_pname, $a_class_file_name)
465 {
466 // cache the plugin objects
467 if (!isset(self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname])) {
468 self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname]
469 = ilPlugin::getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname);
470 }
474 $pl = self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname];
475 $pl->includeClass($a_class_file_name);
476 }
477
478
490 public function hasLearningProgress($a_ctype, $a_cname, $a_slot_id, $a_pname)
491 {
492 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
493
494 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["learning_progress"];
495 }
496
497
509 public function supportsExport($a_ctype, $a_cname, $a_slot_id, $a_pname)
510 {
511 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
512
513 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["supports_export"];
514 }
515
516
522 public static function getAllPlugins()
523 {
524 static $all_plugins;
525 if (!isset($all_plugins)) {
526 $cached_component = ilCachedComponentData::getInstance();
527 $all_plugins = $cached_component->getIlPluginById();
528 }
529
530 return $all_plugins;
531 }
532
533
539 public static function getActivePlugins()
540 {
541 static $active_plugins;
542 if (!isset($active_plugins)) {
543 $cached_component = ilCachedComponentData::getInstance();
544 $plugins = $cached_component->getIlPluginActive();
545 $buf = array();
546 foreach ($plugins as $slot => $plugs) {
547 $buf[] = $plugs;
548 }
549
550 $active_plugins = array_merge([], ...$buf);
551 }
552
553 return $active_plugins;
554 }
555
556
564 public static function isPluginActive($id)
565 {
566 assert(is_string($id));
567 $cached_component = ilCachedComponentData::getInstance();
568 $plugs = $cached_component->getIlPluginById();
569 if (array_key_exists($id, $plugs) && $plugs[$id]['active']) {
570 return true;
571 }
572
573 return false;
574 }
575
576
585 public static function getPluginObjectById($id)
586 {
587 assert(is_string($id));
588 $plugs = self::getAllPlugins();
589 if (!array_key_exists($id, $plugs)) {
590 throw new \InvalidArgumentException("Plugin does not exist: " . $id, 1);
591 }
592 $pdata = $plugs[$id];
593
595 $pdata['component_type'],
596 $pdata['component_name'],
597 $pdata['slot_id'],
598 $pdata['name']
599 );
600 }
601
602
607 public static function getAllGlobalScreenProviders() : array
608 {
609 $providers = array();
610 // return array(); // current fix
611 foreach (self::getActivePlugins() as $plugin) {
612 $pl = self::getPluginObjectById($plugin['plugin_id']);
613 if ($pl->isActive()) {
614 array_push($providers, $pl->promoteGlobalScreenProvider());
615 }
616 }
617
618 return $providers;
619 }
620
621
625 public static function getGlobalScreenProviderCollections() : Generator
626 {
630 foreach (self::getActivePlugins() as $plugin) {
631 $pl = self::getPluginObjectById($plugin['plugin_id']);
632 if ($pl->isActive()) {
633 yield $pl->getGlobalScreenProviderCollection();
634 }
635 }
636 }
637}
An exception for terminatinating execution or to throw for unit testing.
static isVersionGreaterString($a_ver1, $a_ver2)
language handling
Administration class for plugins.
getVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get version of plugin.
exists($a_ctype, $a_cname, $a_slot_id, $a_pname)
Checks whether plugin exists.
static getAllGlobalScreenProviders()
parsePluginPhp($plugin_php_file)
Get informations from plugin php file.
getIliasMaxVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Ilias Max Version.
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
static isPluginActive($id)
Check, if a plugin is active.
static getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugins for a slot.
supportsExport($a_ctype, $a_cname, $a_slot_id, $a_pname)
Checks whether plugin supports export/import.
static getPluginObjectById($id)
Get a plugin-object by id.
hasLearningProgress($a_ctype, $a_cname, $a_slot_id, $a_pname)
Checks whether plugin has active learning progress.
static getActivePlugins()
Get info for all active plugins.
updateRequired(array &$plugin_data, $last_update_version)
Should the plugin be updated.
getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get basic data of plugin from plugin.php.
__construct()
ilPluginAdmin constructor.
getId($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get ID.
static getAllPlugins()
Get info for all plugins.
getAllData($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get all data from file in an array.
getIliasMinVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Ilias Min Version.
setMustInstall(array &$plugin_data)
Set plugin data for intall.
setCurrentState(array &$plugin_data, $active)
Set current state to static values, excluding active and activatoin possible.
pluginSupportCurrentILIAS(array &$plugin_data)
Plugin supports current ILIAS.
isActive($a_ctype, $a_cname, $a_slot_id, $a_pname)
Checks whether plugin is active (include version checks)
needsUpdate($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get version.
static lookupSlotName($a_ctype, $a_cname, $a_slot_id)
Lookup slot name for component and slot id.
static getPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
static getActivePluginsForSlot(string $a_ctype, string $a_cname, string $a_slot_id)
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
const ILIAS_VERSION_NUMERIC
$DIC
Definition: xapitoken.php:46