]> git.mxchange.org Git - friendica.git/commitdiff
Check for URI ID existence in Post\Media::insert
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 9 Jan 2023 15:27:45 +0000 (10:27 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 9 Jan 2023 21:06:22 +0000 (16:06 -0500)
- Address https://github.com/friendica/friendica/issues/12486#issuecomment-1374538325

src/Model/ItemURI.php
src/Model/Post/Media.php

index 3194097f31ad0e5bbad4680b1c2580793267db4f..1755552299741b6884060ea8e4452c75b4aac13d 100644 (file)
@@ -81,4 +81,14 @@ class ItemURI
 
                return $itemuri['id'] ?? 0;
        }
+
+       /**
+        * @param int $uriId
+        * @return bool
+        * @throws \Exception
+        */
+       public static function exists(int $uriId): bool
+       {
+               return DBA::exists('item-uri', ['id' => $uriId]);
+       }
 }
index 074cee5221217b6b743970a40323a18f59697598..ef03b5fea567449a5a22e1d3b11f2740f1575f98 100644 (file)
@@ -30,6 +30,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
+use Friendica\Model\ItemURI;
 use Friendica\Model\Photo;
 use Friendica\Model\Post;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
@@ -89,6 +90,11 @@ class Media
                        return;
                }
 
+               if (!ItemURI::exists($media['uri-id'])) {
+                       Logger::info('Media referenced URI ID not found', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'callstack' => System::callstack()]);
+                       return;
+               }
+
                $media = self::unsetEmptyFields($media);
                $media = DI::dbaDefinition()->truncateFieldsForTable('post-media', $media);