4 * @file src/Model/ItemURI.php
7 namespace Friendica\Model;
9 use Friendica\Database\DBA;
14 * Insert an item-uri record and return its id
16 * @param array $fields Item-uri fields
18 * @return integer item-uri id
21 public static function insert($fields)
23 // If the URI gets too long we only take the first parts and hope for best
24 $uri = substr($fields['uri'], 0, 255);
26 if (!DBA::exists('item-uri', ['uri' => $uri])) {
27 DBA::insert('item-uri', $fields, true);
30 $itemuri = DBA::selectFirst('item-uri', ['id'], ['uri' => $uri]);
32 if (!DBA::isResult($itemuri)) {
33 // This shouldn't happen
37 return $itemuri['id'];
41 * Searched for an id of a given uri. Adds it, if not existing yet.
45 * @return integer item-uri id
48 public static function getIdByURI($uri)
50 // If the URI gets too long we only take the first parts and hope for best
51 $uri = substr($uri, 0, 255);
53 $itemuri = DBA::selectFirst('item-uri', ['id'], ['uri' => $uri]);
55 if (!DBA::isResult($itemuri)) {
56 return self::insert(['uri' => $uri]);
59 return $itemuri['id'];