]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/OStatusPlugin.php
OStatus: garbage collect unused PuSH subscriptions when the last local subscriber...
[quix0rs-gnu-social.git] / plugins / OStatus / OStatusPlugin.php
index 4b9b4d2c32e54075c65f1ce8ca0911017db37f15..ce02393e4345c0ad88a17a0e73cd469c4526a285 100644 (file)
@@ -234,13 +234,30 @@ class OStatusPlugin extends Plugin
         }
     }
     
+
+    /**
+     * Garbage collect unused feeds on unsubscribe
+     */
+    function onEndUnsubscribe($user, $other)
+    {
+        $feed = Feedinfo::staticGet('profile_id', $other->id);
+        if ($feed) {
+            $sub = new Subscription();
+            $sub->subscribed = $other->id;
+            $sub->limit(1);
+            if (!$sub->find(true)) {
+                common_log(LOG_INFO, "Unsubscribing from now-unused feed $feed->feeduri on hub $feed->huburi");
+                $feed->unsubscribe();
+            }
+        }
+        return true;
+    }
+
     
     function onCheckSchema() {
-        // warning: the autoincrement doesn't seem to set.
-        // alter table feedinfo change column id id int(11) not null  auto_increment;
         $schema = Schema::get();
         $schema->ensureTable('feedinfo', Feedinfo::schemaDef());
         $schema->ensureTable('hubsub', HubSub::schemaDef());
         return true;
-    } 
+    }
 }