From 8417f56873afe60dab2f84d11adf236cd94b2a3b Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 27 May 2015 11:37:20 -0500
Subject: [PATCH] user: Ophan users who don't know they're orphaned

This stems from a bug not clearing the org_id when removing organizations
---
 include/upgrader/streams/core/9143a511-00000000.cleanup.sql | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/upgrader/streams/core/9143a511-00000000.cleanup.sql b/include/upgrader/streams/core/9143a511-00000000.cleanup.sql
index c04fdad7a..3095f761b 100644
--- a/include/upgrader/streams/core/9143a511-00000000.cleanup.sql
+++ b/include/upgrader/streams/core/9143a511-00000000.cleanup.sql
@@ -61,3 +61,9 @@ WHERE `key`='transient' AND `namespace` LIKE 'sla.%';
 
 DELETE FROM `%TABLE_PREFIX%config`
 WHERE `key`='configuration' AND `namespace` LIKE 'list.%';
+
+-- Orphan users who don't know they're orphans
+UPDATE `%TABLE_PREFIX%user` A1
+  LEFT JOIN `%TABLE_PREFIX%organization` A2 ON (A1.`org_id` = A2.`id`)
+  SET A1.`org_id` = 0
+  WHERE A2.`id` IS NULL;
-- 
GitLab