From f64242e3379997ea6f39df93571bd53d3b82cddd Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Mon, 17 Dec 2012 13:27:13 -0500
Subject: [PATCH] Refactor DB schema signature

---
 .../upgrader/sql/00ff231f-9f3b454c.patch.sql  | 27 ++++++++++++++++---
 main.inc.php                                  |  2 +-
 setup/inc/sql/osTicket-mysql.sql              |  9 ++++---
 setup/inc/sql/osTicket-mysql.sql.md5          |  2 +-
 4 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/include/upgrader/sql/00ff231f-9f3b454c.patch.sql b/include/upgrader/sql/00ff231f-9f3b454c.patch.sql
index d90d48130..7c3e3bd3c 100644
--- a/include/upgrader/sql/00ff231f-9f3b454c.patch.sql
+++ b/include/upgrader/sql/00ff231f-9f3b454c.patch.sql
@@ -1,17 +1,38 @@
 /**
  * @version v1.7 RC4
- * @signature c2a64ea46d1fb749f5d908820bb813a0
+ * @signature 9f3b454c06dfd5ee96003eae5182ac13
  *
  *  - Supports starts- and ends-with in ticket filter rules
  *  - Fix assigned template variable
+ *  - Allow nested templates to have duplicate names
+ *  - New permission settings for API key  & groups
  */
 
 ALTER TABLE  `%TABLE_PREFIX%filter_rule` CHANGE  `how`  `how` ENUM(  'equal',
     'not_equal',  'contains',  'dn_contain',  'starts',  'ends' );
 
--- %message
+-- templates -> %message
 UPDATE `%TABLE_PREFIX%email_template`
     SET `assigned_alert_body` = REPLACE(`assigned_alert_body`, '%message', '%{comments}');
 
+-- API Access.
+ALTER TABLE  `%TABLE_PREFIX%api_key`
+    CHANGE  `isactive`  `isactive` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT  '1',
+    ADD  `can_create_tickets` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT  '1' AFTER  `apikey`,
+    DROP INDEX  `ipaddr`,
+    ADD INDEX  `ipaddr` (  `ipaddr` );
+
+-- Help topics 
+ALTER TABLE  `%TABLE_PREFIX%help_topic` 
+    DROP INDEX  `topic` ,
+    ADD UNIQUE  `topic` (  `topic` ,  `topic_pid` );
+
+
+-- group settings.
+ALTER TABLE  `%TABLE_PREFIX%groups` 
+    ADD  `can_post_ticket_reply` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT  '1' AFTER  `can_transfer_tickets` ,
+    ADD  `can_view_staff_stats` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT  '0' AFTER  `can_post_ticket_reply`;
+
+-- update schema signature.
 UPDATE `%TABLE_PREFIX%config`
-    SET `schema_signature`='c2a64ea46d1fb749f5d908820bb813a0';
+    SET `schema_signature`='9f3b454c06dfd5ee96003eae5182ac13';
diff --git a/main.inc.php b/main.inc.php
index 5b5fc5931..baf06e4ec 100644
--- a/main.inc.php
+++ b/main.inc.php
@@ -63,7 +63,7 @@
 
     #Current version && schema signature (Changes from version to version)
     define('THIS_VERSION','1.7-RC3+'); //Shown on admin panel
-    define('SCHEMA_SIGNATURE','00ff231f2ade8797a0e7f2a7fccd52f4'); //MD5 signature of the db schema. (used to trigger upgrades)
+    define('SCHEMA_SIGNATURE','9f3b454c06dfd5ee96003eae5182ac13'); //MD5 signature of the db schema. (used to trigger upgrades)
     #load config info
     $configfile='';
     if(file_exists(ROOT_DIR.'ostconfig.php')) //Old installs prior to v 1.6 RC5
