From 54ab33c0f27a83dabdc46e118085d6ffb866875a Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 9 Apr 2014 16:50:30 -0500 Subject: [PATCH] Retroactively add the `format` column to ticket_thread This will make upgrades from osTicket < 1.8.0 substantially faster and more reliable, considering that the previous ticket threads will not need to be explicitly converted to html. --- .../streams/core/d51f303a-dad45ca2.patch.sql | 18 +++--------------- .../streams/core/f5692e24-4323a6a8.patch.sql | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/upgrader/streams/core/d51f303a-dad45ca2.patch.sql b/include/upgrader/streams/core/d51f303a-dad45ca2.patch.sql index 19ddac83b..936b3b0c2 100644 --- a/include/upgrader/streams/core/d51f303a-dad45ca2.patch.sql +++ b/include/upgrader/streams/core/d51f303a-dad45ca2.patch.sql @@ -156,21 +156,9 @@ UPDATE `%TABLE_PREFIX%canned_response` '>', '>'), '\n', '<br/>'); --- Migrate ticket-thread to HTML --- XXX: Migrate & -> & ? -- the problem is that there's a fix in 1.7.1 --- that properly encodes these characters, so encoding & would mean possible --- double encoding. -UPDATE `%TABLE_PREFIX%ticket_thread` - SET `body` = REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( - `body`, - '\r', ''), - '\n ', '\n'), - '\n\n\n', '\n\n'), - '\n\n\n', '\n\n'), - '\n\n\n', '\n\n'), - '<', '<'), - '>', '>'), - '\n', '<br/>'); +-- Mark all thread entries as text +ALTER TABLE `%TABLE_PREFIX%ticket_thread` + ADD `format` varchar(16) NOT NULL default 'text' AFTER `body`; -- Finished with patch UPDATE `%TABLE_PREFIX%config` diff --git a/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql b/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql index ee2296eb5..a75a8372d 100644 --- a/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql +++ b/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql @@ -136,6 +136,25 @@ UPDATE `%TABLE_PREFIX%content` SET `content_id` = LAST_INSERT_ID() DELETE FROM `%TABLE_PREFIX%email_template` WHERE `code_name` IN ('staff.pwreset', 'user.accesslink'); +-- The original patch for d51f303a-dad45ca2.patch.sql migrated all the +-- thread entries from text to html. Now that the format column exists in +-- the ticket_thread table, we opted to retroactively add the format column +-- to the dad45ca2 patch. Therefore, anyone upgrading from osTicket < 1.8.0 +-- to v1.8.2 and further will alreay have a `format` column when they arrive +-- at this patch. In such a case, we'll just change the default to 'html' +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = '%TABLE_PREFIX%ticket_thread' + AND table_schema = DATABASE() + AND column_name = 'format' + ) > 0, + "ALTER TABLE `%TABLE_PREFIX%ticket_thread` CHANGE `format` `format` varchar(16) NOT NULL default 'html'", + "ALTER TABLE `%TABLE_PREFIX%ticket_thread` ADD `format` varchar(16) NOT NULL default 'html' AFTER `body`" +)); +PREPARE stmt FROM @s; +EXECUTE stmt; + -- Finished with patch UPDATE `%TABLE_PREFIX%config` SET `value` = '4323a6a81c35efbf7722b7fc4e475440' -- GitLab