]> git.mxchange.org Git - friendica.git/commitdiff
Changes:
authorRoland Häder <roland@mxchange.org>
Thu, 23 Jun 2022 11:56:18 +0000 (13:56 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 23 Jun 2022 15:30:16 +0000 (17:30 +0200)
- added some type-hints
- added documentation

src/Worker/ProfileUpdate.php
src/Worker/PubSubPublish.php
src/Worker/PushSubscription.php
src/Worker/RemoveUser.php
src/Worker/UpdateContact.php
src/Worker/UpdateContacts.php
src/Worker/UpdateGServer.php
src/Worker/UpdateServerPeers.php

index ba15436d841c0ad189bcb6b6ead793d3e46f58ae..e26abf7e20e445fa36ddfa7ab69578dbb55a8857 100644 (file)
@@ -31,7 +31,14 @@ use Friendica\Protocol\ActivityPub;
  * Send updated profile data to Diaspora and ActivityPub
  */
 class ProfileUpdate {
-       public static function execute($uid = 0) {
+       /**
+        * Sends updated profile data to Diaspora and ActivityPub
+        *
+        * @param int $uid User id (optional, default: 0)
+        * @return void
+        */
+       public static function execute(int $uid = 0)
+       {
                if (empty($uid)) {
                        return;
                }
@@ -43,7 +50,13 @@ class ProfileUpdate {
                foreach ($inboxes as $inbox => $receivers) {
                        Logger::info('Profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub');
                        Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
-                               'APDelivery', Delivery::PROFILEUPDATE, 0, $inbox, $uid, $receivers);
+                               'APDelivery',
+                               Delivery::PROFILEUPDATE,
+                               0,
+                               $inbox,
+                               $uid,
+                               $receivers
+                       );
                }
 
                Diaspora::sendProfile($uid);
index e84ac3152e36e8c5a5e3114885e2e42688e08dce..1bfc3657ae159906600a3dbe80a8468dde44e50f 100644 (file)
@@ -29,7 +29,13 @@ use Friendica\Protocol\OStatus;
 
 class PubSubPublish
 {
-       public static function execute($pubsubpublish_id = 0)
+       /**
+        * Publishes subscriber id
+        *
+        * @param int $pubsubpublish_id Push subscriber id
+        * @return void
+        */
+       public static function execute(int $pubsubpublish_id = 0)
        {
                if ($pubsubpublish_id == 0) {
                        return;
@@ -38,7 +44,13 @@ class PubSubPublish
                self::publish($pubsubpublish_id);
        }
 
-       private static function publish($id)
+       /**
+        * Publishes push subscriber
+        *
+        * @param int $id Push subscriber id
+        * @return void
+        */
+       private static function publish(int $id)
        {
                $subscriber = DBA::selectFirst('push_subscriber', [], ['id' => $id]);
                if (!DBA::isResult($subscriber)) {
@@ -48,7 +60,7 @@ class PubSubPublish
                /// @todo Check server status with GServer::check()
                // Before this can be done we need a way to safely detect the server url.
 
-               Logger::info("Generate feed of user " . $subscriber['nickname']. " to " . $subscriber['callback_url']. " - last updated " . $subscriber['last_update']);
+               Logger::info('Generate feed of user ' . $subscriber['nickname'] . ' to ' . $subscriber['callback_url'] . ' - last updated ' . $subscriber['last_update']);
 
                $last_update = $subscriber['last_update'];
                $params = OStatus::feed($subscriber['nickname'], $last_update);
@@ -57,11 +69,11 @@ class PubSubPublish
                        return;
                }
 
-               $hmac_sig = hash_hmac("sha1", $params, $subscriber['secret']);
+               $hmac_sig = hash_hmac('sha1', $params, $subscriber['secret']);
 
                $headers = [
                        'Content-type' => 'application/atom+xml',
-                       'Link' => sprintf("<%s>;rel=hub,<%s>;rel=self",
+                       'Link' => sprintf('<%s>;rel=hub,<%s>;rel=self',
                                        DI::baseUrl() . '/pubsubhubbub/' . $subscriber['nickname'],
                                        $subscriber['topic']),
                        'X-Hub-Signature' => 'sha1=' . $hmac_sig];
index 45ecb62291a08a2e7fcc6e39a2045967d40a5fe3..48695bfcd0d52b589b7d58d80ca6c2bd9c2c4875 100644 (file)
@@ -37,6 +37,13 @@ use Minishlink\WebPush\Subscription;
 
 class PushSubscription
 {
+       /**
+        * Creates push subscription by subscription and notification ids
+        *
+        * @param int $sid Subscription id
+        * @param int $nid Notification id
+        * @return void
+        */
        public static function execute(int $sid, int $nid)
        {
                Logger::info('Start', ['subscription' => $sid, 'notification' => $nid]);
@@ -48,7 +55,7 @@ class PushSubscription
                }
 
                try {
-                       $Notification = DI::notification()->selectOneById($nid);
+                       $notification = DI::notification()->selectOneById($nid);
                } catch (NotFoundException $e) {
                        Logger::info('Notification not found', ['notification' => $nid]);
                        return;
@@ -60,7 +67,7 @@ class PushSubscription
                        return;
                }
 
-               $user = User::getById($Notification->uid);
+               $user = User::getById($notification->uid);
                if (empty($user)) {
                        Logger::info('User not found', ['application' => $subscription['uid']]);
                        return;
@@ -68,21 +75,21 @@ class PushSubscription
 
                $l10n = DI::l10n()->withLang($user['language']);
 
-               if ($Notification->actorId) {
-                       $actor = Contact::getById($Notification->actorId);
+               if ($notification->actorId) {
+                       $actor = Contact::getById($notification->actorId);
                }
 
                $body = '';
 
-               if ($Notification->targetUriId) {
-                       $post = Post::selectFirst([], ['uri-id' => $Notification->targetUriId, 'uid' => [0, $Notification->uid]]);
+               if ($notification->targetUriId) {
+                       $post = Post::selectFirst([], ['uri-id' => $notification->targetUriId, 'uid' => [0, $notification->uid]]);
                        if (!empty($post['body'])) {
                                $body = BBCode::toPlaintext($post['body'], false);
-                               $body = Plaintext::shorten($body, 160, $Notification->uid);
+                               $body = Plaintext::shorten($body, 160, $notification->uid);
                        }
                }
 
-               $message = DI::notificationFactory()->getMessageFromNotification($Notification);
+               $message = DI::notificationFactory()->getMessageFromNotification($notification);
                $title = $message['plain'] ?: '';
 
                $push = Subscription::create([
@@ -94,11 +101,12 @@ class PushSubscription
                        ],
                ]);
 
+               // @todo Only used for logging?
                $payload = [
                        'access_token'      => $application_token['access_token'],
                        'preferred_locale'  => $user['language'],
                        'notification_id'   => $nid,
-                       'notification_type' => \Friendica\Factory\Api\Mastodon\Notification::getType($Notification),
+                       'notification_type' => \Friendica\Factory\Api\Mastodon\Notification::getType($notification),
                        'icon'              => $actor['thumb'] ?? '',
                        'title'             => $title ?: $l10n->t('Notification from Friendica'),
                        'body'              => $body ?: $l10n->t('Empty Post'),
index e209aec07f18c23056e0f523a190df712bac65fd..6a2d54422eb7fd99bbdfe1ff174522e0a56159c4 100644 (file)
@@ -29,7 +29,13 @@ use Friendica\Model\Post;
  * Removes orphaned data from deleted users
  */
 class RemoveUser {
-       public static function execute($uid)
+       /**
+        * Removes user by id
+        *
+        * @param int $uid User id
+        * @return void
+        */
+       public static function execute(int $uid)
        {
                // Only delete if the user is archived
                $condition = ['account_removed' => true, 'uid' => $uid];
index edabaf163c897fc890c9dc6603049162161faa52..8de3629cafdca24ce8b0d04c60024dd46ff0b09b 100644 (file)
@@ -28,9 +28,11 @@ class UpdateContact
 {
        /**
         * Update contact data via probe
+        *
         * @param int    $contact_id Contact ID
+        * @return void
         */
-       public static function execute($contact_id)
+       public static function execute(int $contact_id)
        {
                $success = Contact::updateFromProbe($contact_id);
 
index 2beb890918538373c87a2e647ba567638da8cba9..9dc0bacca712984f75c83de20e42413000b19bd9 100644 (file)
@@ -102,7 +102,7 @@ class UpdateContacts
         * @param array $ids
         * @return array contact ids
         */
-       private static function getContactsToUpdate(array $condition, int $limit, array $ids = [])
+       private static function getContactsToUpdate(array $condition, int $limit, array $ids = []): array
        {
                $contacts = DBA::select('contact', ['id'], $condition, ['limit' => $limit]);
                while ($contact = DBA::fetch($contacts)) {
index 1085c467c7b9df2645256f91d769a80a65a7d04f..d180f34c45ef55ce5fb7b7b904b658a4651faeff 100644 (file)
@@ -30,8 +30,10 @@ class UpdateGServer
 {
        /**
         * Update the given server
+        *
         * @param string  $server_url    Server URL
         * @param boolean $only_nodeinfo Only use nodeinfo for server detection
+        * @return void
         */
        public static function execute(string $server_url, bool $only_nodeinfo = false)
        {
index 98ae88a97b5be8acded06a0dc1a0f040ecfc4a10..09c88499ec63fa2e985449ab78f1b01584158334 100644 (file)
@@ -32,7 +32,9 @@ class UpdateServerPeers
 {
        /**
         * Query the given server for their known peers
+        *
         * @param string $gserver Server URL
+        * @return void
         */
        public static function execute(string $url)
        {