]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #9655 from MrPetovan/bug/fatal-errors
authorMichael Vogel <icarus@dabo.de>
Mon, 14 Dec 2020 21:11:45 +0000 (22:11 +0100)
committerGitHub <noreply@github.com>
Mon, 14 Dec 2020 21:11:45 +0000 (22:11 +0100)
Fix several occasional fatal errors

mod/dfrn_request.php
src/Model/ItemURI.php
src/Network/Probe.php
src/Protocol/ActivityPub/Processor.php
src/Worker/APDelivery.php

index 3f784015ddccc2660e216826542b329cae259c27..47478d384833823639ea19a6609c9333eb690bc3 100644 (file)
@@ -299,7 +299,7 @@ function dfrn_request_post(App $a)
                $network = $data["network"];
 
                // Canonicalize email-style profile locator
-               $url = Probe::webfingerDfrn($data['url'], $hcard);
+               $url = Probe::webfingerDfrn($data['url'] ?? $url, $hcard);
 
                if (substr($url, 0, 5) === 'stat:') {
                        // Every time we detect the remote subscription we define this as OStatus.
index 7f05786c8ee72072b5cbe73b2aca26f381a2f91a..6421b2dbd9a5007cafd463ff04d62bc7a0c43043 100644 (file)
@@ -31,10 +31,10 @@ class ItemURI
         *
         * @param array $fields Item-uri fields
         *
-        * @return integer item-uri id
+        * @return int|null item-uri id
         * @throws \Exception
         */
-       public static function insert($fields)
+       public static function insert(array $fields)
        {
                // If the URI gets too long we only take the first parts and hope for best
                $uri = substr($fields['uri'], 0, 255);
index 67db29a4f3536fe9b0e98332de9578ac55db8b8a..d5dcba529596ab1176dca5f657725abd04b07f25 100644 (file)
@@ -258,7 +258,7 @@ class Probe
         * @return string profile link
         * @throws HTTPException\InternalServerErrorException
         */
-       public static function webfingerDfrn($webbie, &$hcard_url)
+       public static function webfingerDfrn(string $webbie, string &$hcard_url)
        {
                $profile_link = '';
 
index 8f89b17f809fffa0ee44ec3c6636a3df2a304242..f60eea7122211d3aeafa67bbfe50a25bda82e9c0 100644 (file)
@@ -327,6 +327,10 @@ class Processor
                $item['guid'] = $activity['diaspora:guid'] ?: $guid;
 
                $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
+               if (empty($item['uri-id'])) {
+                       Logger::warning('Unable to get a uri-id for an item uri', ['uri' => $item['uri'], 'guid' => $item['guid']]);
+                       return [];
+               }
 
                $item = self::processContent($activity, $item);
                if (empty($item)) {
@@ -903,20 +907,15 @@ class Processor
                if (!empty($cid)) {
                        self::switchContact($cid);
                        DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
-                       $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
-               } else {
-                       $contact = [];
                }
 
                $item = ['author-id' => Contact::getIdForURL($activity['actor']),
                        'author-link' => $activity['actor']];
 
-               $note = Strings::escapeTags(trim($activity['content'] ?? ''));
-
                // Ensure that the contact has got the right network type
                self::switchContact($item['author-id']);
 
-               $result = Contact::addRelationship($owner, $contact, $item, false, $note);
+               $result = Contact::addRelationship($owner, [], $item, false, $activity['content'] ?? '');
                if ($result === true) {
                        ActivityPub\Transmitter::sendContactAccept($item['author-link'], $activity['id'], $owner['uid']);
                }
index 7173475befa5117a635f06385bc21eedf6053fa8..c98f1e399322e9d02725f08e45e41fe36fa99f9b 100644 (file)
@@ -31,6 +31,28 @@ use Friendica\Util\HTTPSignature;
 
 class APDelivery
 {
+       /**
+        * Delivers ActivityPub messages
+        *
+        * @param string       $cmd
+        * @param integer      $target_id
+        * @param string|array $inboxes
+        * @param integer      $uid
+        * @param array        $receivers
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function execute(string $cmd, int $target_id, $inboxes, int $uid, array $receivers = [])
+       {
+               if (is_string($inboxes)) {
+                       $inboxes = [$inboxes];
+               }
+
+               foreach ($inboxes as $inbox) {
+                       self::perform($cmd, $target_id, $inbox, $uid, $receivers);
+               }
+       }
+
        /**
         * Delivers ActivityPub messages
         *
@@ -42,7 +64,7 @@ class APDelivery
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function execute($cmd, $target_id, $inbox, $uid, $receivers = [])
+       private static function perform(string $cmd, int $target_id, string $inbox, int $uid, array $receivers = [])
        {
                if (ActivityPub\Transmitter::archivedInbox($inbox)) {
                        Logger::info('Inbox is archived', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $target_id, 'uid' => $uid]);