]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/ItemURI.php
Merge pull request #11877 from annando/log-levels
[friendica.git] / src / Model / ItemURI.php
index 460ee1447004becb635d059fb63fd2705515748b..86d23ed541afd659f12f68d7760384804f30e8d9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -30,7 +30,6 @@ class ItemURI
         * Insert an item-uri record and return its id
         *
         * @param array $fields Item-uri fields
-        *
         * @return int|null item-uri id
         * @throws \Exception
         */
@@ -61,32 +60,38 @@ class ItemURI
         * Searched for an id of a given uri. Adds it, if not existing yet.
         *
         * @param string $uri
+        * @param bool   $insert
         *
         * @return integer item-uri id
+        *
         * @throws \Exception
         */
-       public static function getIdByURI($uri)
+       public static function getIdByURI(string $uri, bool $insert = true): int
        {
+               if (empty($uri)) {
+                       return 0;
+               }
+
                // If the URI gets too long we only take the first parts and hope for best
                $uri = substr($uri, 0, 255);
 
                $itemuri = DBA::selectFirst('item-uri', ['id'], ['uri' => $uri]);
 
-               if (!DBA::isResult($itemuri)) {
+               if (!DBA::isResult($itemuri) && $insert) {
                        return self::insert(['uri' => $uri]);
                }
 
-               return $itemuri['id'];
+               return $itemuri['id'] ?? 0;
        }
+
        /**
         * Searched for an id of a given guid.
         *
         * @param string $guid
-        *
         * @return integer item-uri id
         * @throws \Exception
         */
-       public static function getIdByGUID($guid)
+       public static function getIdByGUID(string $guid): int
        {
                // If the GUID gets too long we only take the first parts and hope for best
                $guid = substr($guid, 0, 255);