From b7e02ceca34c8075aeeccc6ca7b8d7e0a66a3429 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 22 Oct 2013 12:59:54 +0000
Subject: [PATCH] Avoid double-encoding canned responses on upgrade

---
 .../streams/core/d51f303a-dad45ca2.patch.sql  | 54 +++++++++----------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/include/upgrader/streams/core/d51f303a-dad45ca2.patch.sql b/include/upgrader/streams/core/d51f303a-dad45ca2.patch.sql
index 94b8f8aa7..b08acdc73 100644
--- a/include/upgrader/streams/core/d51f303a-dad45ca2.patch.sql
+++ b/include/upgrader/streams/core/d51f303a-dad45ca2.patch.sql
@@ -47,89 +47,89 @@ CREATE TABLE `%TABLE_PREFIX%draft` (
 UPDATE `%TABLE_PREFIX%email_template`
     SET `body` = REPLACE( REPLACE( REPLACE( REPLACE(
         `body`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 
 -- Migrate notes to HTML
 UPDATE `%TABLE_PREFIX%api_key`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%email`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%email_template_group`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%faq`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%faq_category`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%filter`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%groups`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%help_topic`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%page`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%sla`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%staff`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 UPDATE `%TABLE_PREFIX%team`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
@@ -142,16 +142,16 @@ UPDATE `%TABLE_PREFIX%team`
 UPDATE `%TABLE_PREFIX%canned_response`
     SET `notes` = REPLACE( REPLACE( REPLACE( REPLACE(
         `notes`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
         '\n', '<br/>'),
-        '&', '&amp;'),
     `response` = REPLACE( REPLACE( REPLACE( REPLACE(
         `response`,
+        '&', '&amp;'),
         '<', '&lt;'),
         '>', '&gt;'),
-        '\n', '<br/>'),
-        '&', '&amp;');
+        '\n', '<br/>');
 
 -- Migrate ticket-thread to HTML
 -- XXX: Migrate & -> &amp; ? -- the problem is that there's a fix in 1.7.1
-- 
GitLab