]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Add profile lists for all tags on upgrade
authorEvan Prodromou <evan@status.net>
Tue, 27 Sep 2011 15:16:14 +0000 (11:16 -0400)
committerEvan Prodromou <evan@status.net>
Tue, 27 Sep 2011 15:16:14 +0000 (11:16 -0400)
scripts/upgrade.php

index 1bf444267cd54b7db7c5766c4792161c6ec1cacb..7d81c1983504f1fd8797a789901b118e5a76e31c 100644 (file)
@@ -52,6 +52,8 @@ function main()
         initSubscriptionURI();
         initGroupMemberURI();
 
+        initProfileLists();
+
         Event::handle('EndUpgrade');
     }
 }
@@ -374,4 +376,47 @@ function initGroupMemberURI()
     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();