]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/upgrade.php
Move conversation table initialization to upgrade script
[quix0rs-gnu-social.git] / scripts / upgrade.php
index 6878d0e52d7b917385667d99f92ce009be43029b..64bc5da0e598d49b869af2314e563aa8ffc115d0 100755 (executable)
@@ -40,6 +40,7 @@ function main()
 
     fixupNoticeRendered();
     fixupNoticeConversation();
+    initConversation();
     fixupGroupURI();
 }
 
@@ -153,4 +154,33 @@ function fixupGroupURI()
     printfnq("DONE.\n");
 }
 
+function initConversation()
+{
+    printfnq("Ensuring all conversations have a row in conversation table...");
+
+    $notice = new Notice();
+    $notice->query('select distinct notice.conversation from notice '.
+                   'where notice.conversation is not null '.
+                   'and not exists (select conversation.id from conversation where id = notice.conversation)');
+
+    while ($notice->fetch()) {
+
+        $id = $notice->conversation;
+
+        $uri = common_local_url('conversation', array('id' => $id));
+
+        // @fixme db_dataobject won't save our value for an autoincrement
+        // so we're bypassing the insert wrappers
+        $conv = new Conversation();
+        $sql = "insert into conversation (id,uri,created) values(%d,'%s','%s')";
+        $sql = sprintf($sql,
+                       $id,
+                       $conv->escape($uri),
+                       $conv->escape(common_sql_now()));
+        $conv->query($sql);
+    }
+
+    printfnq("DONE.\n");
+}
+
 main();