ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
5
6include_once("./Services/Component/classes/class.ilComponent.php");
7
17{
18 public $got_data = false;
19
24 public static $active_plugins = array();
25
30 public static $plugin_objects = array();
31
32
36 public function __construct()
37 {
38 global $lng;
39 $this->lng = $lng;
40 $this->lng->loadLanguageModule("cmps");
41 }
42
51 final private function getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname)
52 {
53 //Can not use DIC because it is not initialized if plugin is activated
54 global $lng;
55 $this->lng = $lng;
56
57 if (!isset($this->got_data[$a_ctype][$a_cname][$a_slot_id][$a_pname])) {
58 include_once "./Services/Component/classes/class.ilPluginSlot.php";
59 $slot_name = ilPluginSlot::lookupSlotName($a_ctype, $a_cname, $a_slot_id);
60
61 $plugin_php_file = "./Customizing/global/plugins/" . $a_ctype . "/" .
62 $a_cname . "/" . $slot_name . "/" . $a_pname . "/plugin.php";
63
64 if (!is_file($plugin_php_file)) {
65 throw new ilPluginException("No plugin.php file found for Plugin :" . $a_pname . ".");
66 }
67
68 $plugin_db_data = ilPlugin::getPluginRecord($a_ctype, $a_cname, $a_slot_id, $a_pname);
69 $plugin_data = $this->parsePluginPhp($plugin_php_file);
70
71 if ($plugin_db_data["plugin_id"] === null) {
72 $this->setMustInstall($plugin_data);
73 } else {
74 $this->setCurrentState($plugin_data, (bool) $plugin_db_data["active"]);
75 if ($this->pluginSupportCurrentILIAS($plugin_data)) {
76 $this->updateRequired($plugin_data, $plugin_db_data["last_update_version"]);
77 }
78 }
79
80 $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname] = $plugin_data;
81 $this->got_data[$a_ctype][$a_cname][$a_slot_id][$a_pname] = true;
82 }
83 }
84
92 protected function pluginSupportCurrentILIAS(array &$plugin_data)
93 {
94 if (ilComponent::isVersionGreaterString($plugin_data["ilias_min_version"], ILIAS_VERSION_NUMERIC)) {
95 $plugin_data["is_active"] = false;
96 $plugin_data["needs_update"] = false;
97 $plugin_data["activation_possible"] = false;
98
99 if (is_object($this->lng)) {
100 $inactive_reason = $this->lng->txt("cmps_needs_newer_ilias_version");
101 } else {
102 $inactive_reason = "Plugin needs a newer version of ILIAS.";
103 }
104 $plugin_data["inactive_reason"] = $inactive_reason;
105
106 return false;
107 }
108
109 if (ilComponent::isVersionGreaterString(ILIAS_VERSION_NUMERIC, $plugin_data["ilias_max_version"])) {
110 $plugin_data["is_active"] = false;
111 $plugin_data["needs_update"] = false;
112 $plugin_data["activation_possible"] = false;
113 if (is_object($this->lng)) {
114 $inactive_reason = $this->lng->txt("cmps_needs_newer_plugin_version");
115 } else {
116 $inactive_reason = "Plugin does not support current version of ILIAS. Newer version of plugin needed.";
117 }
118 $plugin_data["inactive_reason"] = $inactive_reason;
119
120 return false;
121 }
122
123 return true;
124 }
125
134 protected function updateRequired(array &$plugin_data, $last_update_version)
135 {
136 if ($last_update_version == "") {
137 $plugin_data["is_active"] = false;
138 if (is_object($this->lng)) {
139 $inactive_reason = $this->lng->txt("cmps_needs_update");
140 } else {
141 $inactive_reason = "Update needed.";
142 }
143 $plugin_data["inactive_reason"] = $inactive_reason;
144 $plugin_data["needs_update"] = true;
145 $plugin_data["activation_possible"] = false;
146 } elseif (ilComponent::isVersionGreaterString($last_update_version, $plugin_data["version"])) {
147 $plugin_data["is_active"] = false;
148 if (is_object($this->lng)) {
149 $inactive_reason = $this->lng->txt("cmps_needs_upgrade");
150 } else {
151 $inactive_reason = "Upgrade needed.";
152 }
153 $plugin_data["inactive_reason"] = $inactive_reason;
154 $plugin_data["activation_possible"] = false;
155 } elseif ($last_update_version != $plugin_data["version"]) {
156 $plugin_data["is_active"] = false;
157 if (is_object($this->lng)) {
158 $inactive_reason = $this->lng->txt("cmps_needs_update");
159 } else {
160 $inactive_reason = "Update needed.";
161 }
162 $plugin_data["inactive_reason"] = $inactive_reason;
163 $plugin_data["needs_update"] = true;
164 $plugin_data["activation_possible"] = false;
165 }
166 }
167
175 protected function setMustInstall(array &$plugin_data)
176 {
177 $plugin_data["must_install"] = true;
178 $plugin_data["is_active"] = false;
179 $plugin_data["needs_update"] = false;
180 $plugin_data["activation_possible"] = false;
181
182 if (is_object($this->lng)) {
183 $inactive_reason = $this->lng->txt("cmps_must_installed");
184 } else {
185 $inactive_reason = "Plugin must be installed.";
186 }
187 $plugin_data["inactive_reason"] = $inactive_reason;
188 }
189
200 protected function setCurrentState(array &$plugin_data, $active)
201 {
202 $plugin_data["is_active"] = $active;
203 $plugin_data["activation_possible"] = !$active;
204 $plugin_data["must_install"] = false;
205 $plugin_data["needs_update"] = false;
206 $plugin_data["inactive_reason"] = "";
207 }
208
216 protected function parsePluginPhp($plugin_php_file)
217 {
218 include_once($plugin_php_file);
219
220 $values = [
221 "version" => $version,
222 "id" => $id,
223 "ilias_min_version" => $ilias_min_version,
224 "ilias_max_version" => $ilias_max_version,
225 "responsible" => $responsible,
226 "responsible_mail" => $responsible_mail,
227 "learning_progress" => (bool) $learning_progress,
228 "supports_export" => (bool) $supports_export
229 ];
230
231 return $values;
232 }
233
242 public function getVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
243 {
244 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
245 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["version"];
246 }
247
256 public function getIliasMinVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
257 {
258 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
259 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["ilias_min_version"];
260 }
261
270 public function getIliasMaxVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
271 {
272 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
273 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["ilias_max_version"];
274 }
275
284 public function getId($a_ctype, $a_cname, $a_slot_id, $a_pname)
285 {
286 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
287 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["id"];
288 }
289
298 public function isActive($a_ctype, $a_cname, $a_slot_id, $a_pname)
299 {
300 try {
301 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
302 } catch (ilPluginException $e) {
303 return false;
304 }
305 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["is_active"];
306 }
307
316 public function exists($a_ctype, $a_cname, $a_slot_id, $a_pname)
317 {
318 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
319 return isset($this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]);
320 }
321
330 public function needsUpdate($a_ctype, $a_cname, $a_slot_id, $a_pname)
331 {
332 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
333 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["needs_update"];
334 }
335
344 public function getAllData($a_ctype, $a_cname, $a_slot_id, $a_pname)
345 {
346 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
347 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname];
348 }
349
353 public static function getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
354 {
355 // cache the list of active plugins
356 if (!isset(self::$active_plugins[$a_ctype][$a_cname][$a_slot_id])) {
357 include_once "./Services/Component/classes/class.ilPlugin.php";
358
359 self::$active_plugins[$a_ctype][$a_cname][$a_slot_id] =
360 ilPlugin::getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id);
361 }
362 return self::$active_plugins[$a_ctype][$a_cname][$a_slot_id];
363 }
364
374 public static function getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
375 {
376 // cache the plugin objects
377 if (!isset(self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname])) {
378 self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname] =
379 ilPlugin::getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname);
380 }
381 return self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname];
382 }
383
393 public static function includeClass(
394 $a_ctype,
395 $a_cname,
396 $a_slot_id,
397 $a_pname,
398 $a_class_file_name
399 ) {
400 // cache the plugin objects
401 if (!isset(self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname])) {
402 self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname] =
403 ilPlugin::getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname);
404 }
405 $pl = self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname];
406 $pl->includeClass($a_class_file_name);
407 }
408
418 public function hasLearningProgress($a_ctype, $a_cname, $a_slot_id, $a_pname)
419 {
420 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
421 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["learning_progress"];
422 }
423
433 public function supportsExport($a_ctype, $a_cname, $a_slot_id, $a_pname)
434 {
435 $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
436 return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["supports_export"];
437 }
438
444 public static function getAllPlugins()
445 {
446 $cached_component = ilCachedComponentData::getInstance();
447 return $cached_component->getIlPluginById();
448 }
449
455 public static function getActivePlugins()
456 {
457 $cached_component = ilCachedComponentData::getInstance();
458 $plugins = $cached_component->getIlPluginActive();
459 $buf = array();
460 foreach ($plugins as $slot => $plugs) {
461 $buf = array_merge($buf, $plugs);
462 }
463 return $buf;
464 }
465
472 public static function isPluginActive($id)
473 {
474 assert('is_string($id)');
475 $cached_component = ilCachedComponentData::getInstance();
476 $plugs = $cached_component->getIlPluginById();
477 if (array_key_exists($id, $plugs) && $plugs[$id]['active']) {
478 return true;
479 }
480 return false;
481 }
482
490 public static function getPluginObjectById($id)
491 {
492 assert('is_string($id)');
493 $plugs = self::getAllPlugins();
494 if (!array_key_exists($id, $plugs)) {
495 throw new \InvalidArgumentException("Plugin does not exist: " . $id, 1);
496 }
497 $pdata = $plugs[$id];
499 $pdata['component_type'],
500 $pdata['component_name'],
501 $pdata['slot_id'],
502 $pdata['name']
503 );
504 }
505}
An exception for terminatinating execution or to throw for unit testing.
static isVersionGreaterString($a_ver1, $a_ver2)
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.
parsePluginPhp($plugin_php_file)
Get informations from plugin php file.
static includeClass( $a_ctype, $a_cname, $a_slot_id, $a_pname, $a_class_file_name)
Get Plugin Object.
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.
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 getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get plugin object.
static getPluginRecord($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get record from il_plugin table.
static getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugin names for a slot.
if(!array_key_exists('StateId', $_REQUEST)) $id
const ILIAS_VERSION_NUMERIC
global $lng
Definition: privfeed.php:17
$this data['403_header']