From: Evan Prodromou Date: Wed, 7 Sep 2011 20:48:10 +0000 (-0400) Subject: Move inbox initialization to upgrade.php X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9ed1beb3a00f8919e3c15b9f34bcc7e655ec813c;p=quix0rs-gnu-social.git Move inbox initialization to upgrade.php Move the inbox initialization code to upgrade.php. Might not catch group messages, but maybe that's not a big deal. --- diff --git a/scripts/initializeinbox.php b/scripts/initializeinbox.php deleted file mode 100644 index 44508fe22a..0000000000 --- a/scripts/initializeinbox.php +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env php -. - */ - -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); - -$shortoptions = 'i:n:af:'; -$longoptions = array('id=', 'nickname=', 'all', 'file='); - -$helptext = <<find()) { - while ($user->fetch()) { - initializeInbox($user); - } - } - } else if (have_option('f', 'file')) { - $filename = get_option_value('f', 'file'); - if (!file_exists($filename)) { - throw new Exception("No such file '$filename'."); - } else if (!is_readable($filename)) { - throw new Exception("Can't read '$filename'."); - } - $ids = file($filename); - foreach ($ids as $id) { - $user = User::staticGet('id', $id); - if (empty($user)) { - print "Can't find user with id '$id'.\n"; - } - initializeInbox($user); - } - } else { - show_help(); - exit(1); - } -} catch (Exception $e) { - print $e->getMessage()."\n"; - exit(1); -} - -function initializeInbox($user) -{ - if (!have_option('q', 'quiet')) { - print "Initializing inbox for $user->nickname..."; - } - - $inbox = Inbox::staticGet('user_id', $user->id); - - if ($inbox && !empty($inbox->fake)) { - if (!have_option('q', 'quiet')) { - echo "(replacing faux cached inbox)"; - } - $inbox = false; - } - if (!empty($inbox)) { - if (!have_option('q', 'quiet')) { - print "SKIP\n"; - } - } else { - $inbox = Inbox::initialize($user->id); - if (!have_option('q', 'quiet')) { - if (empty($inbox)) { - print "ERR\n"; - } else { - print "DONE\n"; - } - } - } -} diff --git a/scripts/upgrade.php b/scripts/upgrade.php old mode 100755 new mode 100644 index 64bc5da0e5..3536eddb63 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -42,6 +42,7 @@ function main() fixupNoticeConversation(); initConversation(); fixupGroupURI(); + initInbox(); } function tableDefs() @@ -183,4 +184,48 @@ function initConversation() printfnq("DONE.\n"); } +function initInbox() +{ + printfnq("Ensuring all users have an inbox..."); + + $user = new User(); + $user->whereAdd('not exists (select user_id from inbox where user_id = user.id)'); + $user->orderBy('id'); + + if ($user->find()) { + + while ($user->fetch()) { + + try { + $notice = new Notice(); + + $notice->selectAdd(); + $notice->selectAdd('id'); + $notice->joinAdd(array('profile_id', 'subscription:subscribed')); + $notice->whereAdd('subscription.subscriber = ' . $user->id); + $notice->whereAdd('notice.created >= subscription.created'); + + $ids = array(); + + if ($notice->find()) { + while ($notice->fetch()) { + $ids[] = $notice->id; + } + } + + $notice = null; + + $inbox = new Inbox(); + $inbox->user_id = $user->id; + $inbox->pack($ids); + $inbox->insert(); + } catch (Exception $e) { + printv("Error initializing inbox: " . $e->getMessage()); + } + } + } + + printfnq("DONE.\n"); +} + main();