From b77f3a7525aab36fe2179be71fd892e4229ba07d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jan 2023 10:27:45 -0500 Subject: [PATCH] Check for URI ID existence in Post\Media::insert - Address https://github.com/friendica/friendica/issues/12486#issuecomment-1374538325 --- src/Model/ItemURI.php | 10 ++++++++++ src/Model/Post/Media.php | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/Model/ItemURI.php b/src/Model/ItemURI.php index 3194097f31..1755552299 100644 --- a/src/Model/ItemURI.php +++ b/src/Model/ItemURI.php @@ -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]); + } } diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index 074cee5221..ef03b5fea5 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -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); -- 2.39.5