4 * @file src/Model/ItemURI.php
7 namespace Friendica\Model;
9 use Friendica\BaseObject;
10 use Friendica\Database\DBA;
12 require_once 'boot.php';
14 class ItemURI extends BaseObject
17 * @brief Insert an item-uri record and return its id
19 * @param array $fields Item-uri fields
21 * @return integer item-uri id
23 public static function insert($fields)
25 if (!DBA::exists('item-uri', ['uri' => $fields['uri']])) {
26 DBA::insert('item-uri', $fields, true);
29 $itemuri = DBA::selectFirst('item-uri', ['id'], ['uri' => $fields['uri']]);
31 if (!DBA::isResult($itemuri)) {
32 // This shouldn't happen
36 return $itemuri['id'];
40 * @brief Searched for an id of a given uri. Adds it, if not existing yet.
44 * @return integer item-uri id
46 public static function getIdByURI($uri)
48 $itemuri = DBA::selectFirst('item-uri', ['id'], ['uri' => $uri]);
50 if (!DBA::isResult($itemuri)) {
51 return self::insert(['uri' => $uri]);
54 return $itemuri['id'];