4 * @file src/Model/ItemURI.php
7 namespace Friendica\Model;
9 use Friendica\BaseObject;
10 use Friendica\Database\DBA;
12 class ItemURI extends BaseObject
15 * @brief Insert an item-uri record and return its id
17 * @param array $fields Item-uri fields
19 * @return integer item-uri id
22 public static function insert($fields)
24 // If the URI gets too long we only take the first parts and hope for best
25 $uri = substr($fields['uri'], 0, 255);
27 if (!DBA::exists('item-uri', ['uri' => $uri])) {
28 DBA::insert('item-uri', $fields, true);
31 $itemuri = DBA::selectFirst('item-uri', ['id'], ['uri' => $uri]);
33 if (!DBA::isResult($itemuri)) {
34 // This shouldn't happen
38 return $itemuri['id'];
42 * @brief Searched for an id of a given uri. Adds it, if not existing yet.
46 * @return integer item-uri id
49 public static function getIdByURI($uri)
51 // If the URI gets too long we only take the first parts and hope for best
52 $uri = substr($uri, 0, 255);
54 $itemuri = DBA::selectFirst('item-uri', ['id'], ['uri' => $uri]);
56 if (!DBA::isResult($itemuri)) {
57 return self::insert(['uri' => $uri]);
60 return $itemuri['id'];