From: Hypolite Petovan Date: Wed, 5 Dec 2018 05:06:48 +0000 (-0500) Subject: Refactor Worker/Notifier part 2 X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d0228b9b97e9a4f5ac051f594c32004a5c5916e9;p=friendica.git Refactor Worker/Notifier part 2 - Move self-removal in a sub-method in Worker/Notifier --- diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 2581eca7d8..4103484f71 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -82,33 +82,7 @@ class Notifier $uid = $suggest['uid']; $recipients[] = $suggest['cid']; } elseif ($cmd == Delivery::REMOVAL) { - $r = q("SELECT `contact`.*, `user`.`prvkey` AS `uprvkey`, - `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, - `user`.`page-flags`, `user`.`prvnets`, `user`.`account-type`, `user`.`guid` - FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` - WHERE `contact`.`uid` = %d AND `contact`.`self` LIMIT 1", - intval($target_id)); - if (!$r) { - return; - } - $user = $r[0]; - - $r = q("SELECT * FROM `contact` WHERE NOT `self` AND `uid` = %d", intval($target_id)); - if (!$r) { - return; - } - foreach ($r as $contact) { - Contact::terminateFriendship($user, $contact, true); - } - - $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0); - foreach ($inboxes as $inbox) { - Logger::log('Account removal for user ' . $target_id . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG); - Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $a->queue['created'], 'dont_fork' => true], - 'APDelivery', Delivery::REMOVAL, '', $inbox, $target_id); - } - - return; + return self::notifySelfRemoval($target_id, $a->queue['priority'], $a->queue['created']); } elseif ($cmd == Delivery::RELOCATION) { $normal_mode = false; $uid = $target_id; @@ -525,6 +499,38 @@ class Notifier return; } + /** + * @param int $self_user_id + * @param int $priority The priority the Notifier queue item was created with + * @param string $created The date the Notifier queue item was created on + * @return bool + */ + private static function notifySelfRemoval($self_user_id, $priority, $created) + { + $owner = User::getOwnerDataById($self_user_id); + if (!$owner) { + return false; + } + + $contacts_stmt = DBA::select('contact', [], ['self' => false, 'uid' => $self_user_id]); + if (!DBA::isResult($contacts_stmt)) { + return false; + } + + while($contact = DBA::fetch($contacts_stmt)) { + Contact::terminateFriendship($owner, $contact, true); + } + + $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0); + foreach ($inboxes as $inbox) { + Logger::log('Account removal for user ' . $self_user_id . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG); + Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $created, 'dont_fork' => true], + 'APDelivery', Delivery::REMOVAL, '', $inbox, $self_user_id); + } + + return true; + } + /** * @param string $cmd * @param array $target_item