From 0441b912acc6451a04e8e7ac79b07f2b1de1a957 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 13 Dec 2020 13:42:08 -0500 Subject: [PATCH] Return early if an URI id cannot be obtained in ActivityPub\Processor::createItem - Address https://github.com/friendica/friendica/issues/9250#issuecomment-743769813 --- src/Model/ItemURI.php | 4 ++-- src/Protocol/ActivityPub/Processor.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Model/ItemURI.php b/src/Model/ItemURI.php index 7f05786c8..6421b2dbd 100644 --- a/src/Model/ItemURI.php +++ b/src/Model/ItemURI.php @@ -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); diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 088a10e90..f60eea712 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -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)) {