summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-10-12 16:13:07 -0700
committerBrion Vibber <brion@pobox.com>2010-10-12 16:13:07 -0700
commit3579ccac8e2b334d4caef57ffe5b01be21a5cf11 (patch)
tree94c2ea33ab285dd6364f4695e7951f0c59edf4f1
parentf4f16af8ac6c2bb1d5561bd85b4908fd3f9e1dbb (diff)
Cascading deletion for user_group; doesn't yet work properly with caching.
-rw-r--r--classes/User_group.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/classes/User_group.php b/classes/User_group.php
index cfdcef290..fabb8e8d5 100644
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -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();
+ }
}