From 670b5188751c391ede9c58d861b773763866f27f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jan 2023 09:52:04 -0500 Subject: [PATCH 1/4] Include other unique key column in condition in Model\Tag:store - Address https://github.com/friendica/friendica/issues/12486#issuecomment-1372640002 --- src/Model/Tag.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Tag.php b/src/Model/Tag.php index 368be55ddd..8509c30938 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -119,7 +119,7 @@ class Tag $tag = DBA::selectFirst('tag', ['name', 'type'], ['url' => $url]); if (!empty($tag)) { if ($tag['name'] != substr($name, 0, 96)) { - DBA::update('tag', ['name' => substr($name, 0, 96)], ['url' => $url]); + DBA::update('tag', ['name' => substr($name, 0, 96)], ['url' => $url, 'type' => $tag['type']]); } if (!empty($target) && ($tag['type'] != $target)) { DBA::update('tag', ['type' => $target], ['url' => $url]); From 4d5d8e5b64b9511f756c1c9079c723671986e2ef Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jan 2023 10:22:19 -0500 Subject: [PATCH 2/4] Add line number to output in System::callstack --- src/Core/System.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/System.php b/src/Core/System.php index f94004a880..3feaac31dc 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -253,12 +253,12 @@ class System $func['database'] = in_array($func['class'], ['Friendica\Database\DBA', 'Friendica\Database\Database']); if (!$previous['database'] || !$func['database']) { $classparts = explode("\\", $func['class']); - $callstack[] = array_pop($classparts).'::'.$func['function']; + $callstack[] = array_pop($classparts).'::'.$func['function'] . '(' . $func['line'] . ')'; $previous = $func; } } elseif (!in_array($func['function'], $ignore)) { $func['database'] = ($func['function'] == 'q'); - $callstack[] = $func['function']; + $callstack[] = $func['function'] . '(' . $func['line'] . ')'; $func['class'] = ''; $previous = $func; } From b77f3a7525aab36fe2179be71fd892e4229ba07d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jan 2023 10:27:45 -0500 Subject: [PATCH 3/4] 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); From 14e4c0db8e4ede6e9567893cc1b67f7ccbde0eca Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jan 2023 10:29:56 -0500 Subject: [PATCH 4/4] Check image property is set in Object\Image - Property was either an object or null, strict comparison with "false" was inaccurate - Address https://github.com/friendica/friendica/issues/12486#issuecomment-1374888800 --- src/Object/Image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Object/Image.php b/src/Object/Image.php index 00f8f3c5bb..d6c897e88d 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -196,7 +196,7 @@ class Image public function isValid(): bool { if ($this->isImagick()) { - return ($this->image !== false); + return !empty($this->image); } return $this->valid; }