]> git.mxchange.org Git - friendica.git/commitdiff
extract Item::prepareItemD() into own method
authorArt4 <art4@wlabs.de>
Thu, 9 Jan 2025 20:19:35 +0000 (20:19 +0000)
committerArt4 <art4@wlabs.de>
Thu, 9 Jan 2025 20:19:35 +0000 (20:19 +0000)
src/Model/Item.php

index 89544fc716b17b0757b754bfd3bd6d594edbd7ad..40fe7dbd42d46bc2d69bbe7d9079c8b38a73bcf6 100644 (file)
@@ -882,23 +882,7 @@ class Item
                        $item['network'] = trim(($item['network'] ?? '') ?: Protocol::PHANTOM);
                }
 
-               $uid = intval($item['uid']);
-
-               $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']);
+               $item = self::prepareItemData($item, (bool) $notify);
 
                // Store conversation data
                $source = $item['source'] ?? '';
@@ -928,6 +912,8 @@ class Item
 
                $defined_permissions = isset($item['allow_cid']) && isset($item['allow_gid']) && isset($item['deny_cid']) && isset($item['deny_gid']) && isset($item['private']);
 
+               $uid = intval($item['uid']);
+
                // Communities aren't working with the Diaspora protocol
                if (($uid != 0) && ($item['network'] == Protocol::DIASPORA)) {
                        $user = User::getById($uid, ['account-type']);
@@ -1425,6 +1411,27 @@ 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);