Merge pull request #9815 from annando/post-again

"item" is replaced by "post-view" / postupdate check added
This commit is contained in:
Hypolite Petovan 2021-01-17 18:06:58 -05:00 committed by GitHub
commit fe373a10aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 152 additions and 826 deletions

View file

@ -40,7 +40,7 @@ define('FRIENDICA_PLATFORM', 'Friendica');
define('FRIENDICA_CODENAME', 'Red Hot Poker'); define('FRIENDICA_CODENAME', 'Red Hot Poker');
define('FRIENDICA_VERSION', '2021.03-dev'); define('FRIENDICA_VERSION', '2021.03-dev');
define('DFRN_PROTOCOL_VERSION', '2.23'); define('DFRN_PROTOCOL_VERSION', '2.23');
define('NEW_UPDATE_ROUTINE_VERSION', 1170); define('NEW_TABLE_STRUCTURE_VERSION', 1288);
/** /**
* Constant with a HTML line break. * Constant with a HTML line break.

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2021.03-dev (Red Hot Poker) -- Friendica 2021.03-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1388 -- DB_UPDATE_VERSION 1389
-- ------------------------------------------ -- ------------------------------------------
@ -1560,10 +1560,13 @@ CREATE VIEW `post-view` AS SELECT
`contact`.`thumb` AS `contact-avatar`, `contact`.`thumb` AS `contact-avatar`,
`contact`.`network` AS `contact-network`, `contact`.`network` AS `contact-network`,
`contact`.`blocked` AS `contact-blocked`, `contact`.`blocked` AS `contact-blocked`,
`contact`.`hidden` AS `contact-hidden`,
`contact`.`readonly` AS `contact-readonly`, `contact`.`readonly` AS `contact-readonly`,
`contact`.`archive` AS `contact-archive`,
`contact`.`pending` AS `contact-pending`, `contact`.`pending` AS `contact-pending`,
`contact`.`rel` AS `contact-rel`, `contact`.`rel` AS `contact-rel`,
`contact`.`uid` AS `contact-uid`, `contact`.`uid` AS `contact-uid`,
`contact`.`contact-type` AS `contact-contact-type`,
IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`,
`contact`.`self` AS `self`, `contact`.`self` AS `self`,
`contact`.`id` AS `cid`, `contact`.`id` AS `cid`,

View file

@ -2041,9 +2041,9 @@ function api_statuses_repeat($type)
Logger::log('API: api_statuses_repeat: '.$id); Logger::log('API: api_statuses_repeat: '.$id);
$fields = ['uri-id', 'network', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink']; $fields = ['uri-id', 'network', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Item::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]); $item = Post::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
if (DBA::isResult($item) && $item['body'] != "") { if (DBA::isResult($item) && !empty($item['body'])) {
if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER])) { if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER])) {
if (!Item::performActivity($id, 'announce', local_user())) { if (!Item::performActivity($id, 'announce', local_user())) {
throw new InternalServerErrorException(); throw new InternalServerErrorException();
@ -6007,7 +6007,7 @@ function bindComments(&$data)
} }
$idStr = DBA::escape(implode(', ', $ids)); $idStr = DBA::escape(implode(', ', $ids));
$sql = "SELECT `parent`, COUNT(*) as comments FROM `item` WHERE `parent` IN ($idStr) AND `deleted` = ? AND `gravity`= ? GROUP BY `parent`"; $sql = "SELECT `parent`, COUNT(*) as comments FROM `post-view` WHERE `parent` IN ($idStr) AND `deleted` = ? AND `gravity`= ? GROUP BY `parent`";
$items = DBA::p($sql, 0, GRAVITY_COMMENT); $items = DBA::p($sql, 0, GRAVITY_COMMENT);
$itemsData = DBA::toArray($items); $itemsData = DBA::toArray($items);

View file

@ -1266,7 +1266,7 @@ function photos_content(App $a)
// as a "post" but displaying instead the photo it is linked to // as a "post" but displaying instead the photo it is linked to
/// @todo Rewrite this query. To do so, $sql_extra must be changed /// @todo Rewrite this query. To do so, $sql_extra must be changed
$linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1", $linked_items = q("SELECT `id` FROM `post-view` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
DBA::escape($datum) DBA::escape($datum)
); );
if (DBA::isResult($linked_items)) { if (DBA::isResult($linked_items)) {

View file

@ -412,8 +412,8 @@ function ping_get_notifications($uid)
do { do {
$r = q( $r = q(
"SELECT `notify`.*, `item`.`visible`, `item`.`deleted` "SELECT `notify`.*, `post-view`.`visible`, `post-view`.`deleted`
FROM `notify` LEFT JOIN `item` ON `item`.`id` = `notify`.`iid` FROM `notify` LEFT JOIN `post-view` ON `post-view`.`id` = `notify`.`iid`
WHERE `notify`.`uid` = %d AND `notify`.`msg` != '' WHERE `notify`.`uid` = %d AND `notify`.`msg` != ''
AND NOT (`notify`.`type` IN (%d, %d)) AND NOT (`notify`.`type` IN (%d, %d))
AND $seensql `notify`.`seen` ORDER BY `notify`.`date` $order LIMIT %d, 50", AND $seensql `notify`.`seen` ORDER BY `notify`.`date` $order LIMIT %d, 50",

View file

@ -209,14 +209,14 @@ class ForumManager
public static function countUnseenItems() public static function countUnseenItems()
{ {
$stmtContacts = DBA::p( $stmtContacts = DBA::p(
"SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item` "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `post-view`
INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id` INNER JOIN `contact` ON `post-view`.`contact-id` = `contact`.`id`
WHERE `item`.`uid` = ? AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen` WHERE `post-view`.`uid` = ? AND `post-view`.`visible` AND NOT `post-view`.`deleted` AND `post-view`.`unseen`
AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`) AND `contact`.`network` IN (?, ?) AND `contact`.`contact-type` = ?
AND NOT `contact`.`blocked` AND NOT `contact`.`hidden` AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
AND NOT `contact`.`pending` AND NOT `contact`.`archive` AND NOT `contact`.`pending` AND NOT `contact`.`archive`
GROUP BY `contact`.`id` ", GROUP BY `contact`.`id`",
local_user() local_user(), Protocol::DFRN, Protocol::ACTIVITYPUB, Contact::TYPE_COMMUNITY
); );
return DBA::toArray($stmtContacts); return DBA::toArray($stmtContacts);

View file

@ -92,19 +92,19 @@ class TagCloud
if ($flags) { if ($flags) {
if ($flags === 'wall') { if ($flags === 'wall') {
$sql_options .= ' AND `item`.`wall` '; $sql_options .= ' AND `post-view`.`wall` ';
} }
} }
if ($owner_id) { if ($owner_id) {
$sql_options .= ' AND `item`.`owner-id` = ' . intval($owner_id) . ' '; $sql_options .= ' AND `post-view`.`owner-id` = ' . intval($owner_id) . ' ';
} }
// Fetch tags // Fetch tags
$tag_stmt = DBA::p("SELECT `name`, COUNT(`name`) AS `total` FROM `tag-search-view` $tag_stmt = DBA::p("SELECT `name`, COUNT(`name`) AS `total` FROM `tag-search-view`
LEFT JOIN `item` ON `tag-search-view`.`uri-id` = `item`.`uri-id` LEFT JOIN `post-view` ON `tag-search-view`.`uri-id` = `post-view`.`uri-id`
WHERE `tag-search-view`.`uid` = ? WHERE `tag-search-view`.`uid` = ?
AND `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND `post-view`.`visible` AND NOT `post-view`.`deleted` AND NOT `post-view`.`moderated`
$sql_options $sql_options
GROUP BY `name` ORDER BY `total` DESC $limit", GROUP BY `name` ORDER BY `total` DESC $limit",
$uid $uid

View file

@ -22,9 +22,11 @@
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\App; use Friendica\App;
use Friendica\App\Mode;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\Strings; use Friendica\Util\Strings;
class Update class Update
@ -60,8 +62,24 @@ class Update
} }
// We don't support upgrading from very old versions anymore // We don't support upgrading from very old versions anymore
if ($build < NEW_UPDATE_ROUTINE_VERSION) { if ($build < NEW_TABLE_STRUCTURE_VERSION) {
die('You try to update from a version prior to database version 1170. The direct upgrade path is not supported. Please update to version 3.5.4 before updating to this version.'); $error = DI::l10n('Updates from version %s are not supported. Please update at least to version 2021,01 and wait until the postupdate finished version 1383.', $build);
if (DI::mode()->getExecutor() == Mode::INDEX) {
die($error);
} else {
throw new InternalServerErrorException($error);
}
}
// The postupdate has to completed version 1281 for the new post views to take over
$postupdate = DI::config()->get("system", "post_update_version");
if ($postupdate < NEW_TABLE_STRUCTURE_VERSION) {
$error = DI::l10n('Updates from postupdate version %s are not supported. Please update at least to version 2021,01 and wait until the postupdate finished version 1383.', $postupdate);
if (DI::mode()->getExecutor() == Mode::INDEX) {
die($error);
} else {
throw new InternalServerErrorException($error);
}
} }
if ($build < DB_UPDATE_VERSION) { if ($build < DB_UPDATE_VERSION) {

View file

@ -183,7 +183,7 @@ class DBA
/** /**
* Executes a prepared statement that returns data * Executes a prepared statement that returns data
* Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid); * Example: $r = p("SELECT * FROM `post` WHERE `guid` = ?", $guid);
* *
* Please only use it with complicated queries. * Please only use it with complicated queries.
* For all regular queries please use DBA::select or DBA::exists * For all regular queries please use DBA::select or DBA::exists

View file

@ -455,7 +455,7 @@ class Database
/** /**
* Executes a prepared statement that returns data * Executes a prepared statement that returns data
* *
* @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid); * @usage Example: $r = p("SELECT * FROM `post` WHERE `guid` = ?", $guid);
* *
* Please only use it with complicated queries. * Please only use it with complicated queries.
* For all regular queries please use DBA::select or DBA::exists * For all regular queries please use DBA::select or DBA::exists

View file

@ -27,9 +27,8 @@ use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GServer; use Friendica\Model\GServer;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\ItemURI;
use Friendica\Model\PermissionSet;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Model\Post\Category; use Friendica\Model\Post\Category;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\UserItem; use Friendica\Model\UserItem;
@ -53,18 +52,6 @@ class PostUpdate
*/ */
public static function update() public static function update()
{ {
if (!self::update1194()) {
return false;
}
if (!self::update1206()) {
return false;
}
if (!self::update1279()) {
return false;
}
if (!self::update1281()) {
return false;
}
if (!self::update1297()) { if (!self::update1297()) {
return false; return false;
} }
@ -105,352 +92,6 @@ class PostUpdate
return true; return true;
} }
/**
* Updates the "global" field in the item table
*
* @return bool "true" when the job is done
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function update1194()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1194) {
return true;
}
Logger::info("Start");
$end_id = DI::config()->get("system", "post_update_1194_end");
if (!$end_id) {
$r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");
if ($r) {
DI::config()->set("system", "post_update_1194_end", $r[0]["id"]);
$end_id = DI::config()->get("system", "post_update_1194_end");
}
}
Logger::info("End ID: ".$end_id);
$start_id = DI::config()->get("system", "post_update_1194_start");
$query1 = "SELECT `item`.`id` FROM `item` ";
$query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 ";
$query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d
AND `item`.`visible` AND NOT `item`.`private`
AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `item`.`network` IN ('%s', '%s', '%s', '')
AND NOT `item`.`global`";
$r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1",
intval($start_id), intval($end_id),
DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DIASPORA), DBA::escape(Protocol::OSTATUS));
if (!$r) {
DI::config()->set("system", "post_update_version", 1194);
Logger::info("Update is done");
return true;
} else {
DI::config()->set("system", "post_update_1194_start", $r[0]["id"]);
$start_id = DI::config()->get("system", "post_update_1194_start");
}
Logger::info("Start ID: ".$start_id);
$r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1000,1",
intval($start_id), intval($end_id),
DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DIASPORA), DBA::escape(Protocol::OSTATUS));
if ($r) {
$pos_id = $r[0]["id"];
} else {
$pos_id = $end_id;
}
Logger::info("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id);
q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3,
intval($start_id), intval($pos_id),
DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DIASPORA), DBA::escape(Protocol::OSTATUS));
Logger::info("Done");
}
/**
* update the "last-item" field in the "self" contact
*
* This field avoids cost intensive calls in the admin panel and in "nodeinfo"
*
* @return bool "true" when the job is done
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function update1206()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1206) {
return true;
}
Logger::info("Start");
$r = q("SELECT `contact`.`id`, `contact`.`last-item`,
(SELECT MAX(`changed`) FROM `item` USE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date`
FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`");
if (!DBA::isResult($r)) {
return false;
}
foreach ($r as $user) {
if (!empty($user["lastitem_date"]) && ($user["lastitem_date"] > $user["last-item"])) {
DBA::update('contact', ['last-item' => $user['lastitem_date']], ['id' => $user['id']]);
}
}
DI::config()->set("system", "post_update_version", 1206);
Logger::info("Done");
return true;
}
/**
* update the item related tables
*
* @return bool "true" when the job is done
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
private static function update1279()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1279) {
return true;
}
$id = DI::config()->get("system", "post_update_version_1279_id", 0);
Logger::info("Start from item " . $id);
$fields = array_merge(Item::MIXED_CONTENT_FIELDLIST, ['network', 'author-id', 'owner-id', 'tag', 'file',
'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'id',
'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'psid', 'post-type', 'bookmark', 'type',
'inform', 'postopts', 'icid']);
$start_id = $id;
$rows = 0;
$condition = ["`id` > ?", $id];
$params = ['order' => ['id'], 'limit' => 10000];
$items = Item::select($fields, $condition, $params);
if (DBA::errorNo() != 0) {
Logger::info('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
return false;
}
while ($item = Item::fetch($items)) {
$id = $item['id'];
if (empty($item['author-id'])) {
$default = ['url' => $item['author-link'], 'name' => $item['author-name'],
'photo' => $item['author-avatar'], 'network' => $item['network']];
$item['author-id'] = Contact::getIdForURL($item["author-link"], 0, null, $default);
}
if (empty($item['owner-id'])) {
$default = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
'photo' => $item['owner-avatar'], 'network' => $item['network']];
$item['owner-id'] = Contact::getIdForURL($item["owner-link"], 0, null, $default);
}
if (empty($item['psid'])) {
$item['psid'] = PermissionSet::getIdFromACL(
$item['uid'],
$item['allow_cid'],
$item['allow_gid'],
$item['deny_cid'],
$item['deny_gid']
);
}
$item['allow_cid'] = null;
$item['allow_gid'] = null;
$item['deny_cid'] = null;
$item['deny_gid'] = null;
if ($item['post-type'] == 0) {
if (!empty($item['type']) && ($item['type'] == 'note')) {
$item['post-type'] = Item::PT_PERSONAL_NOTE;
} elseif (!empty($item['type']) && ($item['type'] == 'photo')) {
$item['post-type'] = Item::PT_IMAGE;
} elseif (!empty($item['bookmark']) && $item['bookmark']) {
$item['post-type'] = Item::PT_PAGE;
}
}
self::createLanguage($item);
if (!empty($item['icid']) && !empty($item['language'])) {
DBA::update('item-content', ['language' => $item['language']], ['id' => $item['icid']]);
}
unset($item['language']);
Item::update($item, ['id' => $id]);
++$rows;
}
DBA::close($items);
DI::config()->set("system", "post_update_version_1279_id", $id);
Logger::info("Processed rows: " . $rows . " - last processed item: " . $id);
if ($start_id == $id) {
// Set all deprecated fields to "null" if they contain an empty string
$nullfields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'postopts', 'inform', 'type',
'bookmark', 'file', 'location', 'coord', 'tag', 'plink', 'title', 'content-warning',
'body', 'app', 'verb', 'object-type', 'object', 'target-type', 'target',
'author-name', 'author-link', 'author-avatar', 'owner-name', 'owner-link', 'owner-avatar',
'rendered-hash', 'rendered-html'];
foreach ($nullfields as $field) {
$fields = [$field => null];
$condition = [$field => ''];
Logger::info("Setting '" . $field . "' to null if empty.");
// Important: This has to be a "DBA::update", not a "Item::update"
DBA::update('item', $fields, $condition);
}
DI::config()->set("system", "post_update_version", 1279);
Logger::info("Done");
return true;
}
return false;
}
private static function createLanguage(&$item)
{
if (empty($item['postopts'])) {
return;
}
$opts = explode(',', $item['postopts']);
$postopts = [];
foreach ($opts as $opt) {
if (strstr($opt, 'lang=')) {
$language = substr($opt, 5);
} else {
$postopts[] = $opt;
}
}
if (empty($language)) {
return;
}
if (!empty($postopts)) {
$item['postopts'] = implode(',', $postopts);
} else {
$item['postopts'] = null;
}
$lang_pairs = explode(':', $language);
$lang_arr = [];
foreach ($lang_pairs as $pair) {
$lang_pair_arr = explode(';', $pair);
if (count($lang_pair_arr) == 2) {
$lang_arr[$lang_pair_arr[0]] = $lang_pair_arr[1];
}
}
$item['language'] = json_encode($lang_arr);
}
/**
* update item-uri data. Prerequisite for the next item structure update.
*
* @return bool "true" when the job is done
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function update1281()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1281) {
return true;
}
$id = DI::config()->get("system", "post_update_version_1281_id", 0);
Logger::info("Start from item " . $id);
$fields = ['id', 'guid', 'uri', 'uri-id', 'parent-uri', 'parent-uri-id', 'thr-parent', 'thr-parent-id'];
$start_id = $id;
$rows = 0;
$condition = ["`id` > ?", $id];
$params = ['order' => ['id'], 'limit' => 10000];
$items = DBA::select('item', $fields, $condition, $params);
if (DBA::errorNo() != 0) {
Logger::info('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
return false;
}
while ($item = DBA::fetch($items)) {
$id = $item['id'];
if (empty($item['uri'])) {
// Should not happen
continue;
} elseif (empty($item['uri-id'])) {
$item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
}
if (empty($item['parent-uri'])) {
$item['parent-uri-id'] = $item['uri-id'];
} elseif (empty($item['parent-uri-id'])) {
$item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
}
// Very old items don't have this field
if (empty($item['thr-parent'])) {
$item['thr-parent-id'] = $item['parent-uri-id'];
} elseif (empty($item['thr-parent-id'])) {
$item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
}
unset($item['id']);
unset($item['guid']);
unset($item['uri']);
unset($item['parent-uri']);
unset($item['thr-parent']);
DBA::update('item', $item, ['id' => $id]);
++$rows;
}
DBA::close($items);
DI::config()->set("system", "post_update_version_1281_id", $id);
Logger::info("Processed rows: " . $rows . " - last processed item: " . $id);
if ($start_id == $id) {
Logger::info("Updating item-uri in item-activity");
DBA::e("UPDATE `item-activity` INNER JOIN `item-uri` ON `item-uri`.`uri` = `item-activity`.`uri` SET `item-activity`.`uri-id` = `item-uri`.`id` WHERE `item-activity`.`uri-id` IS NULL");
Logger::info("Updating item-uri in item-content");
DBA::e("UPDATE `item-content` INNER JOIN `item-uri` ON `item-uri`.`uri` = `item-content`.`uri` SET `item-content`.`uri-id` = `item-uri`.`id` WHERE `item-content`.`uri-id` IS NULL");
DI::config()->set("system", "post_update_version", 1281);
Logger::info("Done");
return true;
}
return false;
}
/** /**
* Set the delivery queue count to a negative value for all items preceding the feature. * Set the delivery queue count to a negative value for all items preceding the feature.
* *
@ -822,7 +463,7 @@ class PostUpdate
} }
while ($term = DBA::fetch($terms)) { while ($term = DBA::fetch($terms)) {
$item = Item::selectFirst(['uri-id', 'uid'], ['id' => $term['oid']]); $item = Post::selectFirst(['uri-id', 'uid'], ['id' => $term['oid']]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
continue; continue;
} }

View file

@ -302,11 +302,7 @@ class Notification extends BaseFactory
*/ */
public function getPersonalList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT) public function getPersonalList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT)
{ {
$myUrl = str_replace('http://', '', $this->nurl); $condition = ["NOT `wall` AND `uid` = ? AND `author-id` = ?", local_user(), public_contact()];
$diaspUrl = str_replace('/profile/', '/u/', $myUrl);
$condition = ["NOT `wall` AND `uid` = ? AND (`item`.`author-id` = ? OR `item`.`tag` REGEXP ? OR `item`.`tag` REGEXP ?)",
local_user(), public_contact(), $myUrl . '\\]', $diaspUrl . '\\]'];
if (!$seen) { if (!$seen) {
$condition[0] .= " AND `unseen`"; $condition[0] .= " AND `unseen`";

View file

@ -513,15 +513,13 @@ class Event
} }
// Query for the event by event id // Query for the event by event id
$r = q("SELECT `event`.*, `item`.`id` AS `itemid` FROM `event` $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-view`.`id` AS `itemid` FROM `event`
LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid` LEFT JOIN `post-view` ON `post-view`.`event-id` = `event`.`id` AND `post-view`.`uid` = `event`.`uid`
WHERE `event`.`uid` = %d AND `event`.`id` = %d $sql_extra", WHERE `event`.`uid` = %d AND `event`.`id` = %d $sql_extra",
intval($owner_uid), $owner_uid, $event_id));
intval($event_id)
);
if (DBA::isResult($r)) { if (DBA::isResult($events)) {
$return = self::removeDuplicates($r); $return = self::removeDuplicates($events);
} }
return $return; return $return;
@ -554,24 +552,17 @@ class Event
// Query for the event by date. // Query for the event by date.
// @todo Slow query (518 seconds to run), to be optimzed // @todo Slow query (518 seconds to run), to be optimzed
$r = q("SELECT `event`.*, `item`.`id` AS `itemid` FROM `event` $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-view`.`id` AS `itemid` FROM `event`
LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid` LEFT JOIN `post-view` ON `post-view`.`event-id` = `event`.`id` AND `post-view`.`uid` = `event`.`uid`
WHERE `event`.`uid` = %d AND event.ignore = %d WHERE `event`.`uid` = ? AND `event`.`ignore` = ?
AND ((`adjust` = 0 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s') AND ((NOT `adjust` AND (`finish` >= ? OR (`nofinish` AND `start` >= ?)) AND `start` <= ?)
OR (`adjust` = 1 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s')) OR (`adjust` AND (`finish` >= ? OR (`nofinish` AND `start` >= ?)) AND `start` <= ?))" . $sql_extra,
$sql_extra ", $owner_uid, $event_params["ignore"],
intval($owner_uid), $event_params["start"], $event_params["start"], $event_params["finish"],
intval($event_params["ignore"]), $event_params["adjust_start"], $event_params["adjust_start"], $event_params["adjust_finish"]));
DBA::escape($event_params["start"]),
DBA::escape($event_params["start"]),
DBA::escape($event_params["finish"]),
DBA::escape($event_params["adjust_start"]),
DBA::escape($event_params["adjust_start"]),
DBA::escape($event_params["adjust_finish"])
);
if (DBA::isResult($r)) { if (DBA::isResult($events)) {
$return = self::removeDuplicates($r); $return = self::removeDuplicates($events);
} }
return $return; return $return;

View file

@ -160,7 +160,7 @@ class Group
public static function countUnseen() public static function countUnseen()
{ {
$stmt = DBA::p("SELECT `group`.`id`, `group`.`name`, $stmt = DBA::p("SELECT `group`.`id`, `group`.`name`,
(SELECT COUNT(*) FROM `item` FORCE INDEX (`uid_unseen_contactid`) (SELECT COUNT(*) FROM `post-view`
WHERE `uid` = ? WHERE `uid` = ?
AND `unseen` AND `unseen`
AND `contact-id` IN AND `contact-id` IN

View file

@ -148,15 +148,6 @@ class Item
return $postfields; return $postfields;
} }
public static function isLegacyMode()
{
if (is_null(self::$legacy_mode)) {
self::$legacy_mode = (DI::config()->get("system", "post_update_version") < 1279);
}
return self::$legacy_mode;
}
/** /**
* Set the pinned state of an item * Set the pinned state of an item
* *
@ -226,7 +217,7 @@ class Item
* @return array|false current row or false * @return array|false current row or false
* @throws \Exception * @throws \Exception
*/ */
public static function fetch($stmt) private static function fetch($stmt)
{ {
$row = DBA::fetch($stmt); $row = DBA::fetch($stmt);
@ -267,17 +258,6 @@ class Item
// ---------------------- Transform item content data ---------------------- // ---------------------- Transform item content data ----------------------
// Fetch data from the item-content table whenever there is content there
if (self::isLegacyMode()) {
$legacy_fields = array_merge(Post\DeliveryData::LEGACY_FIELD_LIST, self::MIXED_CONTENT_FIELDLIST);
foreach ($legacy_fields as $field) {
if (empty($row[$field]) && !empty($row['internal-item-' . $field])) {
$row[$field] = $row['internal-item-' . $field];
}
unset($row['internal-item-' . $field]);
}
}
if (array_key_exists('verb', $row)) { if (array_key_exists('verb', $row)) {
if (!is_null($row['internal-verb'])) { if (!is_null($row['internal-verb'])) {
$row['verb'] = $row['internal-verb']; $row['verb'] = $row['internal-verb'];
@ -390,53 +370,6 @@ class Item
return $retval; return $retval;
} }
/**
* Select rows from the item table 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 = [])
{
$params['uid'] = $uid;
if (empty($selected)) {
$selected = self::DISPLAY_FIELDLIST;
}
return self::select($selected, $condition, $params);
}
/**
* Retrieve a single record from the item table and returns it in an associative array
*
* @param array $fields
* @param array $condition
* @param array $params
* @return bool|array
* @throws \Exception
* @see DBA::select
*/
public static function selectFirst(array $fields = [], array $condition = [], $params = [])
{
$params['limit'] = 1;
$result = self::select($fields, $condition, $params);
if (is_bool($result)) {
return $result;
} else {
$row = self::fetch($result);
DBA::close($result);
return $row;
}
}
/** /**
* Select rows from the item table and returns them as an array * Select rows from the item table and returns them as an array
* *
@ -830,9 +763,6 @@ class Item
foreach ($fields as $table => $table_fields) { foreach ($fields as $table => $table_fields) {
foreach ($table_fields as $field => $select) { foreach ($table_fields as $field => $select) {
if (empty($selected) || in_array($select, $selected)) { if (empty($selected) || in_array($select, $selected)) {
if (self::isLegacyMode() && in_array($select, $legacy_fields)) {
$selection[] = "`item`.`".$select."` AS `internal-item-" . $select . "`";
}
if (is_int($field)) { if (is_int($field)) {
$selection[] = "`" . $table . "`.`" . $select . "`"; $selection[] = "`" . $table . "`.`" . $select . "`";
} else { } else {
@ -904,7 +834,7 @@ class Item
foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) { foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) {
if (isset($fields[$field])) { if (isset($fields[$field])) {
$content_fields[$field] = $fields[$field]; $content_fields[$field] = $fields[$field];
if (in_array($field, self::CONTENT_FIELDLIST) || !self::isLegacyMode()) { if (in_array($field, self::CONTENT_FIELDLIST)) {
unset($fields[$field]); unset($fields[$field]);
} else { } else {
$fields[$field] = null; $fields[$field] = null;
@ -965,14 +895,6 @@ class Item
$item_content = DBA::selectFirst('item-content', [], ['uri-id' => $item['uri-id']]); $item_content = DBA::selectFirst('item-content', [], ['uri-id' => $item['uri-id']]);
if (DBA::isResult($item_content)) { if (DBA::isResult($item_content)) {
$item_fields = ['icid' => $item_content['id']]; $item_fields = ['icid' => $item_content['id']];
// Clear all fields in the item table that have a content in the item-content table
if (self::isLegacyMode()) {
foreach ($item_content as $field => $content) {
if (in_array($field, self::MIXED_CONTENT_FIELDLIST) && !empty($content)) {
$item_fields[$field] = null;
}
}
}
DBA::update('item', $item_fields, ['id' => $item['id']]); DBA::update('item', $item_fields, ['id' => $item['id']]);
} }
} }

View file

@ -43,7 +43,7 @@ class ItemContent
{ {
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE)) $condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE))
AND (NOT `private` OR (`private` AND `uid` = ?)) AND (NOT `private` OR (`private` AND `uid` = ?))
AND `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `network` IN (?, ?, ?, ?))", AND `uri-id` IN (SELECT `uri-id` FROM `post-view` WHERE `network` IN (?, ?, ?, ?))",
$search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; $search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
if (!empty($last_uriid)) { if (!empty($last_uriid)) {
@ -71,7 +71,7 @@ class ItemContent
{ {
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE)) $condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE))
AND (NOT `private` OR (`private` AND `uid` = ?)) AND (NOT `private` OR (`private` AND `uid` = ?))
AND `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `network` IN (?, ?, ?, ?))", AND `uri-id` IN (SELECT `uri-id` FROM `post-view` WHERE `network` IN (?, ?, ?, ?))",
$search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; $search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
return Post::count($condition); return Post::count($condition);
} }

View file

@ -60,7 +60,7 @@ class Nodeinfo
$logger->debug('user statistics', $userStats); $logger->debug('user statistics', $userStats);
$items = DBA::p("SELECT COUNT(*) AS `total`, `gravity` FROM `item` WHERE `origin` AND NOT `deleted` AND `uid` != 0 AND `gravity` IN (?, ?) GROUP BY `gravity`", $items = DBA::p("SELECT COUNT(*) AS `total`, `gravity` FROM `post-view` WHERE `origin` AND NOT `deleted` AND `uid` != 0 AND `gravity` IN (?, ?) GROUP BY `gravity`",
GRAVITY_PARENT, GRAVITY_COMMENT); GRAVITY_PARENT, GRAVITY_COMMENT);
while ($item = DBA::fetch($items)) { while ($item = DBA::fetch($items)) {
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == GRAVITY_PARENT) {

View file

@ -43,7 +43,7 @@ use Psr\Log\LoggerInterface;
* @property integer parent Parent Item Id * @property integer parent Parent Item Id
* @property boolean seen Whether the notification was read or not. * @property boolean seen Whether the notification was read or not.
* @property string verb Verb URL (@see http://activitystrea.ms) * @property string verb Verb URL (@see http://activitystrea.ms)
* @property string otype Subject type (`item`, `intro` or `mail`) * @property string otype Subject type ('item', 'intro' or 'mail')
* *
* @property-read string name_cache Full name of the contact subject * @property-read string name_cache Full name of the contact subject
* @property-read string msg_cache Plaintext version of the notification text with a placeholder (`{0}`) for the subject contact's name. * @property-read string msg_cache Plaintext version of the notification text with a placeholder (`{0}`) for the subject contact's name.

View file

@ -452,7 +452,7 @@ class Tag
public static function countByTag(string $search, int $uid = 0) public static function countByTag(string $search, int $uid = 0)
{ {
$condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?)) $condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))
AND `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `network` IN (?, ?, ?, ?))", AND `uri-id` IN (SELECT `uri-id` FROM `post-view` WHERE `network` IN (?, ?, ?, ?))",
$search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; $search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
$params = ['group_by' => ['uri-id']]; $params = ['group_by' => ['uri-id']];
@ -472,7 +472,7 @@ class Tag
public static function getURIIdListByTag(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0) public static function getURIIdListByTag(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0)
{ {
$condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?)) $condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))
AND `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `network` IN (?, ?, ?, ?))", AND `uri-id` IN (SELECT `uri-id` FROM `post-view` WHERE `network` IN (?, ?, ?, ?))",
$search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; $search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
if (!empty($last_uriid)) { if (!empty($last_uriid)) {

View file

@ -72,9 +72,8 @@ class UserItem
// Add every user who participated so far in this thread // Add every user who participated so far in this thread
// This can only happen with participations on global items. (means: uid = 0) // This can only happen with participations on global items. (means: uid = 0)
$users = DBA::p("SELECT DISTINCT(`contact`.`uid`) FROM `item` $users = DBA::p("SELECT DISTINCT(`contact-uid`) AS `uid` FROM `post-view`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` != 0 WHERE `contact-uid` != 0 AND `parent` IN (SELECT `parent` FROM `post-view` WHERE `id` = ?)", $iid);
WHERE `parent` IN (SELECT `parent` FROM `item` WHERE `id`=?)", $iid);
while ($user = DBA::fetch($users)) { while ($user = DBA::fetch($users)) {
$uids[] = $user['uid']; $uids[] = $user['uid'];
} }

