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.");
52 if (!$user->hasRole(Profile_role::DELETED)) {
53 common_log(LOG_INFO, "User {$user->nickname} is not pending deletion; aborting.");
57 $notice = $this->getNextBatch($user);
59 common_log(LOG_INFO, "Deleting next {$notice->N} notices by {$user->nickname}");
60 while ($notice->fetch()) {
61 $del = clone($notice);
65 // @todo improve reliability in case we died during the above deletions
66 // with a fatal error. If the job is lost, we should perform some kind
67 // of garbage collection later.
69 // Queue up the next batch.
70 $qm = QueueManager::get();
71 $qm->enqueue($user, 'deluser');
73 // Out of notices? Let's finish deleting this guy!
75 common_log(LOG_INFO, "User $user->id $user->nickname deleted.");
83 * Fetch the next self::DELETION_WINDOW messages for this user.
86 protected function getNextBatch(User $user)
88 $notice = new Notice();
89 $notice->profile_id = $user->id;
90 $notice->limit(self::DELETION_WINDOW);