]> git.mxchange.org Git - friendica.git/commitdiff
Move Item::prepareItemData() into ItemInserter
authorArt4 <art4@wlabs.de>
Thu, 9 Jan 2025 21:04:12 +0000 (21:04 +0000)
committerArt4 <art4@wlabs.de>
Thu, 9 Jan 2025 21:04:12 +0000 (21:04 +0000)
src/Model/Item.php
src/Model/ItemInserter.php

index 782c497ab2f6cc86ca130d790d4604a576656d19..8035d89631f0d0f294f921229a79a10db7b3b2f3 100644 (file)
@@ -876,7 +876,7 @@ class Item
                        $item['network'] = trim(($item['network'] ?? '') ?: Protocol::PHANTOM);
                }
 
-               $item = self::prepareItemData($item, (bool) $notify);
+               $item = $itemInserter->prepareItemData($item, (bool) $notify);
 
                // Store conversation data
                $source = $item['source'] ?? '';
@@ -1364,27 +1364,6 @@ class Item
                return $post_user_id;
        }
 
-       private static function prepareItemData(array $item, bool $notify): array
-       {
-               $item['guid'] = self::guid($item, $notify);
-               $item['uri'] = substr(trim($item['uri'] ?? '') ?: self::newURI($item['guid']), 0, 255);
-
-               // Store URI data
-               $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
-
-               // Backward compatibility: parent-uri used to be the direct parent uri.
-               // If it is provided without a thr-parent, it probably is the old behavior.
-               if (empty($item['thr-parent']) || empty($item['parent-uri'])) {
-                       $item['thr-parent'] = trim($item['thr-parent'] ?? $item['parent-uri'] ?? $item['uri']);
-                       $item['parent-uri'] = $item['thr-parent'];
-               }
-
-               $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
-               $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
-
-               return $item;
-       }
-
        private static function validateItemData(array $item): array
        {
                $item['wall']          = intval($item['wall'] ?? 0);
index 6db36f8ed53431463ddd9008c936b26fb66d110a..a19a5be46cc8f433386d3813e66c4e4f134b3b6c 100644 (file)
@@ -16,18 +16,39 @@ use Friendica\Content\Item as ItemContent;
  */
 final class ItemInserter
 {
-    private ItemContent $itemContent;
+       private ItemContent $itemContent;
 
-    public function __construct(ItemContent $itemContent)
-    {
-        $this->itemContent = $itemContent;
-    }
+       public function __construct(ItemContent $itemContent)
+       {
+               $this->itemContent = $itemContent;
+       }
 
-    public function prepareOriginPost(array $item): array
+       public function prepareOriginPost(array $item): array
        {
                $item = $this->itemContent->initializePost($item);
                $item = $this->itemContent->finalizePost($item, false);
 
                return $item;
        }
-}
\ No newline at end of file
+
+       public function prepareItemData(array $item, bool $notify): array
+       {
+               $item['guid'] = Item::guid($item, $notify);
+               $item['uri'] = substr(trim($item['uri'] ?? '') ?: Item::newURI($item['guid']), 0, 255);
+
+               // Store URI data
+               $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
+
+               // Backward compatibility: parent-uri used to be the direct parent uri.
+               // If it is provided without a thr-parent, it probably is the old behavior.
+               if (empty($item['thr-parent']) || empty($item['parent-uri'])) {
+                       $item['thr-parent'] = trim($item['thr-parent'] ?? $item['parent-uri'] ?? $item['uri']);
+                       $item['parent-uri'] = $item['thr-parent'];
+               }
+
+               $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
+               $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
+
+               return $item;
+       }
+}