ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 include_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  final 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 = ["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,
246  "supports_export" => (bool) $supports_export];
247 
248  return $values;
249  }
250 
251 
263  public function getVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
264  {
265  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
266 
267  return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["version"];
268  }
269 
270 
282  public function getIliasMinVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
283  {
284  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
285 
286  return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["ilias_min_version"];
287  }
288 
289 
301  public function getIliasMaxVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
302  {
303  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
304 
305  return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["ilias_max_version"];
306  }
307 
308 
320  public function getId($a_ctype, $a_cname, $a_slot_id, $a_pname)
321  {
322  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
323 
324  return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["id"];
325  }
326 
327 
338  public function isActive($a_ctype, $a_cname, $a_slot_id, $a_pname)
339  {
340  try {
341  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
342  } catch (ilPluginException $e) {
343  return false;
344  }
345 
346  return (bool) $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["is_active"];
347  }
348 
349 
361  public function exists($a_ctype, $a_cname, $a_slot_id, $a_pname)
362  {
363  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
364 
365  return isset($this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]);
366  }
367 
368 
380  public function needsUpdate($a_ctype, $a_cname, $a_slot_id, $a_pname)
381  {
382  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
383 
384  return (bool) $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["needs_update"];
385  }
386 
387 
399  public function getAllData($a_ctype, $a_cname, $a_slot_id, $a_pname)
400  {
401  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
402 
403  return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname];
404  }
405 
406 
416  public static function getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
417  {
418  // cache the list of active plugins
419  if (!isset(self::$active_plugins[$a_ctype][$a_cname][$a_slot_id])) {
420  self::$active_plugins[$a_ctype][$a_cname][$a_slot_id]
421  = ilPlugin::getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id);
422  }
423 
424  return self::$active_plugins[$a_ctype][$a_cname][$a_slot_id];
425  }
426 
427 
438  public static function getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
439  {
440  // cache the plugin objects
441  if (!isset(self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname])) {
442  self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname]
443  = ilPlugin::getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname);
444  }
445 
446  return self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname];
447  }
448 
449 
462  public static function includeClass($a_ctype, $a_cname, $a_slot_id, $a_pname, $a_class_file_name)
463  {
464  // cache the plugin objects
465  if (!isset(self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname])) {
466  self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname]
467  = ilPlugin::getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname);
468  }
472  $pl = self::$plugin_objects[$a_ctype][$a_cname][$a_slot_id][$a_pname];
473  $pl->includeClass($a_class_file_name);
474  }
475 
476 
488  public function hasLearningProgress($a_ctype, $a_cname, $a_slot_id, $a_pname)
489  {
490  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
491 
492  return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["learning_progress"];
493  }
494 
495 
507  public function supportsExport($a_ctype, $a_cname, $a_slot_id, $a_pname)
508  {
509  $this->getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname);
510 
511  return $this->data[$a_ctype][$a_cname][$a_slot_id][$a_pname]["supports_export"];
512  }
513 
514 
520  public static function getAllPlugins()
521  {
522  $cached_component = ilCachedComponentData::getInstance();
523 
524  return $cached_component->getIlPluginById();
525  }
526 
527 
533  public static function getActivePlugins()
534  {
535  $cached_component = ilCachedComponentData::getInstance();
536  $plugins = $cached_component->getIlPluginActive();
537  $buf = array();
538  foreach ($plugins as $slot => $plugs) {
539  $buf = array_merge($buf, $plugs);
540  }
541 
542  return $buf;
543  }
544 
545 
553  public static function isPluginActive($id)
554  {
555  assert(is_string($id));
556  $cached_component = ilCachedComponentData::getInstance();
557  $plugs = $cached_component->getIlPluginById();
558  if (array_key_exists($id, $plugs) && $plugs[$id]['active']) {
559  return true;
560  }
561 
562  return false;
563  }
564 
565 
574  public static function getPluginObjectById($id)
575  {
576  assert(is_string($id));
577  $plugs = self::getAllPlugins();
578  if (!array_key_exists($id, $plugs)) {
579  throw new \InvalidArgumentException("Plugin does not exist: " . $id, 1);
580  }
581  $pdata = $plugs[$id];
582 
583  return self::getPluginObject(
584  $pdata['component_type'],
585  $pdata['component_name'],
586  $pdata['slot_id'],
587  $pdata['name']
588  );
589  }
590 
591 
595  public static function getAllGlobalScreenProviders() : array
596  {
597  $providers = array();
598  foreach (self::getActivePlugins() as $plugin) {
599  $pl = self::getPluginObjectById($plugin['plugin_id']);
600  if ($pl instanceof ilPlugin && $pl->isActive()) {
601  array_push($providers, $pl->promoteGlobalScreenProvider());
602  }
603  }
604 
605  return $providers;
606  }
607 }
getVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get version of plugin.
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
__construct()
ilPluginAdmin constructor.
static getAllGlobalScreenProviders()
const ILIAS_VERSION_NUMERIC
static isVersionGreaterString($a_ver1, $a_ver2)
isActive($a_ctype, $a_cname, $a_slot_id, $a_pname)
Checks whether plugin is active (include version checks)
static getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugins for a slot.
global $DIC
Definition: saml.php:7
static isPluginActive($id)
Check, if a plugin is active.
getIliasMaxVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Ilias Max Version.
parsePluginPhp($plugin_php_file)
Get informations from plugin php file.
setMustInstall(array &$plugin_data)
Set plugin data for intall.
if(!array_key_exists('StateId', $_REQUEST)) $id
static lookupSlotName($a_ctype, $a_cname, $a_slot_id)
Lookup slot name for component and slot id.
needsUpdate($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get version.
static getActivePlugins()
Get info for all active plugins.
static getPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
exists($a_ctype, $a_cname, $a_slot_id, $a_pname)
Checks whether plugin exists.
pluginSupportCurrentILIAS(array &$plugin_data)
Plugin supports current ILIAS.
getAllData($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get all data from file in an array.
supportsExport($a_ctype, $a_cname, $a_slot_id, $a_pname)
Checks whether plugin supports export/import.
getPluginData($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get basic data of plugin from plugin.php.
Administration class for plugins.
$version
Definition: build.php:27
static getActivePluginsForSlot(string $a_ctype, string $a_cname, string $a_slot_id)
$values
updateRequired(array &$plugin_data, $last_update_version)
Should the plugin be updated.
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
static getAllPlugins()
Get info for all plugins.
hasLearningProgress($a_ctype, $a_cname, $a_slot_id, $a_pname)
Checks whether plugin has active learning progress.
static getPluginObjectById($id)
Get a plugin-object by id.
$this data['403_header']
getIliasMinVersion($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Ilias Min Version.
getId($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get ID.
language handling
setCurrentState(array &$plugin_data, $active)
Set current state to static values, excluding active and activatoin possible.