]> git.mxchange.org Git - friendica.git/commitdiff
Extract getDuplicateID() into ItemHelper
authorArt4 <art4@wlabs.de>
Thu, 23 Jan 2025 13:26:58 +0000 (13:26 +0000)
committerArt4 <art4@wlabs.de>
Thu, 23 Jan 2025 13:26:58 +0000 (13:26 +0000)
src/Model/Item.php
src/Model/ItemHelper.php

index ce62e86c4f8f0779fd454240e3e3f7bd750bbd64..d78daf605d36657eac321802fb10de67626be158 100644 (file)
@@ -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;
                }
index 000208d9134c5dd1e9b89c098b6826b006f56ee9..9b585fd5446d5bfd21b32f0401b602b9a2c0678d 100644 (file)
@@ -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
         *