]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/upgrade.php
replace 'public' in documentation with 'top'
[quix0rs-gnu-social.git] / scripts / upgrade.php
index af89760f705da91182378762e582502b609fcd75..7d81c1983504f1fd8797a789901b118e5a76e31c 100644 (file)
@@ -33,18 +33,29 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
 
 function main()
 {
-    updateSchemaCore();
-    updateSchemaPlugins();
-
-    // These replace old "fixup_*" scripts
-
-    fixupNoticeRendered();
-    fixupNoticeConversation();
-    initConversation();
-    initInbox();
-    fixupGroupURI();
-    initLocalGroup();
-    initNoticeReshare();
+    if (Event::handle('StartUpgrade')) {
+        updateSchemaCore();
+        updateSchemaPlugins();
+
+        // These replace old "fixup_*" scripts
+
+        fixupNoticeRendered();
+        fixupNoticeConversation();
+        initConversation();
+        initInbox();
+        fixupGroupURI();
+
+        initLocalGroup();
+        initNoticeReshare();
+    
+        initFaveURI();
+        initSubscriptionURI();
+        initGroupMemberURI();
+
+        initProfileLists();
+
+        Event::handle('EndUpgrade');
+    }
 }
 
 function tableDefs()
@@ -283,4 +294,129 @@ 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", '.
+                                     '    modified = "%s" '.
+                                     'where user_id = %d '.
+                                     'and notice_id = %d',
+                                     Fave::newURI($fave->user_id, $fave->notice_id, $fave->modified),
+                                     common_sql_date(strtotime($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");
+}
+
+function initProfileLists()
+{
+    printfnq("Ensuring all profile tags have a corresponding list...");
+
+    $ptag = new Profile_tag();
+    $ptag->selectAdd();
+    $ptag->selectAdd('tagger, tag, count(*) as tagged_count');
+    $ptag->whereAdd('NOT EXISTS (SELECT tagger, tagged from profile_list '.
+                    'where profile_tag.tagger = profile_list.tagger '.
+                    'and profile_tag.tag = profile_list.tag)');
+    $ptag->groupBy('tagger, tag');
+    $ptag->orderBy('tagger, tag');
+
+    if ($ptag->find()) {
+        while ($ptag->fetch()) {
+            $plist = new Profile_list();
+
+            $plist->tagger   = $ptag->tagger;
+            $plist->tag      = $ptag->tag;
+            $plist->private  = 0;
+            $plist->created  = common_sql_now();
+            $plist->modified = $plist->created;
+            $plist->mainpage = common_local_url('showprofiletag',
+                                                array('tagger' => $plist->getTagger()->nickname,
+                                                      'tag'    => $plist->tag));;
+
+            $plist->tagged_count     = $ptag->tagged_count;
+            $plist->subscriber_count = 0;
+
+            $plist->insert();
+
+            $orig = clone($plist);
+            // After insert since it uses auto-generated ID
+            $plist->uri      = common_local_url('profiletagbyid',
+                                        array('id' => $plist->id, 'tagger_id' => $plist->tagger));
+
+            $plist->update($orig);
+        }
+    }
+
+    printfnq("DONE.\n");
+}
+
 main();