From d6ac002639d389a491c887985ff8158f97e98d09 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 6 Jan 2016 14:57:30 +0100 Subject: [PATCH] Get conversation ID from child too in scripts/upgrade.php --- scripts/upgrade.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/scripts/upgrade.php b/scripts/upgrade.php index 977cb1b5bd..33b0baa35c 100755 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -120,6 +120,7 @@ function fixupNoticeConversation() $notice = new Notice(); $notice->whereAdd('conversation is null'); + $notice->whereAdd('conversation = 0', 'OR'); $notice->orderBy('id'); // try to get originals before replies $notice->find(); @@ -129,29 +130,36 @@ function fixupNoticeConversation() $orig = clone($notice); - if (empty($notice->reply_to)) { - $notice->conversation = $notice->id; - } else { + if (!empty($notice->reply_to)) { $reply = Notice::getKV('id', $notice->reply_to); - if (empty($reply)) { - $notice->conversation = $notice->id; - } else if (empty($reply->conversation)) { - $notice->conversation = $notice->id; - } else { + if ($reply instanceof Notice && !empty($reply->conversation)) { $notice->conversation = $reply->conversation; } - unset($reply); - $reply = null; + } + + // if still empty + if (empty($notice->conversation)) { + $child = new Notice(); + $child->reply_to = $notice->getID(); + $child->limit(1); + if ($child->find(true) && !empty($child->conversation)) { + $notice->conversation = $child->conversation; + } + unset($child); + } + + // if _still_ empty we just create our own conversation + if (empty($notice->conversation)) { + $notice->conversation = $notice->getID(); } $result = $notice->update($orig); - $orig = null; unset($orig); } catch (Exception $e) { - printv("Error setting conversation: " . $e->getMessage()); + print("Error setting conversation: " . $e->getMessage()); } } -- 2.39.5