]> git.mxchange.org Git - friendica.git/blob - src/Model/ItemURI.php
Merge pull request #6127 from annando/notice
[friendica.git] / src / Model / ItemURI.php
1 <?php
2
3 /**
4  * @file src/Model/ItemURI.php
5  */
6
7 namespace Friendica\Model;
8
9 use Friendica\BaseObject;
10 use Friendica\Database\DBA;
11
12 require_once 'boot.php';
13
14 class ItemURI extends BaseObject
15 {
16         /**
17          * @brief Insert an item-uri record and return its id
18          *
19          * @param array $fields Item-uri fields
20          *
21          * @return integer item-uri id
22          */
23         public static function insert($fields)
24         {
25                 if (!DBA::exists('item-uri', ['uri' => $fields['uri']])) {
26                         DBA::insert('item-uri', $fields, true);
27                 }
28
29                 $itemuri = DBA::selectFirst('item-uri', ['id'], ['uri' => $fields['uri']]);
30
31                 if (!DBA::isResult($itemuri)) {
32                         // This shouldn't happen
33                         return null;
34                 }
35
36                 return $itemuri['id'];
37         }
38
39         /**
40          * @brief Searched for an id of a given uri. Adds it, if not existing yet.
41          *
42          * @param string $uri
43          *
44          * @return integer item-uri id
45          */
46         public static function getIdByURI($uri)
47         {
48                 $itemuri = DBA::selectFirst('item-uri', ['id'], ['uri' => $uri]);
49
50                 if (!DBA::isResult($itemuri)) {
51                         return self::insert(['uri' => $uri]);
52                 }
53
54                 return $itemuri['id'];
55         }
56 }