From e4248dab785f59df2a09f84086a65b41bab6d7cb Mon Sep 17 00:00:00 2001
From: noackorama <noackorama@gmail.com>
Date: Tue, 3 Aug 2021 18:30:18 +0200
Subject: [PATCH] closes #37

---
 app/controllers/profilemodules.php         |  2 +-
 lib/navigation/ProfileNavigation.php       |  2 +-
 lib/plugins/engine/PluginManager.class.php | 23 +++++++++++++++++++---
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/app/controllers/profilemodules.php b/app/controllers/profilemodules.php
index 8f87073e7c7..9e558faca12 100644
--- a/app/controllers/profilemodules.php
+++ b/app/controllers/profilemodules.php
@@ -254,7 +254,7 @@ class ProfileModulesController extends AuthenticatedController
 
         $state = (bool) $state;
         if ($state != $manager->isPluginActivatedForUser($item, $this->user->id)
-            && $manager->setPluginActivated($item, $this->user->id, $state, 'user'))
+            && $manager->setPluginActivatedForUser($item, $this->user->id, $state))
         {
             return [$state, $this->plugins[$item]->getPluginName()];
         }
diff --git a/lib/navigation/ProfileNavigation.php b/lib/navigation/ProfileNavigation.php
index c8d372eff8d..7a17683f901 100644
--- a/lib/navigation/ProfileNavigation.php
+++ b/lib/navigation/ProfileNavigation.php
@@ -125,7 +125,7 @@ class ProfileNavigation extends Navigation
         // Add consultations if appropriate
         if (Config::get()->CONSULTATION_ENABLED) {
             $plugin = PluginEngine::getPlugin('ConsultationModule');
-            if ($current_user && $plugin && $plugin->isActivated($current_user->id, 'user')) {
+            if ($current_user && $plugin && PluginManager::getInstance()->isPluginActivatedForUser($plugin->getPluginId(), $current_user->id)) {
                 $this->addSubNavigation('consultation', new ConsultationNavigation($current_user));
             }
         }
diff --git a/lib/plugins/engine/PluginManager.class.php b/lib/plugins/engine/PluginManager.class.php
index cd14841b219..13973592e0b 100644
--- a/lib/plugins/engine/PluginManager.class.php
+++ b/lib/plugins/engine/PluginManager.class.php
@@ -244,9 +244,9 @@ class PluginManager
     /**
      * Sets the activation status of a plugin in the given context.
      *
-     * @param $id        id of the plugin
-     * @param $rangeId   context range id
-     * @param $active    plugin status (true or false)
+     * @param $id        string id of the plugin
+     * @param $rangeId   string context range id
+     * @param $active    bool plugin status (true or false)
      */
     public function setPluginActivated ($id, $rangeId, $active)
     {
@@ -269,6 +269,23 @@ class PluginManager
         }
     }
 
+    /**
+     * Sets the activation status of a plugin in the given context.
+     *
+     * @param $pluginid string of the plugin
+     * @param $user_id string user id
+     * @param $active  bool  plugin status (true or false)
+     */
+    public function setPluginActivatedForUser($pluginid, $user_id, $active)
+    {
+        $db = DBManager::get();
+        $state = $active ? 1 : 0;
+        unset($this->plugins_activated_cache[$user_id]);
+
+        return $db->execute("REPLACE INTO plugins_activated (pluginid, range_type, range_id, state)
+	                          VALUES (?, 'user', ?, ?)", [$pluginid, $user_id, $state]);
+    }
+
     /**
      * Deactivate all plugins for the given range.
      *
-- 
GitLab