3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Background job to delete prolific users without disrupting front-end too much.
23 * Up to 50 messages are deleted on each run through; when all messages are gone,
24 * the actual account is deleted.
26 * @package QueueHandler
27 * @maintainer Brion Vibber <brion@status.net>
30 class DelUserQueueHandler extends QueueHandler
32 const DELETION_WINDOW = 50;
34 public function transport()
39 public function handle($user)
41 if (!($user instanceof User)) {
42 common_log(LOG_ERR, "Got a bogus user, not deleting");
46 $user = User::staticGet('id', $user->id);
48 common_log(LOG_INFO, "User {$user->nickname} was deleted before we got here.");
53 if (!$user->hasRole(Profile_role::DELETED)) {
54 common_log(LOG_INFO, "User {$user->nickname} is not pending deletion; aborting.");
57 } catch (UserNoProfileException $unp) {
58 common_log(LOG_INFO, "Deleting user {$user->nickname} with no profile... probably a good idea!");
61 $notice = $this->getNextBatch($user);
63 common_log(LOG_INFO, "Deleting next {$notice->N} notices by {$user->nickname}");
64 while ($notice->fetch()) {
65 $del = clone($notice);
69 // @todo improve reliability in case we died during the above deletions
70 // with a fatal error. If the job is lost, we should perform some kind
71 // of garbage collection later.
73 // Queue up the next batch.
74 $qm = QueueManager::get();
75 $qm->enqueue($user, 'deluser');
77 // Out of notices? Let's finish deleting this guy!
79 common_log(LOG_INFO, "User $user->id $user->nickname deleted.");
87 * Fetch the next self::DELETION_WINDOW messages for this user.
90 protected function getNextBatch(User $user)
92 $notice = new Notice();
93 $notice->profile_id = $user->id;
94 $notice->limit(self::DELETION_WINDOW);