From a4c026226f90d2f48f8b0a62e3b989f49bf8d02a Mon Sep 17 00:00:00 2001
From: aydreeihn <adriane@enhancesoft.com>
Date: Wed, 12 Sep 2018 13:43:07 -0500
Subject: [PATCH] Retain Help Topics for Emails

If a Help Topic is disabled or archived and it is also selected as the Help Topic for an Email, make sure we do not remove that Help Topic from the Email. Instead, if that email receives a Ticket, we should just assign the ticket to the Default Help Topic. If there is no Default Help Topic, the Ticket will not have a Help Topic at all.
---
 include/class.topic.php | 13 -------------
 scp/helptopics.php      | 13 ++-----------
 2 files changed, 2 insertions(+), 24 deletions(-)

diff --git a/include/class.topic.php b/include/class.topic.php
index 75c06b7df..32df895cd 100644
--- a/include/class.topic.php
+++ b/include/class.topic.php
@@ -195,19 +195,6 @@ implements TemplateVariable, Searchable {
       return !!($this->flags & self::FLAG_ACTIVE);
     }
 
-    function clearInactiveTopic($topic_id) {
-      global $cfg;
-
-      $emails = Email::objects()->filter(array('topic_id'=>$topic_id))->values_flat('email_id');
-      if ($emails) {
-        foreach ($emails as $email_id) {
-          $email = Email::lookup($email_id[0]);
-          $email->topic_id = $cfg->getDefaultTopicId();
-          $email->save();
-        }
-      }
-    }
-
     function getStatus() {
       if($this->flags & self::FLAG_ACTIVE)
         return 'Active';
diff --git a/scp/helptopics.php b/scp/helptopics.php
index ea1d7b8bd..40580549e 100644
--- a/scp/helptopics.php
+++ b/scp/helptopics.php
@@ -28,9 +28,6 @@ if($_POST){
             if(!$topic){
                 $errors['err']=sprintf(__('%s: Unknown or invalid'), __('help topic'));
             }elseif($topic->update($_POST,$errors)){
-              if ($_POST["status"] != __('Active'))
-                Topic::clearInactiveTopic($topic->getId());
-
                 $msg=sprintf(__('Successfully updated %s.'),
                     __('this help topic'));
             }elseif(!$errors['err']){
@@ -101,11 +98,8 @@ if($_POST){
                           $t->setFlag(Topic::FLAG_ACTIVE, false);
                           $filter_actions = FilterAction::objects()->filter(array('type' => 'topic', 'configuration' => '{"topic_id":'. $t->getId().'}'));
                           FilterAction::setFilterFlag($filter_actions, 'topic', true);
-                          if($t->save()) {
+                          if($t->save())
                             $num++;
-                            //remove topic_id for emails using disabled topic
-                            Topic::clearInactiveTopic($t->getId());
-                          }
                         }
                         if ($num > 0) {
                             if($num==$count)
@@ -130,11 +124,8 @@ if($_POST){
                           $t->setFlag(Topic::FLAG_ACTIVE, false);
                           $filter_actions = FilterAction::objects()->filter(array('type' => 'topic', 'configuration' => '{"topic_id":'. $t->getId().'}'));
                           FilterAction::setFilterFlag($filter_actions, 'topic', true);
-                          if($t->save()) {
+                          if($t->save())
                             $num++;
-                            //remove topic_id for emails using disabled topic
-                            Topic::clearInactiveTopic($t->getId());
-                          }
                         }
                         if ($num > 0) {
                             if($num==$count)
-- 
GitLab