View file

@ -62,11 +62,11 @@ class PublicTimeline extends BaseApi
'uid' => 0, 'network' => Protocol::FEDERATED]; 'uid' => 0, 'network' => Protocol::FEDERATED];
if ($local) { if ($local) {
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `item` WHERE `origin`)"]); $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-view` WHERE `origin`)"]);
} }
if ($remote) { if ($remote) {
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `origin`)"]); $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-view` WHERE `origin`)"]);
} }
if (!empty($max_id)) { if (!empty($max_id)) {

View file

@ -181,7 +181,7 @@ class Status extends BaseProfile
$condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR $condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
(`gravity` = ? AND `vid` = ? AND `origin` AND `thr-parent-id` IN (`gravity` = ? AND `vid` = ? AND `origin` AND `thr-parent-id` IN
(SELECT `uri-id` FROM `item` AS `i` (SELECT `uri-id` FROM `post-view` AS `i`
WHERE `gravity` = ? AND `network` IN (?, ?, ?, ?) AND `uid` IN (?, ?) WHERE `gravity` = ? AND `network` IN (?, ?, ?, ?) AND `uid` IN (?, ?)
AND `i`.`uri-id` = `thr-parent-id`)))", AND `i`.`uri-id` = `thr-parent-id`)))",
GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT, GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT,

View file

@ -71,27 +71,18 @@ class Profile extends BaseModule
// If the page user is the owner of the page we should query for unseen // If the page user is the owner of the page we should query for unseen
// items. Otherwise use a timestamp of the last succesful update request. // items. Otherwise use a timestamp of the last succesful update request.
if ($is_owner || !$last_updated) { if ($is_owner || !$last_updated) {
$sql_extra4 = " AND `item`.`unseen`"; $sql_extra4 = " AND `unseen`";
} else { } else {
$gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated); $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
$sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'"; $sql_extra4 = " AND `received` > '" . $gmupdate . "'";
} }
$items_stmt = DBA::p( $items_stmt = DBA::p(
"SELECT DISTINCT(`parent-uri`) AS `uri`, `item`.`created` "SELECT DISTINCT(`parent-uri`) AS `uri`, `created` FROM `post-view`
FROM `item` WHERE `uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
INNER JOIN `contact` AND `visible` AND (NOT `deleted` OR `gravity` = ?)
ON `contact`.`id` = `item`.`contact-id` AND NOT `moderated` AND `wall` $sql_extra4 $sql_extra
AND NOT `contact`.`blocked` ORDER BY `received` DESC",
AND NOT `contact`.`pending`
WHERE `item`.`uid` = ?
AND `item`.`visible`
AND (NOT `item`.`deleted` OR `item`.`gravity` = ?)
AND NOT `item`.`moderated`
AND `item`.`wall`
$sql_extra4
$sql_extra
ORDER BY `item`.`received` DESC",
$a->profile['uid'], $a->profile['uid'],
GRAVITY_ACTIVITY GRAVITY_ACTIVITY
); );

View file

@ -63,7 +63,7 @@ class Notification extends BaseEntity
protected $seen; protected $seen;
/** @var string Verb URL @see http://activitystrea.ms */ /** @var string Verb URL @see http://activitystrea.ms */
protected $verb; protected $verb;
/** @var string Subject type (`item`, `intro` or `mail`) */ /** @var string Subject type ('item', 'intro' or 'mail') */
protected $otype; protected $otype;
/** @var string Full name of the contact subject (HTML) */ /** @var string Full name of the contact subject (HTML) */
protected $name_cache; protected $name_cache;

View file

@ -184,7 +184,7 @@ class DFRN
// default permissions - anonymous user // default permissions - anonymous user
$sql_extra = sprintf(" AND `item`.`private` != %s ", Item::PRIVATE); $sql_extra = sprintf(" AND `private` != %s ", Item::PRIVATE);
$owner = DBA::selectFirst('owner-view', [], ['nickname' => $owner_nick]); $owner = DBA::selectFirst('owner-view', [], ['nickname' => $owner_nick]);
if (!DBA::isResult($owner)) { if (!DBA::isResult($owner)) {
@ -194,9 +194,7 @@ class DFRN
$owner_id = $owner['uid']; $owner_id = $owner['uid'];
$sql_post_table = ""; if (!$public_feed) {
if (! $public_feed) {
switch ($direction) { switch ($direction) {
case (-1): case (-1):
$sql_extra = sprintf(" AND `issued-id` = '%s' ", DBA::escape($dfrn_id)); $sql_extra = sprintf(" AND `issued-id` = '%s' ", DBA::escape($dfrn_id));
@ -212,71 +210,41 @@ class DFRN
break; // NOTREACHED break; // NOTREACHED
} }
$r = q( $contact = DBA::selectFirst('contact', [], ["NOT `blocked` AND `contact`.`uid` = ?" . $sql_extra, $owner_id]);
"SELECT * FROM `contact` WHERE NOT `blocked` AND `contact`.`uid` = %d $sql_extra LIMIT 1", if (!DBA::isResult($contact)) {
intval($owner_id) Logger::notice('No contact found', ['uid' => $owner_id]);
);
if (! DBA::isResult($r)) {
Logger::log(sprintf('No contact found for uid=%d', $owner_id), Logger::WARNING);
exit(); exit();
} }
$contact = $r[0];
$set = PermissionSet::get($owner_id, $contact['id']); $set = PermissionSet::get($owner_id, $contact['id']);
if (!empty($set)) { if (!empty($set)) {
$sql_extra = " AND `item`.`psid` IN (" . implode(',', $set) .")"; $sql_extra = " AND `psid` IN (" . implode(',', $set) .")";
} else { } else {
$sql_extra = sprintf(" AND `item`.`private` != %s", Item::PRIVATE); $sql_extra = sprintf(" AND `private` != %s", Item::PRIVATE);
} }
} }
if ($public_feed) { if (!strlen($last_update)) {
$sort = 'DESC';
} else {
$sort = 'ASC';
}
if (! strlen($last_update)) {
$last_update = 'now -30 days'; $last_update = 'now -30 days';
} }
if (isset($category)) { if (isset($category)) {
$sql_post_table = sprintf("INNER JOIN (SELECT `uri-id` FROM `category-view` WHERE `name` = '%s' AND `type` = %d AND `uid` = %d ORDER BY `uri-id` DESC) AS `category` ON `item`.`uri-id` = `category`.`uri-id` ", $sql_extra .= sprintf(" AND `uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = '%s' AND `type` = %d AND `uid` = %d)",
DBA::escape(Strings::protectSprintf($category)), intval(Category::CATEGORY), intval($owner_id)); DBA::escape(Strings::protectSprintf($category)), intval(Category::CATEGORY), intval($owner_id));
} }
if ($public_feed && ! $converse) { if ($public_feed && ! $converse) {
$sql_extra .= " AND `contact`.`self` = 1 "; $sql_extra .= " AND `self` ";
} }
$check_date = DateTimeFormat::utc($last_update); $check_date = DateTimeFormat::utc($last_update);
$r = q( $condition = ["`uid` = ? AND `wall` AND `changed` > ? AND `vid` != ? AND `visible`" . $sql_extra,
"SELECT `item`.`id` $owner_id, $check_date, Verb::getID(Activity::ANNOUNCE)];
FROM `item` USE INDEX (`uid_wall_changed`) $sql_post_table
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`wall` AND `item`.`changed` > '%s'
AND `vid` != %d AND `item`.`visible` $sql_extra
ORDER BY `item`.`parent` ".$sort.", `item`.`received` ASC LIMIT 0, 300",
intval($owner_id),
DBA::escape($check_date),
Verb::getID(Activity::ANNOUNCE),
DBA::escape($sort)
);
$ids = []; $params = ['sort' => ['parent' => $public_feed, 'received']];
foreach ($r as $item) { $items = Post::selectToArray(Item::DELIVER_FIELDLIST, $condition, $params, ['limit' => 300]);
$ids[] = $item['id'];
}
if (!empty($ids)) {
$items = Post::selectToArray(Item::DELIVER_FIELDLIST, ['id' => $ids]);
} else {
$items = [];
}
/* /*
* Will check further below if this actually returned results. * Will check further below if this actually returned results.
@ -1924,32 +1892,15 @@ class DFRN
$community = true; $community = true;
Logger::log("possible community action"); Logger::log("possible community action");
} else { } else {
$sql_extra = " AND `contact`.`self` AND `item`.`wall` "; $sql_extra = " AND `self` AND `wall`";
} }
// was the top-level post for this action written by somebody on this site? // was the top-level post for this action written by somebody on this site?
// Specifically, the recipient? // Specifically, the recipient?
$parent = Post::selectFirst(['forum_mode', 'wall'],
["`uri` = ? AND `uid` = ?" . $sql_extra, $item["thr-parent"], $importer["importer_uid"]]);
$is_a_remote_action = false; $is_a_remote_action = DBA::isResult($parent);
$parent = Post::selectFirst(['thr-parent'], ['uri' => $item["thr-parent"]]);
if (DBA::isResult($parent)) {
$r = q(
"SELECT `item`.`forum_mode`, `item`.`wall` FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uri` = '%s' AND (`item`.`thr-parent` = '%s' OR `item`.`thr-parent` = '%s')
AND `item`.`uid` = %d
$sql_extra
LIMIT 1",
DBA::escape($parent["thr-parent"]),
DBA::escape($parent["thr-parent"]),
DBA::escape($parent["thr-parent"]),
intval($importer["importer_uid"])
);
if (DBA::isResult($r)) {
$is_a_remote_action = true;
}
}
/* /*
* Does this have the characteristics of a community or private group action? * Does this have the characteristics of a community or private group action?
@ -1957,7 +1908,7 @@ class DFRN
* valid community action. Also forum_mode makes it valid for sure. * valid community action. Also forum_mode makes it valid for sure.
* If neither, it's not. * If neither, it's not.
*/ */
if ($is_a_remote_action && $community && (!$r[0]["forum_mode"]) && (!$r[0]["wall"])) { if ($is_a_remote_action && $community && (!$parent["forum_mode"]) && (!$parent["wall"])) {
$is_a_remote_action = false; $is_a_remote_action = false;
Logger::log("not a community action"); Logger::log("not a community action");
} }

View file

@ -55,7 +55,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1388); define('DB_UPDATE_VERSION', 1389);
} }
return [ return [

View file

@ -106,10 +106,13 @@
"contact-avatar" => ["contact", "thumb"], "contact-avatar" => ["contact", "thumb"],
"contact-network" => ["contact", "network"], "contact-network" => ["contact", "network"],
"contact-blocked" => ["contact", "blocked"], "contact-blocked" => ["contact", "blocked"],
"contact-hidden" => ["contact", "hidden"],
"contact-readonly" => ["contact", "readonly"], "contact-readonly" => ["contact", "readonly"],
"contact-archive" => ["contact", "archive"],
"contact-pending" => ["contact", "pending"], "contact-pending" => ["contact", "pending"],
"contact-rel" => ["contact", "rel"], "contact-rel" => ["contact", "rel"],
"contact-uid" => ["contact", "uid"], "contact-uid" => ["contact", "uid"],
"contact-contact-type" => ["contact", "contact-type"],
"writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)",
"self" => ["contact", "self"], "self" => ["contact", "self"],
"cid" => ["contact", "id"], "cid" => ["contact", "id"],

View file

@ -58,7 +58,6 @@ class StaticDatabase extends Database
$this->connection = self::$staticConnection; $this->connection = self::$staticConnection;
$this->connected = true; $this->connected = true;
$this->emulate_prepares = false; $this->emulate_prepares = false;
$this->pdo_emulate_prepares = false;
return $this->connected; return $this->connected;
} }

