X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItem.php;h=10c705a9959b6e2b4185c3f6887aa727abaefacd;hb=0bc2fe66f54717a3f2e86fd9626dc565e9d00fd7;hp=b9c88bca8650111f6703a8c6762ea70ac9270aaf;hpb=b6cb83ed4c670c3ea9dde080cb7d9a3bb292d6b2;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index b9c88bca86..10c705a995 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -111,7 +111,7 @@ class Item extends BaseObject * @param string $activity activity string * @return integer Activity index */ - private static function activityToIndex($activity) + public static function activityToIndex($activity) { $index = array_search($activity, self::ACTIVITIES); @@ -584,7 +584,13 @@ class Item extends BaseObject } else { $master_table = "`item`"; } - return "$master_table.`visible` AND NOT $master_table.`deleted` AND NOT $master_table.`moderated` AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) "; + return sprintf("$master_table.`visible` AND NOT $master_table.`deleted` AND NOT $master_table.`moderated` + AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) + AND (`user-author`.`blocked` IS NULL OR NOT `user-author`.`blocked`) + AND (`user-author`.`ignored` IS NULL OR NOT `user-author`.`ignored` OR `item`.`gravity` != %d) + AND (`user-owner`.`blocked` IS NULL OR NOT `user-owner`.`blocked`) + AND (`user-owner`.`ignored` IS NULL OR NOT `user-owner`.`ignored` OR `item`.`gravity` != %d) ", + GRAVITY_PARENT, GRAVITY_PARENT); } /** @@ -615,8 +621,10 @@ class Item extends BaseObject OR `contact`.`self` OR `item`.`gravity` != %d OR `contact`.`uid` = 0) STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = $master_table.`author-id` AND NOT `author`.`blocked` STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = $master_table.`owner-id` AND NOT `owner`.`blocked` - LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d", - Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid)); + LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d + LEFT JOIN `user-contact` AS `user-author` ON `user-author`.`cid` = $master_table.`author-id` AND `user-author`.`uid` = %d + LEFT JOIN `user-contact` AS `user-owner` ON `user-owner`.`cid` = $master_table.`owner-id` AND `user-owner`.`uid` = %d", + Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid), intval($uid), intval($uid)); } else { if (strpos($sql_commands, "`contact`.") !== false) { $joins .= "LEFT JOIN `contact` ON `contact`.`id` = $master_table.`contact-id`"; @@ -1928,6 +1936,7 @@ class Item extends BaseObject } else { // This shouldn't happen. logger('Could not insert activity for URI ' . $item['uri'] . ' - should not happen'); + Lock::release('item_insert_activity'); return false; } if ($locked) { @@ -2456,6 +2465,12 @@ class Item extends BaseObject } } + /** + * This function is only used for the old Friendica app on Android that doesn't like paths with guid + * @param string $guid item guid + * @param int $uid user id + * @return array with id and nick of the item with the given guid + */ public static function getIdAndNickByGuid($guid, $uid = 0) { $nick = ""; @@ -2467,28 +2482,28 @@ class Item extends BaseObject // Does the given user have this item? if ($uid) { - /// @todo This query has to be abstracted for the "uri-id" changes - $item = DBA::fetchFirst("SELECT `item`.`id`, `user`.`nickname` FROM `item` - INNER JOIN `user` ON `user`.`uid` = `item`.`uid` - WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` - AND `item`.`guid` = ? AND `item`.`uid` = ?", $guid, $uid); + $item = self::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]); if (DBA::isResult($item)) { - $id = $item["id"]; - $nick = $item["nickname"]; + $user = DBA::selectFirst('user', ['nickname'], ['uid' => $uid]); + if (!DBA::isResult($user)) { + return; + } + $id = $item['id']; + $nick = $user['nickname']; } } // Or is it anywhere on the server? if ($nick == "") { - /// @todo This query has to be abstracted for the "uri-id" changes - $item = DBA::fetchFirst("SELECT `item`.`id`, `user`.`nickname` FROM `item` - INNER JOIN `user` ON `user`.`uid` = `item`.`uid` - WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` - AND NOT `item`.`private` AND `item`.`wall` - AND `item`.`guid` = ?", $guid); + $condition = ["`guid` = ? AND `uid` != 0", $guid]; + $item = self::selectFirst(['id', 'uid'], $condition); if (DBA::isResult($item)) { - $id = $item["id"]; - $nick = $item["nickname"]; + $user = DBA::selectFirst('user', ['nickname'], ['uid' => $item['uid']]); + if (!DBA::isResult($user)) { + return; + } + $id = $item['id']; + $nick = $user['nickname']; } } return ["nick" => $nick, "id" => $id]; @@ -3177,8 +3192,7 @@ class Item extends BaseObject return; } - // Using dba::delete at this time could delete the associated item entries - $result = DBA::e("DELETE FROM `thread` WHERE `iid` = ?", $itemid); + $result = DBA::delete('thread', ['iid' => $itemid], ['cascade' => false]); logger("deleteThread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG);