From: Evan Prodromou Date: Wed, 7 Sep 2011 20:23:49 +0000 (-0400) Subject: Move conversation table initialization to upgrade script X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=dc4f2c3b10d26a6dec2411ee879b7f6880235d37;p=quix0rs-gnu-social.git Move conversation table initialization to upgrade script --- diff --git a/scripts/init_conversation.php b/scripts/init_conversation.php deleted file mode 100755 index 675e7cabdd..0000000000 --- a/scripts/init_conversation.php +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env php -. - */ - -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); - -require_once INSTALLDIR.'/scripts/commandline.inc'; - -common_log(LOG_INFO, 'Initializing conversation table...'); - -$notice = new Notice(); -$notice->query('select distinct conversation from notice'); - -while ($notice->fetch()) { - $id = $notice->conversation; - - if ($id) { - $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())); - echo "$id "; - $conv->query($sql); - print "... "; - } -} -print "done.\n"; diff --git a/scripts/upgrade.php b/scripts/upgrade.php index 6878d0e52d..64bc5da0e5 100755 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -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();