[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Allow the user to unset action logs from the list of action logs

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <689272e6dcdb1_2cd5d2c50663@gitlab-sidekiq-low-urgency-cpu-bound-v2-86c757c9d6-ctppw.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
157c016b by Alain Cisirika at 2025-08-05T21:00:49+00:00
[ENH] Allow the user to unset action logs from the list of action logs
---
* [ENH] Allow the user to unset action logs from the list of action logs

See merge request tikiwiki/tiki!8150

- - - - -


3 changed files:

- lib/Logs/LogsLib.php
- templates/tiki-admin_actionlog.tpl
- tiki-admin_actionlog.php


Changes:

=====================================
lib/Logs/LogsLib.php
=====================================
@@ -17,6 +17,22 @@ use function mb_convert_encoding;
 
 class LogsLib extends TikiLib
 {
+    /**
+     * @var array|null Caches the action log configuration to avoid repeated DB queries.
+     */
+
+    private static $cachedActionlogConf = null;
+
+    /**
+     * Clears the internal static cache for the action log configuration.
+     * This ensures that the next call to get_all_actionlog_conf() will fetch fresh data.
+     */
+
+    private function clearActionlogConfCache()
+    {
+        self::$cachedActionlogConf = null;
+    }
+
     public function add_log($type, $message, $who = '', $ip = '', $client = '', $time = '', $log = '')
     {
         global $user, $prefs;
@@ -426,12 +442,11 @@ class LogsLib extends TikiLib
 
     public function set_actionlog_conf($action, $objectType, $status)
     {
-        global $actionlogConf;
         $this->delete_actionlog_conf($action, $objectType);
         $action = str_replace('*', '%', $action);
         $query = "insert into `tiki_actionlog_conf` (`action`, `objectType`, `status`) values(?, ?, ?)";
         $this->query($query, [$action, $objectType, $status]);
-        unset($actionlogConf);
+        $this->clearActionlogConfCache();
     }
 
     public function delete_actionlog_conf($action, $objectType)
@@ -445,13 +460,11 @@ class LogsLib extends TikiLib
 
     public function get_all_actionlog_conf()
     {
-        global $actionlogConf;
-
-        if (! isset($actionlogConf)) {
-            $actionlogConf = self::get_actionlog_conf();
+        if (self::$cachedActionlogConf === null) {
+            self::$cachedActionlogConf = self::get_actionlog_conf();
         }
 
-        return $actionlogConf;
+        return self::$cachedActionlogConf;
     }
 
     public function get_actionlog_conf($type = '%', $action = '%')


=====================================
templates/tiki-admin_actionlog.tpl
=====================================
@@ -810,9 +810,10 @@
             <br class="clearfix"/>
 
             <div class="mb-3 row">
-                <div class="col-sm-1 offset-sm-11">
-                    <input type="submit" class="btn btn-primary btn-sm" name="save" value="{tr}Set{/tr}">
-                </div>
+            <p class="offset-sm-10">
+                <input type="submit" class="btn btn-secondary btn-sm" name="unset" value="{tr}Unset All{/tr}">
+                <input type="submit" class="btn btn-primary btn-sm" name="save" value="{tr}Set{/tr}">
+            </p>
             </div>
             <div class="mb-3 row">
                 {*<div class="col-sm-12">*}
@@ -871,9 +872,10 @@
                 {*</div>*}
             </div>
             <div class="mb-3 row">
-                <div class="col-sm-1 offset-sm-11">
-                    <input type="submit" class="btn btn-primary btn-sm" name="save" value="{tr}Set{/tr}">
-                </div>
+            <p class="offset-sm-10">
+                <input type="submit" class="btn btn-secondary btn-sm" name="unset" value="{tr}Unset All{/tr}">
+                <input type="submit" class="btn btn-primary btn-sm" name="save" value="{tr}Set{/tr}">
+            </p>
             </div>
         </form>
     {/tab}


=====================================
tiki-admin_actionlog.php
=====================================
@@ -163,6 +163,16 @@ if (isset($_REQUEST['max'])) {
 }
 
 if ($tiki_p_view_actionlog == 'y') {
+    if (isset($_POST['unset']) && $access->checkCsrf()) {
+        foreach ($action_log_conf_selected as $conf) {
+            $logslib->set_actionlog_conf($conf['action'], $conf['objectType'], 'n');
+        }
+
+        $confs = $logslib->get_all_actionlog_conf();
+        $action_log_conf_selected = $logslib->get_actionlog_conf($action_log_type);
+        $cookietab = 1;
+        Feedback::success(tr('All actions logs unset'));
+    }
     if (isset($_POST['save']) && $access->checkCsrf()) {
         $itemsSelected = false;
         $recordedWithoutReported = [];
@@ -195,13 +205,26 @@ if ($tiki_p_view_actionlog == 'y') {
                 $logslib->set_actionlog_conf($conf['action'], $conf['objectType'], 'n');
             }
         }
-        global $actionlogConf;
-        unset($actionlogConf);
+
         $confs = $logslib->get_all_actionlog_conf();
         $action_log_conf_selected = $logslib->get_actionlog_conf($action_log_type);
         $cookietab = 1;
     }
 } else {
+    if (isset($_POST['unset']) && $access->checkCsrf()) {
+        $_prefs = 'v';
+        foreach ($action_log_conf_selected as $conf) {
+            if ($conf['status'] === 'v' || $conf['status'] === 'y') {
+                $_prefs .= $conf['id'] . 'y';
+            }
+        }
+
+        $tikilib->set_user_preference($user, 'actionlog_conf', $_prefs);
+        $confs = $logslib->get_all_actionlog_conf();
+        $action_log_conf_selected = $logslib->get_actionlog_conf($action_log_type);
+        $cookietab = 1;
+        Feedback::success(tr('All actions logs unset'));
+    }
     if (isset($_POST['save']) && $access->checkCsrf()) {
         $_prefs = 'v';
         foreach ($action_log_conf_selected as $index => $conf) {
@@ -213,8 +236,7 @@ if ($tiki_p_view_actionlog == 'y') {
                 }
             }
         }
-        global $actionlogConf;
-        unset($actionlogConf);
+
         $confs = $logslib->get_all_actionlog_conf();
         $action_log_conf_selected = $logslib->get_actionlog_conf($action_log_type);
         $tikilib->set_user_preference($user, 'actionlog_conf', $_prefs);
@@ -229,10 +251,10 @@ if ($tiki_p_view_actionlog == 'y') {
                     }
                 }
             }
+            unset($conf);
         }
     }
-    global $actionlogConf;
-    $actionlogConf = $confs;
+    $logslib->set_actionlog_conf($confs);
 }
 
 foreach ($confs as $conf) {



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/157c016bbf45cf7a30dc15e05d14671e7b28baf0

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/157c016bbf45cf7a30dc15e05d14671e7b28baf0
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.