ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $plugin_db_data = ilPlugin::getPluginRecord($a_ctype, $a_cname, $a_slot_id, $a_pname);
78 $plugin_data = $this->parsePluginPhp($plugin_php_file);
79
80 if ($plugin_db_data["plugin_id"] === null) {
81 $this->setMustInstall($plugin_data);
82 } else {
83 $this->setCurrentState($plugin_data, (bool) $plugin_db_data["active"]);
84 if ($this->pluginSupportCurrentILIAS($plugin_data)) {
85 $this->updateRequired($plugin_data, $plugin_db_data["last_update_version"]);
86 }
87 }
88
89 $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname] = $plugin_data;
90 $this->got_data[$a_ctype][$a_cname][$a_slot_id][$a_pname] = true;
91 }
92 }
93
94
102 protected function pluginSupportCurrentILIAS(array &$plugin_data)
103 {
104 if (ilComponent::isVersionGreaterString($plugin_data["ilias_min_version"], ILIAS_VERSION_NUMERIC)) {
105 $plugin_data["is_active"] = false;
106 $plugin_data["needs_update"] = false;
107 $plugin_data["activation_possible"] = false;
108
109 if ($this->lng instanceof ilLanguage) {
110 $inactive_reason = $this->lng->txt("cmps_needs_newer_ilias_version");
111 } else {
112 $inactive_reason = "Plugin needs a newer version of ILIAS.";
113 }
114 $plugin_data["inactive_reason"] = $inactive_reason;
115
116 return false;
117 }
118
119 if (ilComponent::isVersionGreaterString(ILIAS_VERSION_NUMERIC, $plugin_data["ilias_max_version"])) {
120 $plugin_data["is_active"] = false;
121 $plugin_data["needs_update"] = false;
122 $plugin_data["activation_possible"] = false;
123 if ($this->lng instanceof ilLanguage) {
124 $inactive_reason = $this->lng->txt("cmps_needs_newer_plugin_version");
125 } else {
126 $inactive_reason = "Plugin does not support current version of ILIAS. Newer version of plugin needed.";
127 }
128 $plugin_data["inactive_reason"] = $inactive_reason;
129
130 return false;
131 }
132
133 return true;
134 }
135
136
145 protected function updateRequired(array &$plugin_data, $last_update_version)
146 {
147 if ($last_update_version == "") {
148 $plugin_data["is_active"] = false;
149 if ($this->lng instanceof ilLanguage) {
150 $inactive_reason = $this->lng->txt("cmps_needs_update");
151 } else {
152 $inactive_reason = "Update needed.";
153 }
154 $plugin_data["inactive_reason"] = $inactive_reason;
155 $plugin_data["needs_update"] = true;
156 $plugin_data["activation_possible"] = false;
157 } else {
158 if (ilComponent::isVersionGreaterString($last_update_version, $plugin_data["version"])) {
159 $plugin_data["is_active"] = false;
160 if ($this->lng instanceof ilLanguage) {
161 $inactive_reason = $this->lng->txt("cmps_needs_upgrade");
162 } else {
163 $inactive_reason = "Upgrade needed.";
164 }
165 $plugin_data["inactive_reason"] = $inactive_reason;
166 $plugin_data["activation_possible"] = false;
167 } else {
168 if ($last_update_version != $plugin_data["version"]) {
169 $plugin_data["is_active"] = false;
170 if ($this->lng instanceof ilLanguage) {
171 $inactive_reason = $this->lng->txt("cmps_needs_update");
172 } else {
173 $inactive_reason = "Update needed.";
174 }
175 $plugin_data["inactive_reason"] = $inactive_reason;
176 $plugin_data["needs_update"] = true;
177 $plugin_data["activation_possible"] = false;
178 }
179 }
180 }
181 }
182
183
191 protected function setMustInstall(array &$plugin_data)
192 {
193 $plugin_data["must_install"] = true;
194 $plugin_data["is_active"] = false;
195 $plugin_data["needs_update"] = false;
196 $plugin_data["activation_possible"] = false;
197
198 if ($this->lng instanceof ilLanguage) {
199 $inactive_reason = $this->lng->txt("cmps_must_installed");
200 } else {
201 $inactive_reason = "Plugin must be installed.";
202 }
203 $plugin_data["inactive_reason"] = $inactive_reason;
204 }
205
206
217 protected function setCurrentState(array &$plugin_data, $active)
218 {
219 $plugin_data["is_active"] = $active;
220 $plugin_data["activation_possible"] = !$active;
221 $plugin_data["must_install"] = false;
222 $plugin_data["needs_update"] = false;
223 $plugin_data["inactive_reason"] = "";
224 }
225
226
234 protected function parsePluginPhp($plugin_php_file)
235 {
236 include($plugin_php_file);
237
238 $values = [
239 "version" => $version,
240 "id" => $id,
241 "ilias_min_version" => $ilias_min_version,
242 "ilias_max_version" => $ilias_max_version,
243 "responsible" => $responsible,
244 "responsible_mail" => $responsible_mail,
245 "learning_progress" => (bool) ($learning_progress ?? false),
246 "supports_export" => (bool) ($supports_export ?? false),
247 "supports_cli_setup" => (bool) ($supports_cli_setup ?? true)
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
521 public static function getAllPlugins()
522 {
523 static $all_plugins;
524 if (!isset($all_plugins)) {
525 $cached_component = ilCachedComponentData::getInstance();
526 $all_plugins = $cached_component->getIlPluginById();
527 }
528
529 return $all_plugins;
530 }
531
532
538 public static function getActivePlugins()
539 {
540 static $active_plugins;
541 if (!isset($active_plugins)) {
542 $cached_component = ilCachedComponentData::getInstance();
543 $plugins = $cached_component->getIlPluginActive();
544 $buf = array();
545 foreach ($plugins as $slot => $plugs) {
546 $buf[] = $plugs;
547 }
548
549 $active_plugins = array_merge([], ...$buf);
550 }
551
552 return $active_plugins;
553 }
554
555
563 public static function isPluginActive($id)
564 {
565 assert(is_string($id));
566 $cached_component = ilCachedComponentData::getInstance();
567 $plugs = $cached_component->getIlPluginById();
568 if (array_key_exists($id, $plugs) && $plugs[$id]['active']) {
569 return true;
570 }
571
572 return false;
573 }
574
575
584 public static function getPluginObjectById($id)
585 {
586 assert(is_string($id));
587 $plugs = self::getAllPlugins();
588 if (!array_key_exists($id, $plugs)) {
589 throw new \InvalidArgumentException("Plugin does not exist: " . $id, 1);
590 }
591 $pdata = $plugs[$id];
592
594 $pdata['component_type'],
595 $pdata['component_name'],
596 $pdata['slot_id'],
597 $pdata['name']
598 );
599 }
600
601
606 public static function getAllGlobalScreenProviders() : array
607 {
608 $providers = array();
609 // return array(); // current fix
610 foreach (self::getActivePlugins() as $plugin) {
611 $pl = self::getPluginObjectById($plugin['plugin_id']);
612 if ($pl->isActive()) {
613 array_push($providers, $pl->promoteGlobalScreenProvider());
614 }
615 }
616
617 return $providers;
618 }
619
620
624 public static function getGlobalScreenProviderCollections() : Generator
625 {
629 foreach (self::getActivePlugins() as $plugin) {
630 $pl = self::getPluginObjectById($plugin['plugin_id']);
631 if ($pl->isActive()) {
632 yield $pl->getGlobalScreenProviderCollection();
633 }
634 }
635 }
636
637 public function getRawPluginDataFor(string $name) : ?array
638 {
639 $this->clearCachedData();
640
643
644 foreach ($this->getPluginSlots($modules, IL_COMP_MODULE) as $plugin_slot) {
645 $plugin = $plugin_slot->getPluginInformationFor($name);
646 if (!is_null($plugin)) {
647 return $plugin;
648 }
649 }
650
651 foreach ($this->getPluginSlots($services, IL_COMP_SERVICE) as $plugin_slot) {
652 $plugin = $plugin_slot->getPluginInformationFor($name);
653 if (!is_null($plugin)) {
654 return $plugin;
655 }
656 }
657
658 return null;
659 }
660
661 protected function getPluginSlots(array $components, string $type) : \Iterator
662 {
663 foreach ($this->getComponentSlotsByType($components, $type) as $slot) {
664 $subdir = (explode('/', $slot['component']))[1];
665 yield new ilPluginSlot($type, $subdir, $slot['id']);
666 }
667 }
668
669 protected function getComponentSlotsByType(array $components, string $type) : \Iterator
670 {
671 foreach ($components as $component) {
672 $component_slots = ilComponent::lookupPluginSlots($type, $component["subdir"]);
673 foreach ($component_slots as $component_slot) {
674 if (count($component_slot) > 0) {
675 yield $component_slot;
676 }
677 }
678 }
679 }
680
681 final public function clearCachedData()
682 {
683 unset($this->data);
684 unset($this->got_data);
686 }
687}
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
const IL_COMP_MODULE
static isVersionGreaterString($a_ver1, $a_ver2)
static lookupPluginSlots($a_type, $a_name)
Lookup all plugin slots of a component.
language handling
static getAvailableCoreModules()
Get all available core modules.
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.
getRawPluginDataFor(string $name)
setCurrentState(array &$plugin_data, $active)
Set current state to static values, excluding active and activatoin possible.
pluginSupportCurrentILIAS(array &$plugin_data)
Plugin supports current ILIAS.
getPluginSlots(array $components, string $type)
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.
getComponentSlotsByType(array $components, string $type)
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)
static getAvailableCoreServices()
Get all available core services.
global $DIC
Definition: goto.php:24
const ILIAS_VERSION_NUMERIC
if($format !==null) $name
Definition: metadata.php:230
$type