]> git.mxchange.org Git - friendica.git/commitdiff
Delete introductions when referenced contact id doesn't exist anymore in Ping module
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 8 Dec 2022 14:24:06 +0000 (09:24 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 10 Dec 2022 16:42:03 +0000 (11:42 -0500)
- Address part of https://github.com/friendica/friendica/issues/11993#issuecomment-1338134893

src/Module/Notifications/Ping.php
src/Navigation/Notifications/Factory/FormattedNavNotification.php

index 76cdd9f77055ce967968eda5d712fd6e07e3d651..df75c047afdd8b8c25d8f135743710db1e930786 100644 (file)
@@ -48,6 +48,7 @@ use Friendica\Navigation\Notifications\Factory;
 use Friendica\Navigation\Notifications\Repository;
 use Friendica\Navigation\Notifications\ValueObject;
 use Friendica\Navigation\SystemMessages;
+use Friendica\Network\HTTPException;
 use Friendica\Protocol\Activity;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Profiler;
@@ -229,7 +230,11 @@ class Ping extends BaseModule
 
                        // merge all notification types in one array
                        foreach ($intros as $intro) {
-                               $navNotifications[] = $this->formattedNavNotification->createFromIntro($intro);
+                               try {
+                                       $navNotifications[] = $this->formattedNavNotification->createFromIntro($intro);
+                               } catch (HTTPException\NotFoundException $e) {
+                                       $this->introductionRepo->delete($intro);
+                               }
                        }
 
                        if (count($registrations) <= 1 || $this->pconfig->get($this->session->getLocalUserId(), 'system', 'detailed_notif')) {
@@ -242,7 +247,7 @@ class Ping extends BaseModule
                                                new Uri($this->baseUrl->get(true) . '/moderation/users/pending')
                                        );
                                }
-                       } elseif (count($registrations) > 1) {
+                       } else {
                                $navNotifications[] = $this->formattedNavNotification->createFromParams(
                                        $registrations[0]['name'],
                                        $registrations[0]['url'],
index 2b1360eaa4f82cb9d9b33d6d40ac1545a52e4cba..9813fbf859dda00a901f10e816daf401b1d3b0ae 100644 (file)
@@ -28,7 +28,7 @@ use Friendica\Model\Contact;
 use Friendica\Navigation\Notifications\Entity;
 use Friendica\Navigation\Notifications\Exception\NoMessageException;
 use Friendica\Navigation\Notifications\ValueObject;
-use Friendica\Network\HTTPException\ServiceUnavailableException;
+use Friendica\Network\HTTPException;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy;
 use Friendica\Util\Temporal;
@@ -73,7 +73,7 @@ class FormattedNavNotification extends BaseFactory
         * @param Uri       $href
         * @param bool      $seen
         * @return ValueObject\FormattedNavNotification
-        * @throws ServiceUnavailableException
+        * @throws HTTPException\ServiceUnavailableException
         */
        public function createFromParams(string $contact_name, string $contact_url, string $message, \DateTime $date, Uri $href, bool $seen = false): ValueObject\FormattedNavNotification
        {
@@ -115,9 +115,9 @@ class FormattedNavNotification extends BaseFactory
         * @param Entity\Notification $notification
         * @return ValueObject\FormattedNavNotification
         * @throws NoMessageException
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        * @throws \Friendica\Network\HTTPException\NotFoundException
-        * @throws \Friendica\Network\HTTPException\ServiceUnavailableException
+        * @throws HTTPException\InternalServerErrorException
+        * @throws HTTPException\NotFoundException
+        * @throws HTTPException\ServiceUnavailableException
         */
        public function createFromNotification(Entity\Notification $notification): ValueObject\FormattedNavNotification
        {
@@ -141,10 +141,20 @@ class FormattedNavNotification extends BaseFactory
                );
        }
 
+       /**
+        * @param \Friendica\Contact\Introduction\Entity\Introduction $intro
+        * @return ValueObject\FormattedNavNotification
+        * @throws HTTPException\NotFoundException when the contact record couldn't be located
+        * @throws HTTPException\ServiceUnavailableException
+        */
        public function createFromIntro(\Friendica\Contact\Introduction\Entity\Introduction $intro): ValueObject\FormattedNavNotification
        {
-               if (!isset(self::$contacts[$intro->cid])) {
-                       self::$contacts[$intro->cid] = Contact::getById($intro->cid, ['name', 'url', 'pending']);
+               if (empty(self::$contacts[$intro->cid])) {
+                       if ($contact = Contact::getById($intro->cid, ['name', 'url', 'pending'])) {
+                               self::$contacts[$intro->cid] = $contact;
+                       } else {
+                               throw new HTTPException\NotFoundException('Contact not found with id' . $intro->cid);
+                       }
                }
 
                if (self::$contacts[$intro->cid]['pending']) {