View file

@ -179,6 +179,50 @@ return [
'guid' => '6', 'guid' => '6',
], ],
], ],
'item-content' => [
[
'id' => 1,
'uri-id' => 1,
'uri-plink-hash' => '1',
'body' => 'Parent status',
'plink' => 'http://localhost/display/1',
],
[
'id' => 2,
'uri-id' => 2,
'uri-plink-hash' => '2',
'body' => 'Reply',
'plink' => 'http://localhost/display/2',
],
[
'id' => 3,
'uri-id' => 3,
'uri-plink-hash' => '3',
'body' => 'Other user status',
'plink' => 'http://localhost/display/3',
],
[
'id' => 4,
'uri-id' => 4,
'uri-plink-hash' => '4',
'body' => 'Friend user reply',
'plink' => 'http://localhost/display/4',
],
[
'id' => 5,
'uri-id' => 5,
'uri-plink-hash' => '5',
'body' => '[share]Shared status[/share]',
'plink' => 'http://localhost/display/5',
],
[
'id' => 6,
'uri-id' => 6,
'uri-plink-hash' => '6',
'body' => 'Friend user status',
'plink' => 'http://localhost/display/6',
],
],
'item' => [ 'item' => [
[ [
'id' => 1, 'id' => 1,
@ -191,7 +235,6 @@ return [
'uid' => 42, 'uid' => 42,
'verb' => 'http://activitystrea.ms/schema/1.0/post', 'verb' => 'http://activitystrea.ms/schema/1.0/post',
'unseen' => 1, 'unseen' => 1,
'body' => 'Parent status',
'parent' => 1, 'parent' => 1,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
@ -205,7 +248,6 @@ return [
'deny_cid' => '', 'deny_cid' => '',
'deny_gid' => '', 'deny_gid' => '',
'guid' => '1', 'guid' => '1',
'plink' => 'http://localhost/display/1',
], ],
[ [
'id' => 2, 'id' => 2,
@ -218,7 +260,6 @@ return [
'uid' => 42, 'uid' => 42,
'verb' => 'http://activitystrea.ms/schema/1.0/post', 'verb' => 'http://activitystrea.ms/schema/1.0/post',
'unseen' => 0, 'unseen' => 0,
'body' => 'Reply',
'parent' => 1, 'parent' => 1,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
@ -228,10 +269,8 @@ return [
'starred' => 0, 'starred' => 0,
'origin' => 1, 'origin' => 1,
'guid' => '2', 'guid' => '2',
'plink' => 'http://localhost/display/2',
], ],
[ [
'id' => 3, 'id' => 3,
'uri-id' => 3, 'uri-id' => 3,
'visible' => 1, 'visible' => 1,
@ -242,7 +281,6 @@ return [
'uid' => 42, 'uid' => 42,
'verb' => 'http://activitystrea.ms/schema/1.0/post', 'verb' => 'http://activitystrea.ms/schema/1.0/post',
'unseen' => 0, 'unseen' => 0,
'body' => 'Other user status',
'parent' => 3, 'parent' => 3,
'parent-uri-id' => 3, 'parent-uri-id' => 3,
'thr-parent-id' => 3, 'thr-parent-id' => 3,
@ -252,7 +290,6 @@ return [
'starred' => 0, 'starred' => 0,
'origin' => 1, 'origin' => 1,
'guid' => '3', 'guid' => '3',
'plink' => 'http://localhost/display/3',
], ],
[ [
'id' => 4, 'id' => 4,
@ -275,7 +312,6 @@ return [
'starred' => 0, 'starred' => 0,
'origin' => 1, 'origin' => 1,
'guid' => '4', 'guid' => '4',
'plink' => 'http://localhost/display/4',
], ],
[ [
@ -289,7 +325,6 @@ return [
'uid' => 42, 'uid' => 42,
'verb' => 'http://activitystrea.ms/schema/1.0/post', 'verb' => 'http://activitystrea.ms/schema/1.0/post',
'unseen' => 0, 'unseen' => 0,
'body' => '[share]Shared status[/share]',
'parent' => 1, 'parent' => 1,
'parent-uri-id' => 1, 'parent-uri-id' => 1,
'thr-parent-id' => 1, 'thr-parent-id' => 1,
@ -303,7 +338,6 @@ return [
'deny_cid' => '', 'deny_cid' => '',
'deny_gid' => '', 'deny_gid' => '',
'guid' => '5', 'guid' => '5',
'plink' => 'http://localhost/display/5',
], ],
[ [
'id' => 6, 'id' => 6,
@ -316,7 +350,6 @@ return [
'uid' => 42, 'uid' => 42,
'verb' => 'http://activitystrea.ms/schema/1.0/post', 'verb' => 'http://activitystrea.ms/schema/1.0/post',
'unseen' => 0, 'unseen' => 0,
'body' => 'Friend user status',
'parent' => 6, 'parent' => 6,
'parent-uri-id' => 6, 'parent-uri-id' => 6,
'thr-parent-id' => 6, 'thr-parent-id' => 6,
@ -326,7 +359,6 @@ return [
'starred' => 0, 'starred' => 0,
'origin' => 1, 'origin' => 1,
'guid' => '6', 'guid' => '6',
'plink' => 'http://localhost/display/6',
], ],
], ],
'notify' => [ 'notify' => [

View file

@ -12,7 +12,6 @@ return [
'password' => 'testpw', 'password' => 'testpw',
'database' => 'testdb', 'database' => 'testdb',
'charset' => 'utf8mb4', 'charset' => 'utf8mb4',
'pdo_emulate_prepares' => true,
], ],
'config' => [ 'config' => [

View file

@ -12,7 +12,6 @@ return [
'password' => 'testpw', 'password' => 'testpw',
'database' => 'testdb', 'database' => 'testdb',
'charset' => 'utf8mb4', 'charset' => 'utf8mb4',
'pdo_emulate_prepares' => true,
], ],
'config' => [ 'config' => [

View file

@ -447,7 +447,7 @@ return [
'password' => '{$conf('database', 'password')}', 'password' => '{$conf('database', 'password')}',
'database' => '{$conf('database', 'database')}', 'database' => '{$conf('database', 'database')}',
'charset' => 'utf8mb4', 'charset' => 'utf8mb4',
'pdo_emulate_prepares' => true, 'pdo_emulate_prepares' => false,
], ],
// **************************************************************** // ****************************************************************

View file

@ -53,227 +53,9 @@ use Friendica\Model\Item;
use Friendica\Model\Notify; use Friendica\Model\Notify;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Model\Storage; use Friendica\Model\Storage;
use Friendica\Util\DateTimeFormat;
use Friendica\Worker\Delivery; use Friendica\Worker\Delivery;
function update_1179()
{
if (DI::config()->get('system', 'no_community_page')) {
DI::config()->set('system', 'community_page_style', CP_NO_COMMUNITY_PAGE);
}
// Update the central item storage with uid=0
Worker::add(PRIORITY_LOW, "threadupdate");
return Update::SUCCESS;
}
function update_1181()
{
// Fill the new fields in the term table.
// deactivated, the "term" table is deprecated
// Worker::add(PRIORITY_LOW, "TagUpdate");
return Update::SUCCESS;
}
function update_1189()
{
if (strlen(DI::config()->get('system', 'directory_submit_url')) &&
!strlen(DI::config()->get('system', 'directory'))) {
DI::config()->set('system', 'directory', dirname(DI::config()->get('system', 'directory_submit_url')));
DI::config()->delete('system', 'directory_submit_url');
}
return Update::SUCCESS;
}
function update_1191()
{
DI::config()->set('system', 'maintenance', 1);
if (Addon::isEnabled('forumlist')) {
Addon::uninstall('forumlist');
}
// select old formlist addon entries
$r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
DBA::escape('forumlist')
);
// convert old forumlist addon entries in new config entries
if (DBA::isResult($r)) {
foreach ($r as $rr) {
$uid = $rr['uid'];
$family = $rr['cat'];
$key = $rr['k'];
$value = $rr['v'];
if ($key === 'randomise') {
DI::pConfig()->delete($uid, $family, $key);
}
if ($key === 'show_on_profile') {
if ($value) {
DI::pConfig()->set($uid, 'feature', 'forumlist_profile', $value);
}
DI::pConfig()->delete($uid, $family, $key);
}
if ($key === 'show_on_network') {
if ($value) {
DI::pConfig()->set($uid, 'feature', 'forumlist_widget', $value);
}
DI::pConfig()->delete($uid, $family, $key);
}
}
}
DI::config()->set('system', 'maintenance', 0);
return Update::SUCCESS;
}
function update_1203()
{
$r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
DBA::escape(User::ACCOUNT_TYPE_COMMUNITY),
DBA::escape(User::PAGE_FLAGS_COMMUNITY),
DBA::escape(User::PAGE_FLAGS_PRVGROUP)
);
}
function update_1244()
{
// Sets legacy_password for all legacy hashes
DBA::update('user', ['legacy_password' => true], ['SUBSTR(password, 1, 4) != "$2y$"']);
// All legacy hashes are re-hashed using the new secure hashing function
$stmt = DBA::select('user', ['uid', 'password'], ['legacy_password' => true]);
while ($user = DBA::fetch($stmt)) {
DBA::update('user', ['password' => User::hashPassword($user['password'])], ['uid' => $user['uid']]);
}
// Logged in users are forcibly logged out
DBA::delete('session', ['1 = 1']);
return Update::SUCCESS;
}
function update_1245()
{
$rino = DI::config()->get('system', 'rino_encrypt');
if (!$rino) {
return Update::SUCCESS;
}
DI::config()->set('system', 'rino_encrypt', 1);
return Update::SUCCESS;
}
function update_1247()
{
// Removing hooks with the old name
DBA::e("DELETE FROM `hook`
WHERE `hook` LIKE 'plugin_%'");
// Make sure we install the new renamed ones
Addon::reload();
}
function update_1260()
{
DI::config()->set('system', 'maintenance', 1);
DI::config()->set(
'system',
'maintenance_reason',
DI::l10n()->t(
'%s: Updating author-id and owner-id in item and thread table. ',
DateTimeFormat::utcNow().' '.date('e')
)
);
$items = DBA::p("SELECT `id`, `owner-link`, `owner-name`, `owner-avatar`, `network` FROM `item`
WHERE `owner-id` = 0 AND `owner-link` != ''");
while ($item = DBA::fetch($items)) {
$contact = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
'photo' => $item['owner-avatar'], 'network' => $item['network']];
$cid = Contact::getIdForURL($item['owner-link'], 0, null, $contact);
if (empty($cid)) {
continue;
}
Item::update(['owner-id' => $cid], ['id' => $item['id']]);
}
DBA::close($items);
DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
SET `thread`.`owner-id` = `item`.`owner-id` WHERE `thread`.`owner-id` = 0");
$items = DBA::p("SELECT `id`, `author-link`, `author-name`, `author-avatar`, `network` FROM `item`
WHERE `author-id` = 0 AND `author-link` != ''");
while ($item = DBA::fetch($items)) {
$contact = ['url' => $item['author-link'], 'name' => $item['author-name'],
'photo' => $item['author-avatar'], 'network' => $item['network']];
$cid = Contact::getIdForURL($item['author-link'], 0, null, $contact);
if (empty($cid)) {
continue;
}
Item::update(['author-id' => $cid], ['id' => $item['id']]);
}
DBA::close($items);
DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
SET `thread`.`author-id` = `item`.`author-id` WHERE `thread`.`author-id` = 0");
DI::config()->set('system', 'maintenance', 0);
return Update::SUCCESS;
}
function update_1261()
{
// This fixes the results of an issue in the develop branch of 2018-05.
DBA::update('contact', ['blocked' => false, 'pending' => false], ['uid' => 0, 'blocked' => true, 'pending' => true]);
return Update::SUCCESS;
}
function update_1278()
{
DI::config()->set('system', 'maintenance', 1);
DI::config()->set(
'system',
'maintenance_reason',
DI::l10n()->t(
'%s: Updating post-type.',
DateTimeFormat::utcNow().' '.date('e')
)
);
Item::update(['post-type' => Item::PT_PAGE], ['bookmark' => true]);
Item::update(['post-type' => Item::PT_PERSONAL_NOTE], ['type' => 'note']);
DI::config()->set('system', 'maintenance', 0);
return Update::SUCCESS;
}
function update_1288()
{
// Updates missing `uri-id` values
DBA::e("UPDATE `item-activity` INNER JOIN `item` ON `item`.`iaid` = `item-activity`.`id` SET `item-activity`.`uri-id` = `item`.`uri-id` WHERE `item-activity`.`uri-id` IS NULL OR `item-activity`.`uri-id` = 0");
DBA::e("UPDATE `item-content` INNER JOIN `item` ON `item`.`icid` = `item-content`.`id` SET `item-content`.`uri-id` = `item`.`uri-id` WHERE `item-content`.`uri-id` IS NULL OR `item-content`.`uri-id` = 0");
return Update::SUCCESS;
}
// Post-update script of PR 5751 // Post-update script of PR 5751
function update_1298() function update_1298()
{ {