]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Cascading deletion for user_group; doesn't yet work properly with caching.
authorBrion Vibber <brion@pobox.com>
Tue, 12 Oct 2010 23:13:07 +0000 (16:13 -0700)
committerBrion Vibber <brion@pobox.com>
Tue, 12 Oct 2010 23:13:07 +0000 (16:13 -0700)
classes/User_group.php

index cfdcef29067160c3288ad5f73af4e3a2a124fbbd..fabb8e8d5ceb4951991bd8d4d14d2fcd4283c662 100644 (file)
@@ -547,4 +547,36 @@ class User_group extends Memcached_DataObject
         $group->query('COMMIT');
         return $group;
     }
+
+    /**
+     * Handle cascading deletion, on the model of notice and profile.
+     *
+     * Pretty sure some caching won't get handled properly here.
+     */
+    function delete()
+    {
+        if ($this->id) {
+            $related = array('Group_inbox',
+                             'Group_alias',
+                             'Group_block',
+                             'Group_member',
+                             'Local_group',
+                             'Related_group',
+                             );
+            Event::handle('UserGroupDeleteRelated', array($this, &$related));
+
+            foreach ($related as $cls) {
+                $inst = new $cls();
+                $inst->group_id = $this->id;
+                $inst->delete();
+            }
+
+            $inst = new Related_group();
+            $inst->related_group_id = $this->id;
+            $inst->delete();
+        } else {
+            common_log(LOG_WARN, "Ambiguous user_group->delete(); skipping related tables.");
+        }
+        parent::delete();
+    }
 }