]> git.mxchange.org Git - friendica.git/blob - src/Model/Item.php
use dba
[friendica.git] / src / Model / Item.php
1 <?php
2
3 /**
4  * @file src/Model/Item.php
5  */
6
7 namespace Friendica\Model;
8
9 use Friendica\Core\Worker;
10 use Friendica\Model\Term;
11 use dba;
12
13 require_once 'include/tags.php';
14 require_once 'include/threads.php';
15
16 class Item
17 {
18         /**
19          * @brief Update existing item entries
20          *
21          * @param array $fields The fields that are to be changed
22          * @param array $condition The condition for finding the item entries
23          *
24          * In the future we may have to change permissions as well.
25          * Then we had to add the user id as third parameter.
26          *
27          * A return value of "0" doesn't mean an error - but that 0 rows had been changed.
28          *
29          * @return integer|boolean number of affected rows - or "false" if there was an error
30          */
31         public static function update(array $fields, array $condition)
32         {
33                 if (empty($condition) || empty($fields)) {
34                         return false;
35                 }
36
37                 $success = dba::update('item', $fields, $condition);
38
39                 if (!$success) {
40                         return false;
41                 }
42
43                 $rows = dba::affected_rows();
44
45                 // We cannot simply expand the condition to check for origin entries
46                 // The condition needn't to be a simple array but could be a complex condition.
47                 $items = dba::select('item', ['id', 'origin'], $condition);
48                 while ($item = dba::fetch($items)) {
49                         // We only need to notfiy others when it is an original entry from us
50                         if (!$item['origin']) {
51                                 continue;
52                         }
53
54                         create_tags_from_item($item['id']);
55                         Term::createFromItem($item['id']);
56                         update_thread($item['id']);
57
58                         Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']);
59                 }
60
61                 return $rows;
62         }
63 }