]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Merge branch '0.8.x' into 0.9.x
[quix0rs-gnu-social.git] / classes / Profile.php
index 8f92b386e963b1167c8326085e6e81c01c2646d9..4a069ee84eb6141465d27f2a9ac205432d41cfd5 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, Control Yourself, Inc.
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, StatusNet, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -17,7 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
 /**
  * Table Definition for profile
@@ -476,4 +476,79 @@ class Profile extends Memcached_DataObject
         $biolimit = self::maxBio();
         return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit));
     }
+
+    function delete()
+    {
+        $this->_deleteNotices();
+        $this->_deleteSubscriptions();
+        $this->_deleteMessages();
+        $this->_deleteTags();
+        $this->_deleteBlocks();
+
+        $related = array('Avatar',
+                         'Reply',
+                         'Group_member',
+                         );
+
+        foreach ($related as $cls) {
+            $inst = new $cls();
+            $inst->profile_id = $this->id;
+            $inst->delete();
+        }
+
+        parent::delete();
+    }
+
+    function _deleteNotices()
+    {
+        $notice = new Notice();
+        $notice->profile_id = $this->id;
+
+        if ($notice->find()) {
+            while ($notice->fetch()) {
+                $other = clone($notice);
+                $other->delete();
+            }
+        }
+    }
+
+    function _deleteSubscriptions()
+    {
+        $sub = new Subscription();
+        $sub->subscriber = $this->id;
+        $sub->delete();
+
+        $subd = new Subscription();
+        $subd->subscribed = $this->id;
+        $subd->delete();
+    }
+
+    function _deleteMessages()
+    {
+        $msg = new Message();
+        $msg->from_profile = $this->id;
+        $msg->delete();
+
+        $msg = new Message();
+        $msg->to_profile = $this->id;
+        $msg->delete();
+    }
+
+    function _deleteTags()
+    {
+        $tag = new Profile_tag();
+        $tag->tagged = $this->id;
+        $tag->delete();
+    }
+
+    function _deleteBlocks()
+    {
+        $block = new Profile_block();
+        $block->blocked = $this->id;
+        $block->delete();
+
+        $block = new Group_block();
+        $block->blocked = $this->id;
+        $block->delete();
+    }
 }