From: Evan Prodromou Date: Mon, 12 Sep 2011 16:13:04 +0000 (-0400) Subject: initialize fave, sub, and membership URIs X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=14f03a237e1a67a764a75cfa8e6fed34f0074a4b;p=quix0rs-gnu-social.git initialize fave, sub, and membership URIs --- diff --git a/scripts/upgrade.php b/scripts/upgrade.php index af89760f70..2b116733c6 100644 --- a/scripts/upgrade.php +++ b/scripts/upgrade.php @@ -43,8 +43,13 @@ function main() initConversation(); initInbox(); fixupGroupURI(); + initLocalGroup(); initNoticeReshare(); + + initFaveURI(); + initSubscriptionURI(); + initGroupMemberURI(); } function tableDefs() @@ -283,4 +288,84 @@ function initNoticeReshare() printfnq("DONE.\n"); } +function initFaveURI() +{ + printfnq("Ensuring all faves have a URI..."); + + $fave = new Fave(); + $fave->whereAdd('uri IS NULL'); + + if ($fave->find()) { + while ($fave->fetch()) { + try { + $fave->decache(); + $fave->query(sprintf('update fave '. + 'set uri = "%s" '. + 'where user_id = %d '. + 'and notice_id = %d', + Fave::newURI($fave->user_id, $fave->notice_id, $fave->modified), + $fave->user_id, + $fave->notice_id)); + } catch (Exception $e) { + common_log(LOG_ERR, "Error updated fave URI: " . $e->getMessage()); + } + } + } + + printfnq("DONE.\n"); +} + +function initSubscriptionURI() +{ + printfnq("Ensuring all subscriptions have a URI..."); + + $sub = new Subscription(); + $sub->whereAdd('uri IS NULL'); + + if ($sub->find()) { + while ($sub->fetch()) { + try { + $sub->decache(); + $sub->query(sprintf('update subscription '. + 'set uri = "%s" '. + 'where subscriber = %d '. + 'and subscribed = %d', + Subscription::newURI($sub->subscriber, $sub->subscribed, $sub->created), + $sub->subscriber, + $sub->subscribed)); + } catch (Exception $e) { + common_log(LOG_ERR, "Error updated subscription URI: " . $e->getMessage()); + } + } + } + + printfnq("DONE.\n"); +} + +function initGroupMemberURI() +{ + printfnq("Ensuring all group memberships have a URI..."); + + $mem = new Group_member(); + $mem->whereAdd('uri IS NULL'); + + if ($mem->find()) { + while ($mem->fetch()) { + try { + $mem->decache(); + $mem->query(sprintf('update group_member set uri = "%s" '. + 'where profile_id = %d ' . + 'and group_id = %d ', + Group_member::newURI($mem->profile_id, $mem->group_id, $mem->created), + $mem->profile_id, + $mem->group_id)); + } catch (Exception $e) { + common_log(LOG_ERR, "Error updated membership URI: " . $e->getMessage()); + } + } + } + + printfnq("DONE.\n"); +} + main();