]> git.mxchange.org Git - friendica.git/commitdiff
Refactor Worker/Notifier part 2
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 5 Dec 2018 05:06:48 +0000 (00:06 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 21 Jan 2019 14:27:06 +0000 (09:27 -0500)
- Move self-removal in a sub-method in Worker/Notifier

src/Worker/Notifier.php

index 2581eca7d8307a8042ee4902ec8af18aae7cd92b..4103484f71aea1cee3e540c1efb86944ee80a3e8 100644 (file)
@@ -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