]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
initialize fave, sub, and membership URIs
authorEvan Prodromou <evan@status.net>
Mon, 12 Sep 2011 16:13:04 +0000 (12:13 -0400)
committerEvan Prodromou <evan@status.net>
Mon, 12 Sep 2011 16:13:04 +0000 (12:13 -0400)
scripts/upgrade.php

index af89760f705da91182378762e582502b609fcd75..2b116733c65213b7f2e62715d32073a4c8f22583 100644 (file)
@@ -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();