mirror of
https://github.com/friendica/friendica
synced 2025-04-27 21:50:11 +00:00
"selectForUser" and "" selectFirstForUser" is now moved to Post
This commit is contained in:
parent
c1226bff07
commit
2b1d0b9db8
29 changed files with 179 additions and 121 deletions
|
@ -1296,9 +1296,9 @@ class Contact
|
|||
}
|
||||
|
||||
if (empty($contact["network"]) || in_array($contact["network"], Protocol::FEDERATED)) {
|
||||
$sql = "(`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))";
|
||||
$sql = "(`uid` = 0 OR (`uid` = ? AND NOT `global`))";
|
||||
} else {
|
||||
$sql = "`item`.`uid` = ?";
|
||||
$sql = "`uid` = ?";
|
||||
}
|
||||
|
||||
$contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id');
|
||||
|
@ -1340,18 +1340,11 @@ class Contact
|
|||
}
|
||||
|
||||
if ($thread_mode) {
|
||||
$r = Item::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri', 'thr-parent-id', 'author-id'], $condition, $params);
|
||||
$items = [];
|
||||
while ($item = DBA::fetch($r)) {
|
||||
$items[] = $item;
|
||||
}
|
||||
DBA::close($r);
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri', 'thr-parent-id', 'author-id'], $condition, $params));
|
||||
|
||||
$o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
|
||||
} else {
|
||||
$r = Item::selectForUser(local_user(), [], $condition, $params);
|
||||
|
||||
$items = Item::inArray($r);
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), [], $condition, $params));
|
||||
|
||||
$o .= conversation($a, $items, 'contact-posts', $update);
|
||||
}
|
||||
|
|
|
@ -353,7 +353,7 @@ class Item
|
|||
* @param bool $do_close
|
||||
* @return array Data array
|
||||
*/
|
||||
public static function inArray($stmt, $do_close = true) {
|
||||
public static function toArray($stmt, $do_close = true) {
|
||||
if (is_bool($stmt)) {
|
||||
return $stmt;
|
||||
}
|
||||
|
@ -390,28 +390,6 @@ class Item
|
|||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single record from the item table for a given user and returns it in an associative array
|
||||
*
|
||||
* @param integer $uid User ID
|
||||
* @param array $selected
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
* @return bool|array
|
||||
* @throws \Exception
|
||||
* @see DBA::select
|
||||
*/
|
||||
public static function selectFirstForUser($uid, array $selected = [], array $condition = [], $params = [])
|
||||
{
|
||||
$params['uid'] = $uid;
|
||||
|
||||
if (empty($selected)) {
|
||||
$selected = self::DISPLAY_FIELDLIST;
|
||||
}
|
||||
|
||||
return self::selectFirst($selected, $condition, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select rows from the item table for a given user
|
||||
*
|
||||
|
@ -1518,7 +1496,7 @@ class Item
|
|||
'wall', 'private', 'forum_mode', 'origin', 'author-id'];
|
||||
$condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid']];
|
||||
$params = ['order' => ['id' => false]];
|
||||
$parent = self::selectFirst($fields, $condition, $params);
|
||||
$parent = Post::selectFirst($fields, $condition, $params);
|
||||
|
||||
if (!DBA::isResult($parent)) {
|
||||
Logger::notice('item parent was not found - ignoring item', ['thr-parent' => $item['thr-parent'], 'uid' => $item['uid']]);
|
||||
|
@ -1533,7 +1511,7 @@ class Item
|
|||
'parent-uri' => $parent['parent-uri'],
|
||||
'uid' => $parent['uid']];
|
||||
$params = ['order' => ['id' => false]];
|
||||
$toplevel_parent = self::selectFirst($fields, $condition, $params);
|
||||
$toplevel_parent = Post::selectFirst($fields, $condition, $params);
|
||||
if (!DBA::isResult($toplevel_parent)) {
|
||||
Logger::notice('item top level parent was not found - ignoring item', ['parent-uri' => $parent['parent-uri'], 'uid' => $parent['uid']]);
|
||||
return [];
|
||||
|
@ -2019,7 +1997,7 @@ class Item
|
|||
$transmit = $notify || ($item['visible'] && ($parent_origin || $item['origin']));
|
||||
|
||||
if ($transmit) {
|
||||
$transmit_item = self::selectFirst(['verb', 'origin'], ['id' => $item['id']]);
|
||||
$transmit_item = Post::selectFirst(['verb', 'origin'], ['id' => $item['id']]);
|
||||
// Don't relay participation messages
|
||||
if (($transmit_item['verb'] == Activity::FOLLOW) &&
|
||||
(!$transmit_item['origin'] || ($item['author-id'] != Contact::getPublicIdByUserId($uid)))) {
|
||||
|
|
|
@ -56,7 +56,7 @@ class ItemContent
|
|||
'limit' => [$start, $limit]
|
||||
];
|
||||
|
||||
$tags = DBA::select('item', ['uri-id'], $condition, $params);
|
||||
$tags = Post::select(['uri-id'], $condition, $params);
|
||||
|
||||
$uriids = [];
|
||||
while ($tag = DBA::fetch($tags)) {
|
||||
|
@ -73,7 +73,7 @@ class ItemContent
|
|||
AND (NOT `private` OR (`private` AND `uid` = ?))
|
||||
AND `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `network` IN (?, ?, ?, ?))",
|
||||
$search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
|
||||
return DBA::count('item', $condition);
|
||||
return Post::count($condition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -89,7 +89,7 @@ class Post
|
|||
* @param bool $do_close
|
||||
* @return array Data array
|
||||
*/
|
||||
public static function inArray($stmt, $do_close = true) {
|
||||
public static function toArray($stmt, $do_close = true) {
|
||||
if (is_bool($stmt)) {
|
||||
return $stmt;
|
||||
}
|
||||
|
@ -213,4 +213,83 @@ class Post
|
|||
|
||||
return DBA::select('post-view', $selected, $condition, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select rows from the post view for a given user
|
||||
*
|
||||
* @param integer $uid User ID
|
||||
* @param array $selected Array of selected fields, empty for all
|
||||
* @param array $condition Array of fields for condition
|
||||
* @param array $params Array of several parameters
|
||||
*
|
||||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectForUser($uid, array $selected = [], array $condition = [], $params = [])
|
||||
{
|
||||
if (empty($selected)) {
|
||||
$selected = Item::DISPLAY_FIELDLIST;
|
||||
}
|
||||
|
||||
$selected = array_unique(array_merge($selected, ['internal-uri-id', 'internal-uid', 'internal-file-count']));
|
||||
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
["`visible` AND NOT `deleted` AND NOT `moderated`
|
||||
AND NOT `author-blocked` AND NOT `owner-blocked`
|
||||
AND (NOT `causer-blocked` OR `causer-id` = ?) AND NOT `contact-blocked`
|
||||
AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
|
||||
OR `self` OR `gravity` != ? OR `contact-uid` = ?)
|
||||
AND NOT EXISTS (SELECT `iid` FROM `user-item` WHERE `hidden` AND `iid` = `id` AND `uid` = ?)
|
||||
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `author-id` AND `blocked`)
|
||||
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `owner-id` AND `blocked`)
|
||||
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `author-id` AND `ignored` AND `gravity` = ?)
|
||||
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `owner-id` AND `ignored` AND `gravity` = ?)",
|
||||
0, Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, 0, $uid, $uid, $uid, $uid, GRAVITY_PARENT, $uid, GRAVITY_PARENT]);
|
||||
|
||||
$select_string = '';
|
||||
|
||||
if (in_array('pinned', $selected)) {
|
||||
$selected = array_flip($selected);
|
||||
unset($selected['pinned']);
|
||||
$selected = array_flip($selected);
|
||||
|
||||
$select_string = '(SELECT `pinned` FROM `user-item` WHERE `iid` = `post-view`.`id` AND uid=`post-view`.`uid`) AS `pinned`, ';
|
||||
}
|
||||
|
||||
$select_string .= implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));
|
||||
|
||||
$condition_string = DBA::buildCondition($condition);
|
||||
$param_string = DBA::buildParameter($params);
|
||||
|
||||
$sql = "SELECT " . $select_string . " FROM `post-view` " . $condition_string . $param_string;
|
||||
$sql = DBA::cleanQuery($sql);
|
||||
|
||||
return DBA::p($sql, $condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single record from the post view for a given user and returns it in an associative array
|
||||
*
|
||||
* @param integer $uid User ID
|
||||
* @param array $selected
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
* @return bool|array
|
||||
* @throws \Exception
|
||||
* @see DBA::select
|
||||
*/
|
||||
public static function selectFirstForUser($uid, array $selected = [], array $condition = [], $params = [])
|
||||
{
|
||||
$params['limit'] = 1;
|
||||
|
||||
$result = self::selectForUser($uid, $selected, $condition, $params);
|
||||
|
||||
if (is_bool($result)) {
|
||||
return $result;
|
||||
} else {
|
||||
$row = self::fetch($result);
|
||||
DBA::close($result);
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue