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.
This commit is contained in:
Evan Prodromou
2011-09-07 16:48:10 -04:00
parent dc4f2c3b10
commit 9ed1beb3a0
2 changed files with 45 additions and 116 deletions

45
scripts/upgrade.php Executable file → Normal file
View File

@@ -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();