diff --git a/setup/inc/sql/osTicket-mysql.sql b/setup/inc/sql/osTicket-mysql.sql
index 688646f43..004b99340 100644
--- a/setup/inc/sql/osTicket-mysql.sql
+++ b/setup/inc/sql/osTicket-mysql.sql
@@ -5,11 +5,12 @@ CREATE TABLE `%TABLE_PREFIX%api_key` (
   `isactive` tinyint(1) NOT NULL default '1',
   `ipaddr` varchar(64) NOT NULL,
   `apikey` varchar(255) NOT NULL,
+  `can_create_tickets` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT  '1',
   `notes` text,
   `updated` datetime NOT NULL,
   `created` datetime NOT NULL,
   PRIMARY KEY  (`id`),
-  UNIQUE KEY `ipaddr` (`ipaddr`),
+  KEY `ipaddr` (`ipaddr`),
   UNIQUE KEY `apikey` (`apikey`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
@@ -133,7 +134,7 @@ CREATE TABLE `%TABLE_PREFIX%config` (
   `assigned_alert_team_members` tinyint(1) unsigned NOT NULL default '0',
   `auto_assign_reopened_tickets` tinyint(1) unsigned NOT NULL default '1',
   `show_related_tickets` tinyint(1) unsigned NOT NULL default '1',
-  `show_assigned_tickets` tinyint(1) unsigned NOT NULL default '0',
+  `show_assigned_tickets` tinyint(1) unsigned NOT NULL default '1',
   `show_answered_tickets` tinyint(1) unsigned NOT NULL default '0',
   `show_notes_inline` tinyint(1) unsigned NOT NULL default '1',
   `hide_staff_name` tinyint(1) unsigned NOT NULL default '0',
@@ -355,6 +356,7 @@ CREATE TABLE `%TABLE_PREFIX%groups` (
   `group_name` varchar(50) NOT NULL default '',
   `can_create_tickets` tinyint(1) unsigned NOT NULL default '1',
   `can_edit_tickets` tinyint(1) unsigned NOT NULL default '1',
+  `can_post_ticket_reply` tinyint( 1 ) unsigned NOT NULL DEFAULT  '1',
   `can_delete_tickets` tinyint(1) unsigned NOT NULL default '0',
   `can_close_tickets` tinyint(1) unsigned NOT NULL default '1',
   `can_assign_tickets` tinyint(1) unsigned NOT NULL default '1',
@@ -362,6 +364,7 @@ CREATE TABLE `%TABLE_PREFIX%groups` (
   `can_ban_emails` tinyint(1) unsigned NOT NULL default '0',
   `can_manage_premade` tinyint(1) unsigned NOT NULL default '0',
   `can_manage_faq` tinyint(1) unsigned NOT NULL default '0',
+  `can_view_staff_stats` tinyint( 1 ) unsigned NOT NULL DEFAULT  '0',
   `notes` text,
   `created` datetime NOT NULL,
   `updated` datetime NOT NULL,
@@ -402,7 +405,7 @@ CREATE TABLE `%TABLE_PREFIX%help_topic` (
   `created` datetime NOT NULL,
   `updated` datetime NOT NULL,
   PRIMARY KEY  (`topic_id`),
-  UNIQUE KEY `topic` (`topic`),
+  UNIQUE KEY `topic` ( `topic` ,  `topic_pid` ),
   KEY `topic_pid` (`topic_pid`),
   KEY `priority_id` (`priority_id`),
   KEY `dept_id` (`dept_id`),
diff --git a/setup/inc/sql/osTicket-mysql.sql.md5 b/setup/inc/sql/osTicket-mysql.sql.md5
index d46d0cc2e..49a6e93dd 100644
--- a/setup/inc/sql/osTicket-mysql.sql.md5
+++ b/setup/inc/sql/osTicket-mysql.sql.md5
@@ -1 +1 @@
-c2a64ea46d1fb749f5d908820bb813a0
+9f3b454c06dfd5ee96003eae5182ac13
-- 
GitLab