]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/upgrade.php
initialize fave, sub, and membership URIs
[quix0rs-gnu-social.git] / scripts / upgrade.php
index 759c2df58f2453408713dd7889976524b584fa2f..2b116733c65213b7f2e62715d32073a4c8f22583 100644 (file)
@@ -43,7 +43,13 @@ function main()
     initConversation();
     initInbox();
     fixupGroupURI();
+
     initLocalGroup();
+    initNoticeReshare();
+    
+    initFaveURI();
+    initSubscriptionURI();
+    initGroupMemberURI();
 }
 
 function tableDefs()
@@ -258,4 +264,108 @@ function initLocalGroup()
     printfnq("DONE.\n");
 }
 
+function initNoticeReshare()
+{
+    printfnq("Ensuring all reshares have the correct verb and object-type...");
+    
+    $notice = new Notice();
+    $notice->whereAdd('repeat_of is not null');
+    $notice->whereAdd('(verb != "'.ActivityVerb::SHARE.'" OR object_type != "'.ActivityObject::ACTIVITY.'")');
+
+    if ($notice->find()) {
+        while ($notice->fetch()) {
+            try {
+                $orig = Notice::staticGet('id', $notice->id);
+                $notice->verb = ActivityVerb::SHARE;
+                $notice->object_type = ActivityObject::ACTIVITY;
+                $notice->update($orig);
+            } catch (Exception $e) {
+                printfv("Error updating verb and object_type for {$notice->id}:" . $e->getMessage());
+            }
+        }
+    }
+
+    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();