diff options
Diffstat (limited to 'lib/plugins/engine')
| -rw-r--r-- | lib/plugins/engine/PluginEngine.php (renamed from lib/plugins/engine/PluginEngine.class.php) | 21 | ||||
| -rw-r--r-- | lib/plugins/engine/PluginManager.php (renamed from lib/plugins/engine/PluginManager.class.php) | 90 | ||||
| -rw-r--r-- | lib/plugins/engine/PluginRepository.php (renamed from lib/plugins/engine/PluginRepository.class.php) | 4 |
3 files changed, 60 insertions, 55 deletions
diff --git a/lib/plugins/engine/PluginEngine.class.php b/lib/plugins/engine/PluginEngine.php index ecf00cf..25974c5 100644 --- a/lib/plugins/engine/PluginEngine.class.php +++ b/lib/plugins/engine/PluginEngine.php @@ -3,8 +3,7 @@ /** * Factory Class for the plugin engine * @author Dennis Reil, <dennis.reil@offis.de> - * @package pluginengine - * @subpackage engine + * @template P of StudIPPlugin */ class PluginEngine @@ -38,27 +37,28 @@ class PluginEngine global $user, $perm; // load system plugins - self::getPlugins('SystemPlugin'); + self::getPlugins(SystemPlugin::class); // load homepage plugins - self::getPlugins('HomepagePlugin'); + self::getPlugins(HomepagePlugin::class); // load course plugins if (Context::getId()) { - self::getPlugins('StudipModule'); - self::getPlugins('StandardPlugin'); + self::getPlugins(StudipModule::class); + self::getPlugins(StandardPlugin::class); } // load admin plugins if (is_object($user) && $perm->have_perm('admin')) { - self::getPlugins('AdministrationPlugin'); + self::getPlugins(AdministrationPlugin::class); } } /** * Get instance of the plugin specified by plugin class name. * - * @param string $class class name of plugin + * @param class-string<P> $class class name of plugin + * @return P */ public static function getPlugin ($class) { @@ -70,10 +70,9 @@ class PluginEngine * returns all enabled plugins. The optional context parameter can be * used to get only plugins that are activated in the given context. * - * @template T - * @param T $type plugin type or null (all types) + * @param class-string<P>|null $type plugin type or null (all types) * @param string $context context range id (optional) - * @return T[] all plugins of the specified type + * @return P[]|StudIPPlugin[] all plugins of the specified type */ public static function getPlugins ($type, $context = null) { diff --git a/lib/plugins/engine/PluginManager.class.php b/lib/plugins/engine/PluginManager.php index be4f766..ec434a9 100644 --- a/lib/plugins/engine/PluginManager.class.php +++ b/lib/plugins/engine/PluginManager.php @@ -1,14 +1,11 @@ <?php -# Lifter010: TODO -/* - * PluginManager.class.php - plugin manager for Stud.IP +/** + * PluginManager.php - plugin manager for Stud.IP * - * Copyright (c) 2009 Elmar Ludwig + * @copyright 2009 Elmar Ludwig + * @license GPL2 or any later version * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. + * @template P of StudIPPlugin */ class PluginManager @@ -354,10 +351,10 @@ class PluginManager $path = 'lib/modules'; } - $pluginfile = $basepath.'/'.$path.'/'.$class.'.class.php'; + $pluginfile = $basepath.'/'.$path.'/'.$class.'.php'; if (!file_exists($pluginfile)) { - $pluginfile = $basepath.'/'.$path.'/'.$class.'.php'; + $pluginfile = $basepath.'/'.$path.'/'.$class.'.class.php'; if (!file_exists($pluginfile)) { return null; @@ -427,41 +424,49 @@ class PluginManager $this->plugins[$id]['name'] = $name; $this->plugins[$id]['path'] = $path; $this->plugins[$id]['type'] = $type; + } else { + foreach ($this->plugins as $plugin) { + $common_types = array_intersect($type, $plugin['type']); - return $id; - } - - foreach ($this->plugins as $plugin) { - $common_types = array_intersect($type, $plugin['type']); - - if (count($common_types) > 0 && $plugin['position'] >= $position) { - $position = $plugin['position'] + 1; + if (count($common_types) > 0 && $plugin['position'] >= $position) { + $position = $plugin['position'] + 1; + } } - } - $sql = 'INSERT INTO plugins ( + $sql = 'INSERT INTO plugins ( pluginname, pluginclassname, pluginpath, plugintype, navigationpos, dependentonid ) VALUES (?,?,?,?,?,?)'; - $stmt = $db->prepare($sql); - $stmt->execute([$name, $class, $path, join(',', $type), $position, $depends]); - $id = $db->lastInsertId(); - - $this->plugins[$id] = [ - 'id' => $id, - 'name' => $name, - 'class' => $class, - 'path' => $path, - 'type' => $type, - 'enabled' => false, - 'position' => $position, - 'depends' => $depends - ]; + $stmt = $db->prepare($sql); + $stmt->execute([$name, $class, $path, join(',', $type), $position, $depends]); + $id = $db->lastInsertId(); - $this->readPluginInfos(); + $this->plugins[$id] = [ + 'id' => $id, + 'name' => $name, + 'class' => $class, + 'path' => $path, + 'type' => $type, + 'enabled' => false, + 'position' => $position, + 'depends' => $depends + ]; - $db->exec("INSERT INTO roles_plugins (roleid, pluginid) + $this->readPluginInfos(); + + $db->exec("INSERT INTO roles_plugins (roleid, pluginid) SELECT roleid, $id FROM roles WHERE `system` = 'y' AND rolename != 'Nobody'"); + } + + if (!in_array(StandardPlugin::class, $type)) { + ToolActivation::findEachBySQL( + function (ToolActivation $activation) use ($id) { + $this->setPluginActivated($id, $activation->range_id, false); + }, + 'plugin_id = ?', + [$id] + ); + } return $id; } @@ -568,7 +573,7 @@ class PluginManager * Get instance of the plugin specified by plugin meta data. * * @param array $plugin_info plugin meta data - * @return object + * @return P */ protected function getCachedPlugin ($plugin_info) { @@ -586,7 +591,7 @@ class PluginManager } if ($plugin_class) { - $plugin = $plugin_class->newInstance(); + $plugin = app()->get($class); } return $this->plugin_cache[$class] = $plugin; @@ -595,8 +600,8 @@ class PluginManager /** * Get instance of the plugin specified by plugin class name. * - * @param string $class class name of plugin - * @return object + * @param class-string<P> $class class name of plugin + * @return P|null */ public function getPlugin ($class) { @@ -615,7 +620,7 @@ class PluginManager * Get instance of the plugin specified by plugin id. * * @param int $id id of the plugin - * @return object $plugin + * @return P|null $plugin */ public function getPluginById ($id) { @@ -635,8 +640,9 @@ class PluginManager * returns all enabled plugins. The optional context parameter can be * used to get only plugins that are activated in the given context. * - * @param string $type plugin type or null (all types) + * @param class-string<P>|null $type plugin type or null (all types) * @param string $context context range id (optional) + * @return P[]|StudIPPlugin[] */ public function getPlugins ($type, $context = null) { diff --git a/lib/plugins/engine/PluginRepository.class.php b/lib/plugins/engine/PluginRepository.php index 14415f4..4bd24c6 100644 --- a/lib/plugins/engine/PluginRepository.class.php +++ b/lib/plugins/engine/PluginRepository.php @@ -1,7 +1,7 @@ <?php /* - * PluginRepository.class.php - query plugin meta data + * PluginRepository.php - query plugin meta data * * Copyright (c) 2008 Elmar Ludwig * @@ -55,7 +55,7 @@ class PluginRepository */ public function readMetadata($url) { - $cache = StudipCacheFactory::getCache(); + $cache = \Studip\Cache\Factory::getCache(); $cache_key = 'plugin_metadata/'.$url; $metadata = $cache->read($cache_key); |
