From a35d0fb4b7f2afa48b7ce8b817e758985ae9c377 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Wed, 17 Sep 2014 05:32:13 +0000
Subject: [PATCH] Add status properties to the status table.

---
 include/class.list.php                        | 26 ++++++-------------
 include/upgrader/streams/core.sig             |  2 +-
 .../core/03ff59bf-519d98cd.cleanup.sql        |  2 ++
 .../streams/core/03ff59bf-519d98cd.patch.sql  | 24 +++++++++++++++++
 setup/inc/streams/core/install-mysql.sql      |  2 +-
 5 files changed, 36 insertions(+), 20 deletions(-)
 create mode 100644 include/upgrader/streams/core/03ff59bf-519d98cd.cleanup.sql
 create mode 100644 include/upgrader/streams/core/03ff59bf-519d98cd.patch.sql

diff --git a/include/class.list.php b/include/class.list.php
index 274009de9..009f88921 100644
--- a/include/class.list.php
+++ b/include/class.list.php
@@ -766,7 +766,6 @@ class TicketStatus  extends VerySimpleModel implements CustomListItem {
 
     var $_list;
     var $_form;
-    var $_config;
     var $_settings;
     var $_properties;
 
@@ -777,7 +776,6 @@ class TicketStatus  extends VerySimpleModel implements CustomListItem {
 
     function __construct() {
         call_user_func_array(array('parent', '__construct'), func_get_args());
-        $this->_config = new Config('TS.'.$this->getId());
     }
 
     protected function hasFlag($field, $flag) {
@@ -793,7 +791,7 @@ class TicketStatus  extends VerySimpleModel implements CustomListItem {
     }
 
     protected function hasProperties() {
-        return ($this->_config->get('properties'));
+        return ($this->get('properties'));
     }
 
     function getForm() {
@@ -900,7 +898,7 @@ class TicketStatus  extends VerySimpleModel implements CustomListItem {
     private function getProperties() {
 
         if (!isset($this->_properties)) {
-            $this->_properties = $this->_config->get('properties');
+            $this->_properties = $this->get('properties');
             if (is_string($this->_properties))
                 $this->_properties = JsonDataParser::parse($this->_properties);
             elseif (!$this->_properties)
@@ -980,20 +978,16 @@ class TicketStatus  extends VerySimpleModel implements CustomListItem {
         }
 
         if (count($errors) === 0) {
+            if ($properties && is_array($properties))
+                $properties = JsonDataEncoder::encode($properties);
+
+            $this->set('properties', $properties);
             $this->save(true);
-            $this->setProperties($properties);
         }
 
         return count($errors) === 0;
     }
 
-    function setProperties($properties) {
-        if ($properties && is_array($properties))
-            $properties = JsonDataEncoder::encode($properties);
-
-        $this->_config->set('properties', $properties);
-    }
-
     function update($vars, &$errors) {
 
         $fields = array('value' => 'name', 'sort' => 'sort');
@@ -1042,13 +1036,9 @@ class TicketStatus  extends VerySimpleModel implements CustomListItem {
     static function __create($ht, &$error=false) {
         global $ost;
 
-        $properties = JsonDataEncoder::encode($ht['properties']);
-        unset($ht['properties']);
-        if ($status = TicketStatus::create($ht)) {
+        $ht['properties'] = JsonDataEncoder::encode($ht['properties']);
+        if (($status = TicketStatus::create($ht)))
             $status->save(true);
-            $status->_config = new Config('TS.'.$status->getId());
-            $status->_config->set('properties', $properties);
-        }
 
         return $status;
     }
diff --git a/include/upgrader/streams/core.sig b/include/upgrader/streams/core.sig
index 30a5aca33..d1c341c68 100644
--- a/include/upgrader/streams/core.sig
+++ b/include/upgrader/streams/core.sig
@@ -1 +1 @@
-03ff59bf35a58a102e9b32ad33c2839f
+519d98cd885f060e220da7b30a6f78ae
diff --git a/include/upgrader/streams/core/03ff59bf-519d98cd.cleanup.sql b/include/upgrader/streams/core/03ff59bf-519d98cd.cleanup.sql
new file mode 100644
index 000000000..2f39fa0f2
--- /dev/null
+++ b/include/upgrader/streams/core/03ff59bf-519d98cd.cleanup.sql
@@ -0,0 +1,2 @@
+DELETE FROM  `%TABLE_PREFIX%config`
+    WHERE  `key` = 'properties' AND  `namespace` LIKE  'TS.%';
diff --git a/include/upgrader/streams/core/03ff59bf-519d98cd.patch.sql b/include/upgrader/streams/core/03ff59bf-519d98cd.patch.sql
new file mode 100644
index 000000000..57e823f6d
--- /dev/null
+++ b/include/upgrader/streams/core/03ff59bf-519d98cd.patch.sql
@@ -0,0 +1,24 @@
+/**
+ * @version v1.9.4
+ * @signature 519d98cd885f060e220da7b30a6f78ae
+ * @title Add properties filed and drop 'resolved' state
+ *
+ * This patch drops resolved state and any associated statuses
+ *
+ */
+
+-- add properties field
+ALTER TABLE  `%TABLE_PREFIX%ticket_status`
+    ADD  `properties` TEXT NOT NULL AFTER  `sort`,
+    DROP  `notes`;
+
+UPDATE `%TABLE_PREFIX%ticket_status` s
+    INNER JOIN `ost_config` c
+        ON(c.namespace = CONCAT('TS.', s.id) AND c.key='properties')
+    SET s.properties = c.value;
+
+
+-- Set new schema signature
+UPDATE `%TABLE_PREFIX%config`
+    SET `value` = '519d98cd885f060e220da7b30a6f78ae'
+    WHERE `key` = 'schema_signature' AND `namespace` = 'core';
diff --git a/setup/inc/streams/core/install-mysql.sql b/setup/inc/streams/core/install-mysql.sql
index 4879e53ce..c130bcf2c 100644
--- a/setup/inc/streams/core/install-mysql.sql
+++ b/setup/inc/streams/core/install-mysql.sql
@@ -681,7 +681,7 @@ CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%ticket_status` (
   `mode` int(11) unsigned NOT NULL DEFAULT '0',
   `flags` int(11) unsigned NOT NULL DEFAULT '0',
   `sort` int(11) unsigned NOT NULL DEFAULT '0',
-  `notes` text NOT NULL,
+  `properties` text NOT NULL,
   `created` datetime NOT NULL,
   `updated` datetime NOT NULL,
   PRIMARY KEY (`id`),
-- 
GitLab