From 66cbb45386930debca1af4ac28850b8c57b33be7 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 19 Jun 2014 10:37:43 -0500
Subject: [PATCH] oops: Don't crash installing help topics

---
 include/class.topic.php            | 10 +++++++---
 include/i18n/en_US/help_topic.yaml |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/class.topic.php b/include/class.topic.php
index c415b157a..ee0f2a47e 100644
--- a/include/class.topic.php
+++ b/include/class.topic.php
@@ -351,7 +351,9 @@ class Topic {
         } else {
             if (isset($vars['topic_id']))
                 $sql .= ', topic_id='.db_input($vars['topic_id']);
-            if ($vars['topic_pid'] && $cfg->getTopicSortMode() != 'a') {
+            // If in manual sort mode, place the new item directly below the
+            // parent item
+            if ($vars['topic_pid'] && $cfg && $cfg->getTopicSortMode() != 'a') {
                 $sql .= ', `sort`='.db_input(
                     db_result(db_query('SELECT COALESCE(`sort`,0)+1 FROM '.TOPIC_TABLE
                         .' WHERE `topic_id`='.db_input($vars['topic_pid']))));
@@ -363,7 +365,7 @@ class Topic {
             else
                 $errors['err']='Unable to create the topic. Internal error';
         }
-        if ($cfg->getTopicSortMode() == 'a') {
+        if (!$cfg || $cfg->getTopicSortMode() == 'a') {
             static::updateSortOrder();
         }
         return $rv;
@@ -371,7 +373,9 @@ class Topic {
 
     static function updateSortOrder() {
         // Fetch (un)sorted names
-        $names = static::getHelpTopics(false, true);
+        if (!($names = static::getHelpTopics(false, true)))
+            return;
+
         uasort($names, function($a, $b) { return strcmp($a, $b); });
 
         $update = array_keys($names);
diff --git a/include/i18n/en_US/help_topic.yaml b/include/i18n/en_US/help_topic.yaml
index 508590a57..ee9e9aa40 100644
--- a/include/i18n/en_US/help_topic.yaml
+++ b/include/i18n/en_US/help_topic.yaml
@@ -43,7 +43,7 @@
   notes: |
     Product, service, or equipment related issues
 
-- pid: 10
+- topic_pid: 10
   isactive: 1
   ispublic: 1
   dept_id: 1
-- 
GitLab