From b4eca89c7252a32442569109c5d4cccb551d7389 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org>
Date: Tue, 10 Mar 2020 15:27:26 +0100
Subject: [PATCH] :sparkles: feat(config) Add option to deactivate a trigger

This allow to temporarily disable a trigger while keeping its definition
 in the configuration for later.
The syntax is backward compatible so that no migration is needed.

issue #6074
---
 include/class_config.inc             |  4 ++++
 plugins/config/class_hooksConfig.inc | 11 +++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/include/class_config.inc b/include/class_config.inc
index cbae9d07f..169c4fcdf 100644
--- a/include/class_config.inc
+++ b/include/class_config.inc
@@ -484,6 +484,10 @@ class config
             $class  = strtoupper($parts[0]);
             $mode   = strtoupper($parts[1]);
             $cmd    = $parts[2];
+            if (!isset($cmd[0]) || ($cmd[0] == '#')) {
+              /* Ignore commented out and empty triggers */
+              continue;
+            }
             if (!isset($this->data['HOOKS'][$class])) {
               $this->data['HOOKS'][$class] = ['CLASS' => $parts[0]];
             }
diff --git a/plugins/config/class_hooksConfig.inc b/plugins/config/class_hooksConfig.inc
index d0dcc4eff..759543f78 100644
--- a/plugins/config/class_hooksConfig.inc
+++ b/plugins/config/class_hooksConfig.inc
@@ -70,13 +70,19 @@ class hooksConfig extends simplePlugin
                         'precreate', 'preremove', 'premodify', 'check',
                         'prelock', 'postlock', 'preunlock', 'postunlock']
                 ),
+                new BooleanAttribute(
+                  _('Deactivated'), _('Use this to temporarily deactivate a trigger'),
+                  'triggerDecativate', TRUE,
+                  FALSE, '',
+                  '#', ''
+                ),
                 new TextAreaAttribute(
                   _('Command'), _('The command that will be called'),
                   'triggerCmd', TRUE
                 )
               ],
-              '/^([^\\|]+)\\|([^\\|]+)\\|(.*)$/',
-              '%s|%s|%s',
+              '/^([^\\|]+)\\|([^\\|]+)\\|(#?)(.*)$/',
+              '%s|%s|%s%s',
               '', // acl
               _('Triggers')
             ),
@@ -99,6 +105,7 @@ class hooksConfig extends simplePlugin
     $this->attributesAccess['fdTabHook']->setHeaders([
       _('Tab'),
       _('Mode'),
+      _('Deactivated'),
       _('Command'),
       '',
     ]);
-- 
GitLab