diff --git a/src/Model/Item.php b/src/Model/Item.php index ce62e86c4f..d78daf605d 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -650,42 +650,6 @@ class Item return true; } - /** - * Return the id of the given item array if it has been stored before - * - * @param array $item Item record - * @return integer Item id or zero on error - */ - private static function getDuplicateID(array $item): int - { - if (empty($item['network']) || in_array($item['network'], Protocol::FEDERATED)) { - $condition = [ - '`uri-id` = ? AND `uid` = ? AND `network` IN (?, ?, ?)', - $item['uri-id'], - $item['uid'], - Protocol::ACTIVITYPUB, - Protocol::DIASPORA, - Protocol::DFRN - ]; - $existing = Post::selectFirst(['id', 'network'], $condition); - if (DBA::isResult($existing)) { - // We only log the entries with a different user id than 0. Otherwise we would have too many false positives - if ($item['uid'] != 0) { - DI::logger()->notice('Item already existed for user', [ - 'uri-id' => $item['uri-id'], - 'uid' => $item['uid'], - 'network' => $item['network'], - 'existing_id' => $existing['id'], - 'existing_network' => $existing['network'] - ]); - } - - return $existing['id']; - } - } - return 0; - } - /** * Fetch the uri-id of the parent for the given uri-id * @@ -758,7 +722,7 @@ class Item * We have to check several networks since Friendica posts could be repeated * via Diaspora. */ - $duplicate = self::getDuplicateID($item); + $duplicate = $itemHelper->getDuplicateID($item); if ($duplicate) { return $duplicate; } diff --git a/src/Model/ItemHelper.php b/src/Model/ItemHelper.php index 000208d913..9b585fd544 100644 --- a/src/Model/ItemHelper.php +++ b/src/Model/ItemHelper.php @@ -18,7 +18,7 @@ use Psr\Log\LoggerInterface; /** * A helper class for handling an Item Model * - * @internal only for use in Friendica\Content\Item class + * @internal ONLY for use in Friendica\Content\Item class * * @see Item::insert() */ @@ -77,6 +77,44 @@ final class ItemHelper return $item; } + /** + * Return the id of the given item array if it has been stored before + * + * @param array $item Item record + * @return integer Item id or zero on error + */ + public function getDuplicateID(array $item): int + { + if (empty($item['network']) || in_array($item['network'], Protocol::FEDERATED)) { + $condition = [ + '`uri-id` = ? AND `uid` = ? AND `network` IN (?, ?, ?)', + $item['uri-id'], + $item['uid'], + Protocol::ACTIVITYPUB, + Protocol::DIASPORA, + Protocol::DFRN + ]; + + $existing = Post::selectFirst(['id', 'network'], $condition); + + if ($this->database->isResult($existing)) { + // We only log the entries with a different user id than 0. Otherwise we would have too many false positives + if ($item['uid'] != 0) { + $this->logger->notice('Item already existed for user', [ + 'uri-id' => $item['uri-id'], + 'uid' => $item['uid'], + 'network' => $item['network'], + 'existing_id' => $existing['id'], + 'existing_network' => $existing['network'] + ]); + } + + return $existing['id']; + } + } + return 0; + } + /** * Check if the item array is a duplicate *