use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1316);
+ define('DB_UPDATE_VERSION', 1317);
}
return [
"extid" => ["extid(191)"],
"uid_id" => ["uid", "id"],
"uid_contactid_id" => ["uid", "contact-id", "id"],
- "uid_created" => ["uid", "created"],
+ "uid_received" => ["uid", "received"],
"uid_commented" => ["uid", "commented"],
"uid_unseen_contactid" => ["uid", "unseen", "contact-id"],
"uid_network_received" => ["uid", "network", "received"],
"uid_network_commented" => ["uid", "network", "commented"],
"uid_thrparent" => ["uid", "thr-parent(190)"],
"uid_parenturi" => ["uid", "parent-uri(190)"],
- "uid_contactid_created" => ["uid", "contact-id", "created"],
- "authorid_created" => ["author-id", "created"],
+ "uid_contactid_received" => ["uid", "contact-id", "received"],
+ "authorid_received" => ["author-id", "received"],
"ownerid" => ["owner-id"],
"contact-id" => ["contact-id"],
"uid_uri" => ["uid", "uri(190)"],
"indexes" => [
"PRIMARY" => ["iid"],
"uid_network_commented" => ["uid", "network", "commented"],
- "uid_network_created" => ["uid", "network", "created"],
+ "uid_network_received" => ["uid", "network", "received"],
"uid_contactid_commented" => ["uid", "contact-id", "commented"],
- "uid_contactid_created" => ["uid", "contact-id", "created"],
+ "uid_contactid_received" => ["uid", "contact-id", "received"],
"contactid" => ["contact-id"],
"ownerid" => ["owner-id"],
"authorid" => ["author-id"],
- "uid_created" => ["uid", "created"],
+ "uid_received" => ["uid", "received"],
"uid_commented" => ["uid", "commented"],
- "uid_wall_created" => ["uid", "wall", "created"],
+ "uid_wall_received" => ["uid", "wall", "received"],
"private_wall_origin_commented" => ["private", "wall", "origin", "commented"],
]
],
if ($throttle_day > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
- $condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
+ $condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom];
$posts_day = DBA::count('thread', $condition);
if ($posts_day > $throttle_day) {
if ($throttle_week > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
- $condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
+ $condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom];
$posts_week = DBA::count('thread', $condition);
if ($posts_week > $throttle_week) {
if ($throttle_month > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
- $condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
+ $condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom];
$posts_month = DBA::count('thread', $condition);
if ($posts_month > $throttle_month) {
$fields = ['author-id', 'author-name', 'author-link', 'author-avatar'];
$activity = Item::activityToIndex(ACTIVITY2_ANNOUNCE);
$condition = ['parent-uri' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY, 'uid' => [0, $item['uid']], 'activity' => $activity];
- $announce = Item::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['created' => true]]);
+ $announce = Item::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['received' => true]]);
if (!DBA::isResult($announce)) {
return [];
}
$parentlines = [];
$lineno = 0;
$actor = [];
- $created = '';
+ $received = '';
while ($row = Item::fetch($thread_items)) {
- if (($row['verb'] == ACTIVITY2_ANNOUNCE) && !empty($row['contact-uid']) && ($row['created'] > $created) && ($row['thr-parent'] == $row['parent-uri'])) {
+ if (($row['verb'] == ACTIVITY2_ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
$actor = ['link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
- $created = $row['created'];
+ $received = $row['received'];
}
if ((($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && !in_array($row['network'], [Protocol::DIASPORA])) &&
function sort_item_children(array $items)
{
$result = $items;
- usort($result, 'sort_thr_created_rev');
+ usort($result, 'sort_thr_received_rev');
foreach ($result as $k => $i) {
if (isset($result[$k]['children'])) {
$result[$k]['children'] = sort_item_children($result[$k]['children']);
/**
* Expands a flat list of items into corresponding tree-like conversation structures,
- * sort the top-level posts either on "created" or "commented", and finally
+ * sort the top-level posts either on "received" or "commented", and finally
* append all the items at the top level (???)
*
* @brief Expands a flat item list into a conversation array for display
*
* @param array $item_list A list of items belonging to one or more conversations
- * @param string $order Either on "created" or "commented"
+ * @param string $order Either on "received" or "commented"
* @return array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
}
}
- if (stristr($order, 'created')) {
- usort($parents, 'sort_thr_created');
+ if (stristr($order, 'received')) {
+ usort($parents, 'sort_thr_received');
} elseif (stristr($order, 'commented')) {
usort($parents, 'sort_thr_commented');
}
}
/**
- * @brief usort() callback to sort item arrays by the created key
+ * @brief usort() callback to sort item arrays by the received key
*
* @param array $a
* @param array $b
* @return int
*/
-function sort_thr_created(array $a, array $b)
+function sort_thr_received(array $a, array $b)
{
- return strcmp($b['created'], $a['created']);
+ return strcmp($b['received'], $a['received']);
}
/**
- * @brief usort() callback to reverse sort item arrays by the created key
+ * @brief usort() callback to reverse sort item arrays by the received key
*
* @param array $a
* @param array $b
* @return int
*/
-function sort_thr_created_rev(array $a, array $b)
+function sort_thr_received_rev(array $a, array $b)
{
- return strcmp($a['created'], $b['created']);
+ return strcmp($a['received'], $b['received']);
}
/**
}
if ($datequery) {
- $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.created <= '%s' ",
+ $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received <= '%s' ",
DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
}
if ($datequery2) {
- $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.created >= '%s' ",
+ $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received >= '%s' ",
DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
}
// Normal conversation view
if ($order === 'post') {
- $ordering = '`created`';
- $order_mode = 'created';
+ $ordering = '`received`';
+ $order_mode = 'received';
} else {
$ordering = '`commented`';
$order_mode = 'commented';
$condition = ["`unseen` AND `uid` = ? AND `contact-id` != ?", local_user(), local_user()];
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid', 'wall'];
- $params = ['order' => ['created' => true]];
+ $params = ['order' => ['received' => true]];
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
if (DBA::isResult($items)) {
$condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`))
AND `otype` = ? AND `type` = ? AND `term` = ?",
local_user(), TERM_OBJ_POST, TERM_HASHTAG, $search];
- $params = ['order' => ['created' => true],
+ $params = ['order' => ['received' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
$terms = DBA::select('term', ['oid'], $condition, $params);
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
- $params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
+ $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
- $params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
+ $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
- $params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
+ $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
if (DBA::isResult($items)) {
$pager = new Pager($a->query_string);
- $params = ['order' => ['created' => true],
+ $params = ['order' => ['received' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
if ($thread_mode) {
Logger::log('duplicated item with the same guid found. '.print_r($item,true));
return 0;
}
- } else {
+ } elseif ($item['network'] == Protocol::OSTATUS) {
// Check for an existing post with the same content. There seems to be a problem with OStatus.
$condition = ["`body` = ? AND `network` = ? AND `created` = ? AND `contact-id` = ? AND `uid` = ?",
$item['body'], $item['network'], $item['created'], $item['contact-id'], $item['uid']];
if ($network != "") {
$condition[0] .= " AND `network` = ?";
$condition[] = $network;
-
- /*
- * There is an index "uid_network_received" but not "uid_network_created"
- * This avoids the creation of another index just for one purpose.
- * And it doesn't really matter wether to look at "received" or "created"
- */
- $condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
- $condition[] = $days;
- } else {
- $condition[0] .= " AND `created` < UTC_TIMESTAMP() - INTERVAL ? DAY";
- $condition[] = $days;
}
+ $condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
+ $condition[] = $days;
+
$items = self::select(['file', 'resource-id', 'starred', 'type', 'id', 'post-type'], $condition);
if (!DBA::isResult($items)) {
public static function firstPostDate($uid, $wall = false)
{
$condition = ['uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true, 'moderated' => false];
- $params = ['order' => ['created' => false]];
- $thread = DBA::selectFirst('thread', ['created'], $condition, $params);
+ $params = ['order' => ['received' => false]];
+ $thread = DBA::selectFirst('thread', ['received'], $condition, $params);
if (DBA::isResult($thread)) {
- return substr(DateTimeFormat::local($thread['created']), 0, 10);
+ return substr(DateTimeFormat::local($thread['received']), 0, 10);
}
return false;
}
AND `item`.`wall`
$sql_extra4
$sql_extra
- ORDER BY `item`.`created` DESC",
+ ORDER BY `item`.`received` DESC",
$a->profile['profile_uid'],
GRAVITY_ACTIVITY
);
}
if (!empty($datequery)) {
- $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
+ $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
}
if (!empty($datequery2)) {
- $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
+ $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
}
// Does the profile page belong to a forum?
$sql_extra3
$sql_extra
$sql_extra2
- ORDER BY `thread`.`created` DESC
+ ORDER BY `thread`.`received` DESC
$pager_sql",
$a->profile['profile_uid']
);
$items = DBA::toArray($items_stmt);
- $o .= conversation($a, $items, $pager, 'profile', $update, false, 'created', $a->profile['profile_uid']);
+ $o .= conversation($a, $items, $pager, 'profile', $update, false, 'received', $a->profile['profile_uid']);
if (!$update) {
$o .= $pager->renderMinimal(count($items));
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`wall` AND `item`.`changed` > '%s'
AND `item`.`visible` $sql_extra
- ORDER BY `item`.`parent` ".$sort.", `item`.`created` ASC LIMIT 0, 300",
+ ORDER BY `item`.`parent` ".$sort.", `item`.`received` ASC LIMIT 0, 300",
intval($owner_id),
DBA::escape($check_date),
DBA::escape($sort)
$check_date = DateTimeFormat::utc($last_update);
$authorid = Contact::getIdForURL($owner["url"], 0, true);
- $condition = ["`uid` = ? AND `created` > ? AND NOT `deleted`
+ $condition = ["`uid` = ? AND `received` > ? AND NOT `deleted`
AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
$owner["uid"], $check_date, Protocol::OSTATUS, Protocol::DFRN];
$condition[] = $authorid;
}
- $params = ['order' => ['created' => true], 'limit' => $max_items];
+ $params = ['order' => ['received' => true], 'limit' => $max_items];
if ($filter === 'posts') {
$ret = Item::selectThread([], $condition, $params);