aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-05-06 09:03:33 +0000
committerJan-Hendrik Willms <tleilax+github@gmail.com>2024-05-06 15:07:50 +0200
commitb5d0e549f592bd20a6d6c80cc4ffa65329d8e2af (patch)
tree4e1593178e431b122c3bd6ffff05b5880a40de3c
parentca5c092e4bf992c89dd55d9b2e262dc4e2a21747 (diff)
fixes #3977
Closes #3977 Merge request studip/studip!2945
-rw-r--r--db/migrations/5.1.57_cleanup_tool_activations.php23
-rw-r--r--lib/plugins/engine/PluginManager.class.php60
2 files changed, 57 insertions, 26 deletions
diff --git a/db/migrations/5.1.57_cleanup_tool_activations.php b/db/migrations/5.1.57_cleanup_tool_activations.php
new file mode 100644
index 0000000..6700816
--- /dev/null
+++ b/db/migrations/5.1.57_cleanup_tool_activations.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * @see https://gitlab.studip.de/studip/studip/-/issues/3977
+ */
+return new class extends Migration
+{
+ public function description()
+ {
+ return 'Removes invalid tool activations (that are no longer connected '
+ . 'to a StandardPlugin';
+ }
+
+ protected function up()
+ {
+ $query = "DELETE FROM `tools_activated`
+ WHERE `plugin_id` NOT IN (
+ SELECT `pluginid`
+ FROM `plugins`
+ WHERE FIND_IN_SET(?, `plugintype`)
+ )";
+ DBManager::get()->execute($query, [StandardPlugin::class]);
+ }
+};
diff --git a/lib/plugins/engine/PluginManager.class.php b/lib/plugins/engine/PluginManager.class.php
index 8491b03..fdb243e 100644
--- a/lib/plugins/engine/PluginManager.class.php
+++ b/lib/plugins/engine/PluginManager.class.php
@@ -418,41 +418,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
+ ];
+
+ $this->readPluginInfos();
- $db->exec("INSERT INTO roles_plugins (roleid, pluginid)
+ $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;
}