From c2908ebf9583b328f21083904c3621a0a62b663c Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 18 May 2015 15:51:43 -0500
Subject: [PATCH] Drop `content_id` and `lang` from %content

---
 include/class.page.php                        | 10 ++-----
 .../core/9143a511-00000000.cleanup.sql        | 28 +++++++++++++++++++
 .../core/9143a511-959aca6e.cleanup.sql        | 11 --------
 .../streams/core/9143a511-959aca6e.patch.sql  | 11 --------
 .../streams/core/f5692e24-4323a6a8.patch.sql  |  6 +---
 setup/inc/streams/core/install-mysql.sql      |  2 --
 6 files changed, 32 insertions(+), 36 deletions(-)
 create mode 100644 include/upgrader/streams/core/9143a511-00000000.cleanup.sql
 delete mode 100644 include/upgrader/streams/core/9143a511-959aca6e.cleanup.sql
 delete mode 100644 include/upgrader/streams/core/9143a511-959aca6e.patch.sql

diff --git a/include/class.page.php b/include/class.page.php
index a49a7b263..2e502548a 100644
--- a/include/class.page.php
+++ b/include/class.page.php
@@ -275,13 +275,9 @@ class Page extends VerySimpleModel {
         $this->isactive = (bool) $vars['isactive'];
         $this->notes = Format::sanitize($vars['notes']);
 
-        if (!isset($this->id)) {
-            if ($this->save()) {
-                $this->content_id = $this->id;
-                $rv = $this->save();
-            }
-        }
-        elseif ($this->save())
+        $isnew = !isset($this->id);
+        $rv = $this->save();
+        if (!$isnew)
             $rv = $this->saveTranslations($vars, $errors);
 
         // Attach inline attachments from the editor
diff --git a/include/upgrader/streams/core/9143a511-00000000.cleanup.sql b/include/upgrader/streams/core/9143a511-00000000.cleanup.sql
new file mode 100644
index 000000000..f020b9af3
--- /dev/null
+++ b/include/upgrader/streams/core/9143a511-00000000.cleanup.sql
@@ -0,0 +1,28 @@
+/**
+ * @signature 959aca6ed189cd918d227a3ea8a135a3
+ * @version v1.9.6
+ * @title Retire `private`, `required`, and `edit_mask` for fields
+ *
+ */
+
+ALTER TABLE `%TABLE_PREFIX%form_field`
+    DROP `private`,
+    DROP `required`,
+    DROP `edit_mask`;
+
+ALTER TABLE `%TABLE_PREFIX%content`
+    DROP `lang`;
+
+-- DROP IF EXISTS `%content.content_id`
+SET @s = (SELECT IF(
+    (SELECT COUNT(*)
+        FROM INFORMATION_SCHEMA.COLUMNS
+        WHERE table_name = '%TABLE_PREFIX%content'
+        AND table_schema = DATABASE()
+        AND column_name = 'content_id'
+    ) > 0,
+    "SELECT 1",
+    "ALTER TABLE `%TABLE_PREFIX%content` DROP `content_id`"
+));
+PREPARE stmt FROM @s;
+EXECUTE stmt;
diff --git a/include/upgrader/streams/core/9143a511-959aca6e.cleanup.sql b/include/upgrader/streams/core/9143a511-959aca6e.cleanup.sql
deleted file mode 100644
index 1961edddc..000000000
--- a/include/upgrader/streams/core/9143a511-959aca6e.cleanup.sql
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * @signature 959aca6ed189cd918d227a3ea8a135a3
- * @version v1.9.6
- * @title Retire `private`, `required`, and `edit_mask` for fields
- *
- */
-
-ALTER TABLE `%TABLE_PREFIX%form_field`
-    DROP `private`,
-    DROP `required`,
-    DROP `edit_mask`;
diff --git a/include/upgrader/streams/core/9143a511-959aca6e.patch.sql b/include/upgrader/streams/core/9143a511-959aca6e.patch.sql
deleted file mode 100644
index 706c255b3..000000000
--- a/include/upgrader/streams/core/9143a511-959aca6e.patch.sql
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * @signature 959aca6ed189cd918d227a3ea8a135a3
- * @version v1.9.6
- * @title Retire `private`, `required`, and `edit_mask` for fields
- *
- */
-
--- Finished with patch
-UPDATE `%TABLE_PREFIX%config`
-    SET `value` = '959aca6ed189cd918d227a3ea8a135a3'
-    WHERE `key` = 'schema_signature' AND `namespace` = 'core';
diff --git a/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql b/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql
index 39d7cb469..67a21aa77 100644
--- a/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql
+++ b/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql
@@ -69,11 +69,7 @@ ALTER TABLE `%TABLE_PREFIX%help_topic`
 -- Add `content_id` to the content table to allow for translations
 RENAME TABLE `%TABLE_PREFIX%page` TO `%TABLE_PREFIX%content`;
 ALTER TABLE `%TABLE_PREFIX%content`
-  CHANGE `type` `type` varchar(32) NOT NULL default 'other',
-  ADD `content_id` int(10) unsigned NOT NULL default 0 AFTER `id`;
-
-UPDATE `%TABLE_PREFIX%content`
-  SET `content_id` = `id`;
+  CHANGE `type` `type` varchar(32) NOT NULL default 'other';
 
 DROP TABLE IF EXISTS `%TABLE_PREFIX%user_account`;
 CREATE TABLE `%TABLE_PREFIX%user_account` (
diff --git a/setup/inc/streams/core/install-mysql.sql b/setup/inc/streams/core/install-mysql.sql
index 7914d88d4..9226cabec 100644
--- a/setup/inc/streams/core/install-mysql.sql
+++ b/setup/inc/streams/core/install-mysql.sql
@@ -799,12 +799,10 @@ CREATE TABLE `%TABLE_PREFIX%task` (
 -- pages
 CREATE TABLE IF NOT EXISTS `%TABLE_PREFIX%content` (
   `id` int(10) unsigned NOT NULL auto_increment,
-  `content_id` int(10) unsigned NOT NULL default '0',
   `isactive` tinyint(1) unsigned NOT NULL default '0',
   `type` varchar(32) NOT NULL default 'other',
   `name` varchar(255) NOT NULL,
   `body` text NOT NULL,
-  `lang` varchar(16) NOT NULL default 'en_US',
   `notes` text,
   `created` datetime NOT NULL,
   `updated` datetime NOT NULL,
-- 
GitLab