From 7770208a916c60ccf51a2eea8b0cb6da65aaccf2 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Thu, 9 Jan 2014 22:11:32 +0000 Subject: [PATCH] Add patch for various db issues and enhancements Conflicts: include/upgrader/streams/core.sig --- include/class.thread.php | 12 ++--- include/upgrader/streams/core.sig | 2 +- .../streams/core/ed60ba20-84737218.patch.sql | 50 +++++++++++++++++++ setup/inc/streams/core/install-mysql.sql | 16 +++--- 4 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 include/upgrader/streams/core/ed60ba20-84737218.patch.sql diff --git a/include/class.thread.php b/include/class.thread.php index 975a3a472..508470d67 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -181,7 +181,7 @@ class Thread { /* XXX: Leave this out until TICKET_EMAIL_INFO_TABLE has a primary * key $sql = 'DELETE mid.* FROM '.TICKET_EMAIL_INFO_TABLE.' mid - INNER JOIN '.TICKET_THREAD_TABLE.' thread ON (thread.id = mid.message_id) + INNER JOIN '.TICKET_THREAD_TABLE.' thread ON (thread.id = mid.thread_id) WHERE thread.ticket_id = '.db_input($this->getTicketId()); db_query($sql); */ @@ -244,7 +244,7 @@ Class ThreadEntry { .' ,count(DISTINCT attach.attach_id) as attachments ' .' FROM '.TICKET_THREAD_TABLE.' thread ' .' LEFT JOIN '.TICKET_EMAIL_INFO_TABLE.' info - ON (thread.id=info.message_id) ' + ON (thread.id=info.thread_id) ' .' LEFT JOIN '.TICKET_ATTACHMENT_TABLE.' attach ON (thread.ticket_id=attach.ticket_id AND thread.id=attach.ref_id @@ -337,7 +337,7 @@ Class ThreadEntry { require_once(INCLUDE_DIR.'class.mailparse.php'); $sql = 'SELECT headers FROM '.TICKET_EMAIL_INFO_TABLE - .' WHERE message_id='.$this->getId(); + .' WHERE thread_id='.$this->getId(); $headers = db_result(db_query($sql)); return Mail_Parse::splitHeaders($headers); } @@ -643,7 +643,7 @@ Class ThreadEntry { /* static */ function logEmailHeaders($id, $mid, $header=false) { $sql='INSERT INTO '.TICKET_EMAIL_INFO_TABLE - .' SET message_id='.db_input($id) //TODO: change it to thread_id + .' SET thread_id='.db_input($id) .', email_mid='.db_input($mid); //TODO: change it to message_id. if ($header) $sql .= ', headers='.db_input($header); @@ -708,8 +708,8 @@ Class ThreadEntry { function lookupByEmailHeaders($mailinfo, &$seen=false) { // Search for messages using the References header, then the // in-reply-to header - $search = 'SELECT message_id, email_mid FROM '.TICKET_EMAIL_INFO_TABLE - . ' WHERE email_mid=%s ORDER BY message_id DESC'; + $search = 'SELECT thread_id, email_mid FROM '.TICKET_EMAIL_INFO_TABLE + . ' WHERE email_mid=%s ORDER BY thread_id DESC'; if (list($id, $mid) = db_fetch_row(db_query( sprintf($search, db_input($mailinfo['mid']))))) { diff --git a/include/upgrader/streams/core.sig b/include/upgrader/streams/core.sig index 4fecf9e08..a0a9b1bd8 100644 --- a/include/upgrader/streams/core.sig +++ b/include/upgrader/streams/core.sig @@ -1 +1 @@ -ed60ba203a473f4f32ac49eb45db16c7 +8473721890e9eddb6417076c96b715a1 diff --git a/include/upgrader/streams/core/ed60ba20-84737218.patch.sql b/include/upgrader/streams/core/ed60ba20-84737218.patch.sql new file mode 100644 index 000000000..975dbad33 --- /dev/null +++ b/include/upgrader/streams/core/ed60ba20-84737218.patch.sql @@ -0,0 +1,50 @@ +/** + * @version v1.8.1 + * @signature 8473721890e9eddb6417076c96b715a1 + * @title Various schema improvements and bug fixes + * + */ + +-- [#317](https://github.com/osTicket/osTicket-1.8/issues/317) +ALTER TABLE `%TABLE_PREFIX%faq` + CHANGE `created` `created` datetime NOT NULL, + CHANGE `updated` `updated` datetime NOT NULL; + +-- [#328](https://github.com/osTicket/osTicket-1.8/issues/328) +UPDATE `%TABLE_PREFIX%filter_rule` + SET `how` = 'equal' WHERE `how` IS NULL; + +-- [#331](https://github.com/osTicket/osTicket-1.8/issues/331) +ALTER TABLE `%TABLE_PREFIX%ticket_email_info` + CHANGE `message_id` `thread_id` int(11) unsigned NOT NULL, + ADD PRIMARY KEY (`thread_id`), + DROP INDEX `message_id`, + ADD INDEX `email_mid` (`email_mid`); + +-- [#386](https://github.com/osTicket/osTicket-1.8/issues/386) +UPDATE `%TABLE_PREFIX%email_template` + SET `body` = REPLACE(`body`, '%{recipient}', '%{recipient.name}'); + +-- Change EndUser link to be recipient specific +UPDATE `%TABLE_PREFIX%email_template` + SET `body` = REPLACE(`body`, '%{ticket.client_link}', '%{recipient.ticket_link}'); + +-- Add inline flag and drop ref_type +ALTER TABLE `%TABLE_PREFIX%ticket_attachment` + ADD `inline` tinyint(1) NOT NULL default 0 AFTER `ref_id`, + DROP `ref_type`; + +ALTER TABLE `%TABLE_PREFIX%ticket_thread` + ADD `user_id` int(11) unsigned not null default 0 AFTER `staff_id`; + +ALTER TABLE `%TABLE_PREFIX%ticket` + ADD `email_id` int(11) unsigned not null default 0 AFTER `team_id`, + CHANGE `ticketID` `number` varchar(20); + +ALTER TABLE `%TABLE_PREFIX%ticket_collaborator` + ADD`created` datetime NOT NULL AFTER `role`; + +-- Finished with patch +UPDATE `%TABLE_PREFIX%config` + SET `value` = '8473721890e9eddb6417076c96b715a1' + 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 060c31148..8d348ba4f 100644 --- a/setup/inc/streams/core/install-mysql.sql +++ b/setup/inc/streams/core/install-mysql.sql @@ -33,8 +33,8 @@ CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%faq` ( `answer` text NOT NULL, `keywords` tinytext, `notes` text, - `created` date NOT NULL, - `updated` date NOT NULL, + `created` datetime NOT NULL, + `updated` datetime NOT NULL, PRIMARY KEY (`faq_id`), UNIQUE KEY `question` (`question`), KEY `category_id` (`category_id`), @@ -506,7 +506,7 @@ CREATE TABLE `%TABLE_PREFIX%team_member` ( DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket`; CREATE TABLE `%TABLE_PREFIX%ticket` ( `ticket_id` int(11) unsigned NOT NULL auto_increment, - `ticketID` int(11) unsigned NOT NULL default '0', + `number` varchar(20), `user_id` int(11) unsigned NOT NULL default '0', `user_email_id` int(11) unsigned NOT NULL default '0', `dept_id` int(10) unsigned NOT NULL default '0', @@ -514,6 +514,7 @@ CREATE TABLE `%TABLE_PREFIX%ticket` ( `topic_id` int(10) unsigned NOT NULL default '0', `staff_id` int(10) unsigned NOT NULL default '0', `team_id` int(10) unsigned NOT NULL default '0', + `email_id` int(11) unsigned NOT NULL default '0', `ip_address` varchar(64) NOT NULL default '', `status` enum('open','closed') NOT NULL default 'open', `source` enum('Web','Email','Phone','API','Other') NOT NULL default 'Other', @@ -544,11 +545,10 @@ CREATE TABLE `%TABLE_PREFIX%ticket_attachment` ( `ticket_id` int(11) unsigned NOT NULL default '0', `file_id` int(10) unsigned NOT NULL default '0', `ref_id` int(11) unsigned NOT NULL default '0', - `ref_type` enum('M','R','N') NOT NULL default 'M', + `inline` tinyint(1) NOT NULL default '0', `created` datetime NOT NULL, PRIMARY KEY (`attach_id`), KEY `ticket_id` (`ticket_id`), - KEY `ref_type` (`ref_type`), KEY `ref_id` (`ref_id`), KEY `file_id` (`file_id`) ) DEFAULT CHARSET=utf8; @@ -567,10 +567,11 @@ CREATE TABLE `%TABLE_PREFIX%ticket_lock` ( DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_email_info`; CREATE TABLE `%TABLE_PREFIX%ticket_email_info` ( - `message_id` int(11) unsigned NOT NULL, + `thread_id` int(11) unsigned NOT NULL, `email_mid` varchar(255) NOT NULL, `headers` text, - KEY `message_id` (`email_mid`) + PRIMARY KEY (`thread_id`), + KEY `email_mid` (`email_mid`) ) DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_event`; @@ -629,6 +630,7 @@ CREATE TABLE `%TABLE_PREFIX%ticket_collaborator` ( `user_id` int(11) unsigned NOT NULL DEFAULT '0', -- M => (message) clients, N => (note) 3rd-Party, R => (reply) external authority `role` char(1) NOT NULL DEFAULT 'M', + `created` datetime NOT NULL, `updated` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `collab` (`ticket_id`,`user_id`) -- GitLab