From 51ac34e80c5a99008b1a945b2c00b6dbfdde1529 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 26 Jul 2009 13:06:38 -0600 Subject: [PATCH 1/6] first version of deleting users --- classes/Profile.php | 75 +++++++++++++++++++++++++++++++++++++++++++++ classes/User.php | 43 ++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/classes/Profile.php b/classes/Profile.php index f926b2cef2..0ee6fa657f 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -461,4 +461,79 @@ class Profile extends Memcached_DataObject $c->delete(common_cache_key('profile:notice_count:'.$this->id)); } } + + 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; + $msg->delete(); + } + + function _deleteBlocks() + { + $block = new Profile_block(); + $block->blocked = $this->id; + $block->delete(); + + $block = new Group_block(); + $block->blocked = $this->id; + $block->delete(); + } } diff --git a/classes/User.php b/classes/User.php index bea47a3b05..991e9c18fb 100644 --- a/classes/User.php +++ b/classes/User.php @@ -685,4 +685,47 @@ class User extends Memcached_DataObject { return Design::staticGet('id', $this->design_id); } + + function delete() + { + $profile = $this->getProfile(); + $profile->delete(); + + $related = array('Fave', + 'User_openid', + 'Confirm_address', + 'Remember_me', + 'Foreign_link', + 'Invitation', + ); + + if (common_config('inboxes', 'enabled')) { + $related[] = 'Notice_inbox'; + } + + foreach ($related as $cls) { + $inst = new $cls(); + $inst->user_id = $this->id; + $inst->delete(); + } + + $this->_deleteTags(); + + parent::delete(); + } + + function _deleteTags() + { + $tag = new Profile_tag(); + $tag->tagger = $this->id; + $tag->delete(); + } + + function _deleteBlocks() + { + $block = new Profile_block(); + $block->blocker = $this->id; + $block->delete(); + // XXX delete group block? Reset blocker? + } } From 94e3f6bb092486df99034064c0e7d553bcf7d180 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 2 Oct 2009 15:29:57 -0400 Subject: [PATCH 2/6] also delete blocks --- classes/User.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/User.php b/classes/User.php index ef84342922..007662131c 100644 --- a/classes/User.php +++ b/classes/User.php @@ -714,6 +714,7 @@ class User extends Memcached_DataObject } $this->_deleteTags(); + $this->_deleteBlocks(); parent::delete(); } From be513db013b6079d3ff32fdb0bb332cdbace1798 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 2 Oct 2009 15:42:34 -0400 Subject: [PATCH 3/6] copy-and-paste typo in profile deletion --- classes/Profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Profile.php b/classes/Profile.php index 463802b4ee..8385ebf889 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -523,7 +523,7 @@ class Profile extends Memcached_DataObject { $tag = new Profile_tag(); $tag->tagged = $this->id; - $msg->delete(); + $tag->delete(); } function _deleteBlocks() From 54b22c0c0bb1e7f5fbbcf9035219b5ed07e1b80c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 2 Oct 2009 15:42:58 -0400 Subject: [PATCH 4/6] script to permanently delete a user --- scripts/deleteuser.php | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 scripts/deleteuser.php diff --git a/scripts/deleteuser.php b/scripts/deleteuser.php new file mode 100644 index 0000000000..67aea7921c --- /dev/null +++ b/scripts/deleteuser.php @@ -0,0 +1,68 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'i::n::y'; +$longoptions = array('id::nickname::yes'); + +$helptext = <<nickname}' ({$user->id}). Are you sure? [y/N] "; + $response = fgets(STDIN); + if (strtolower($response) != 'y') { + print "Aborting.\n"; + exit(0); + } +} + +print "Deleting..."; +$user->delete(); +print "DONE.\n"; From 2d85d619074b69ff0d31249c45715af686b13986 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 2 Oct 2009 15:46:00 -0400 Subject: [PATCH 5/6] better handling of y response in deleteuser.php --- scripts/deleteuser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deleteuser.php b/scripts/deleteuser.php index 67aea7921c..52389123c5 100644 --- a/scripts/deleteuser.php +++ b/scripts/deleteuser.php @@ -57,7 +57,7 @@ if (have_option('i', 'id')) { if (!have_option('y', 'yes')) { print "About to PERMANENTLY delete user '{$user->nickname}' ({$user->id}). Are you sure? [y/N] "; $response = fgets(STDIN); - if (strtolower($response) != 'y') { + if (strtolower(trim($response)) != 'y') { print "Aborting.\n"; exit(0); } From 5528c0cd3d66c1acd7bf25b26833e8a107641f35 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 3 Oct 2009 22:06:51 +0000 Subject: [PATCH 6/6] Using CDATA for autofocus script --- lib/htmloutputter.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php index 64be745beb..2ff9380cc1 100644 --- a/lib/htmloutputter.php +++ b/lib/htmloutputter.php @@ -427,16 +427,12 @@ class HTMLOutputter extends XMLOutputter function autofocus($id) { $this->elementStart('script', array('type' => 'text/javascript')); - $this->raw(' - - '); + $this->raw('/**/'); $this->elementEnd('script'); } }