Merge pull request #5246 from annando/abstraction-encore

Urgent bugfix: Non existing field / double "network" in field list
This commit is contained in:
Hypolite Petovan 2018-06-19 17:58:50 -04:00 committed by GitHub
commit 43ab1b2cf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 73 additions and 97 deletions

View file

@ -110,14 +110,21 @@ function item_redir_and_replace_images($body, $images, $cid) {
/** /**
* Render actions localized * Render actions localized
*/ */
function localize_item(&$item) { function localize_item(&$item)
{
$extracted = item_extract_images($item['body']); $extracted = item_extract_images($item['body']);
if ($extracted['images']) { if ($extracted['images']) {
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']); $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
} }
/// @TODO Separted ??? /*
heluecht 2018-06-19: from my point of view this whole code part is useless.
It just renders the body message of technical posts (Like, dislike, ...).
But: The body isn't visible at all. So we do this stuff just because we can.
Even if these messages were visible, this would only mean that something went wrong.
During the further steps of the database restructuring I would like to address this issue.
*/
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
if (activity_match($item['verb'], ACTIVITY_LIKE) if (activity_match($item['verb'], ACTIVITY_LIKE)
|| activity_match($item['verb'], ACTIVITY_DISLIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)
@ -125,15 +132,11 @@ function localize_item(&$item) {
|| activity_match($item['verb'], ACTIVITY_ATTENDNO) || activity_match($item['verb'], ACTIVITY_ATTENDNO)
|| activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) { || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
/// @TODO may hurt performance $fields = ['author-link', 'author-name', 'verb', 'object-type', 'resource-id', 'body', 'plink'];
$r = q("SELECT * FROM `item`, `contact` $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
WHERE `item`.`contact-id`=`contact`.`id` if (!DBM::is_result($obj)) {
AND `item`.`uri`='%s'",
dbesc($item['parent-uri']));
if (!DBM::is_result($r)) {
return; return;
} }
$obj = $r[0];
$author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]'; $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
$objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]'; $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
@ -189,7 +192,8 @@ function localize_item(&$item) {
$links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>"); $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
$Bname = $obj->title; $Bname = $obj->title;
$Blink = ""; $Bphoto = ""; $Blink = "";
$Bphoto = "";
foreach ($links->link as $l) { foreach ($links->link as $l) {
$atts = $l->attributes(); $atts = $l->attributes();
switch ($atts['rel']) { switch ($atts['rel']) {
@ -258,18 +262,12 @@ function localize_item(&$item) {
} }
if (activity_match($item['verb'], ACTIVITY_TAG)) { if (activity_match($item['verb'], ACTIVITY_TAG)) {
/// @TODO may hurt performance "joining" two tables + asterisk $fields = ['author-link', 'author-name', 'verb', 'object-type', 'resource-id', 'body', 'plink'];
$r = q("SELECT * FROM `item`, `contact` $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
WHERE `item`.`contact-id`=`contact`.`id` if (!DBM::is_result($obj)) {
AND `item`.`uri`='%s'",
dbesc($item['parent-uri']));
if (!DBM::is_result($r)) {
return; return;
} }
$obj = $r[0];
$author = '[url=' . Contact::magicLinkById($item['author-id']) . ']' . $item['author-name'] . '[/url]'; $author = '[url=' . Contact::magicLinkById($item['author-id']) . ']' . $item['author-name'] . '[/url]';
$objauthor = '[url=' . Contact::magicLinkById($obj['author-id']) . ']' . $obj['author-name'] . '[/url]'; $objauthor = '[url=' . Contact::magicLinkById($obj['author-id']) . ']' . $obj['author-name'] . '[/url]';
@ -300,7 +298,6 @@ function localize_item(&$item) {
$tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content); $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
$item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag); $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag);
} }
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) { if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
@ -315,13 +312,9 @@ function localize_item(&$item) {
$obj = XML::parseString($xmlhead.$item['object']); $obj = XML::parseString($xmlhead.$item['object']);
if (strlen($obj->id)) { if (strlen($obj->id)) {
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", $fields = ['author-link', 'author-name', 'plink'];
dbesc($obj->id), $target = Item::selectFirst($fields, ['uri' => $obj->id, 'uid' => $item['uid']]);
intval($item['uid']) if (DBM::is_result($target) && $target['plink']) {
);
if (DBM::is_result($r) && $r[0]['plink']) {
$target = $r[0];
$Bname = $target['author-name']; $Bname = $target['author-name'];
$Blink = $target['author-link']; $Blink = $target['author-link'];
$A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]'; $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';

View file

@ -99,11 +99,9 @@ function authenticate_success($user_record, $login_initial = false, $interactive
$master_record = $a->user; $master_record = $a->user;
if ((x($_SESSION, 'submanage')) && intval($_SESSION['submanage'])) { if ((x($_SESSION, 'submanage')) && intval($_SESSION['submanage'])) {
$r = dba::fetch_first("SELECT * FROM `user` WHERE `uid` = ? LIMIT 1", $user = dba::selectFirst('user', [], ['uid' => $_SESSION['submanage']]);
intval($_SESSION['submanage']) if (DBM::is_result($user)) {
); $master_record = $user;
if (DBM::is_result($r)) {
$master_record = $r;
} }
} }
@ -155,10 +153,10 @@ function authenticate_success($user_record, $login_initial = false, $interactive
logger('auth_identities refresh: ' . print_r($a->identities, true), LOGGER_DEBUG); logger('auth_identities refresh: ' . print_r($a->identities, true), LOGGER_DEBUG);
} }
$r = dba::fetch_first("SELECT * FROM `contact` WHERE `uid` = ? AND `self` LIMIT 1", $_SESSION['uid']); $contact = dba::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => true]);
if (DBM::is_result($r)) { if (DBM::is_result($contact)) {
$a->contact = $r; $a->contact = $contact;
$a->cid = $r['id']; $a->cid = $contact['id'];
$_SESSION['cid'] = $a->cid; $_SESSION['cid'] = $a->cid;
} }

View file

@ -647,13 +647,13 @@ function item_post(App $a) {
// This field is for storing the raw conversation data // This field is for storing the raw conversation data
$datarray['protocol'] = PROTOCOL_DFRN; $datarray['protocol'] = PROTOCOL_DFRN;
$r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $datarray['parent-uri']); $conversation = dba::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $datarray['parent-uri']]);
if (DBM::is_result($r)) { if (DBM::is_result($conversation)) {
if ($r['conversation-uri'] != '') { if ($r['conversation-uri'] != '') {
$datarray['conversation-uri'] = $r['conversation-uri']; $datarray['conversation-uri'] = $conversation['conversation-uri'];
} }
if ($r['conversation-href'] != '') { if ($r['conversation-href'] != '') {
$datarray['conversation-href'] = $r['conversation-href']; $datarray['conversation-href'] = $conversation['conversation-href'];
} }
} }

View file

@ -1332,7 +1332,8 @@ function photos_content(App $a)
// The difference is that we won't be displaying the conversation head item // The difference is that we won't be displaying the conversation head item
// as a "post" but displaying instead the photo it is linked to // as a "post" but displaying instead the photo it is linked to
$linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1", /// @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",
dbesc($datum) dbesc($datum)
); );
@ -1340,7 +1341,8 @@ function photos_content(App $a)
$link_item = []; $link_item = [];
if (DBM::is_result($linked_items)) { if (DBM::is_result($linked_items)) {
$link_item = $linked_items[0]; // This is a workaround to not being forced to rewrite the while $sql_extra handling
$link_item = Item::selectFirstForUser(local_user(), [], ['id' => $linked_items[0]['id']]);
$r = q("SELECT COUNT(*) AS `total` $r = q("SELECT COUNT(*) AS `total`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`

View file

@ -155,12 +155,7 @@ class Worker
*/ */
private static function totalEntries() private static function totalEntries()
{ {
$s = dba::fetch_first("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE `executed` <= ? AND NOT `done`", NULL_DATE); return dba::count('workerqueue', ["`executed` <= ? AND NOT `done`", NULL_DATE]);
if (DBM::is_result($s)) {
return $s["total"];
} else {
return 0;
}
} }
/** /**
@ -718,9 +713,7 @@ class Worker
*/ */
private static function activeWorkers() private static function activeWorkers()
{ {
$workers = dba::fetch_first("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'Worker.php'"); return dba::count('process', ['command' => 'Worker.php']);
return $workers["processes"];
} }
/** /**
@ -973,9 +966,9 @@ class Worker
self::clearProcesses(); self::clearProcesses();
$workers = dba::fetch_first("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'worker.php'"); $workers = self::activeWorkers();
if ($workers["processes"] == 0) { if ($workers == 0) {
self::callWorker(); self::callWorker();
} }
} }

View file

@ -52,8 +52,8 @@ class Conversation
$conversation['source'] = $arr['source']; $conversation['source'] = $arr['source'];
} }
$old_conv = dba::fetch_first("SELECT `item-uri`, `reply-to-uri`, `conversation-uri`, `conversation-href`, `protocol`, `source` $fields = ['item-uri', 'reply-to-uri', 'conversation-uri', 'conversation-href', 'protocol', 'source'];
FROM `conversation` WHERE `item-uri` = ?", $conversation['item-uri']); $old_conv = dba::selectFirst('conversation', $fields, ['item-uri' => $conversation['item-uri']]);
if (DBM::is_result($old_conv)) { if (DBM::is_result($old_conv)) {
// Don't update when only the source has changed. // Don't update when only the source has changed.
// Only do this when there had been no source before. // Only do this when there had been no source before.

View file

@ -296,7 +296,7 @@ class Item extends BaseObject
'file', 'location', 'coord', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'file', 'location', 'coord', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'unseen', 'deleted', 'origin', 'forum_mode', 'mention',
'rendered-hash', 'rendered-html', 'global', 'shadow', 'content-warning', 'rendered-hash', 'rendered-html', 'global', 'content-warning',
'id' => 'item_id', 'network']; 'id' => 'item_id', 'network'];
$fields['author'] = ['url' => 'author-link', 'name' => 'author-name', $fields['author'] = ['url' => 'author-link', 'name' => 'author-name',
@ -306,7 +306,7 @@ class Item extends BaseObject
'thumb' => 'owner-avatar', 'nick' => 'owner-nick', 'network' => 'owner-network']; 'thumb' => 'owner-avatar', 'nick' => 'owner-nick', 'network' => 'owner-network'];
$fields['contact'] = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar', $fields['contact'] = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar',
'network', 'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias', 'uid' => 'contact-uid', 'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias', 'uid' => 'contact-uid',
'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id', 'network' => 'contact-network']; 'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id', 'network' => 'contact-network'];
$fields['parent-item'] = ['guid' => 'parent-guid', 'network' => 'parent-network']; $fields['parent-item'] = ['guid' => 'parent-guid', 'network' => 'parent-network'];

View file

@ -211,18 +211,11 @@ class User
] ]
); );
} else { } else {
$user = dba::fetch_first('SELECT `uid`, `password`, `legacy_password` $fields = ['uid', 'password', 'legacy_password'];
FROM `user` $condition = ["(`email` = ? OR `username` = ? OR `nickname` = ?)
WHERE (`email` = ? OR `username` = ? OR `nickname` = ?) AND NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `verified`",
AND `blocked` = 0 $user_info, $user_info, $user_info];
AND `account_expired` = 0 $user = dba::selectFirst('user', $fields, $condition);
AND `account_removed` = 0
AND `verified` = 1
LIMIT 1',
$user_info,
$user_info,
$user_info
);
} }
if (!DBM::is_result($user)) { if (!DBM::is_result($user)) {

View file

@ -950,13 +950,13 @@ class DFRN
$conversation_uri = $conversation_href; $conversation_uri = $conversation_href;
if (isset($parent_item)) { if (isset($parent_item)) {
$r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $item['parent-uri']); $conversation = dba::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $item['parent-uri']]);
if (DBM::is_result($r)) { if (DBM::is_result($conversation)) {
if ($r['conversation-uri'] != '') { if ($r['conversation-uri'] != '') {
$conversation_uri = $r['conversation-uri']; $conversation_uri = $conversation['conversation-uri'];
} }
if ($r['conversation-href'] != '') { if ($r['conversation-href'] != '') {
$conversation_href = $r['conversation-href']; $conversation_href = $conversation['conversation-href'];
} }
} }
} }
@ -1537,13 +1537,11 @@ class DFRN
$author["name"] = $xpath->evaluate($element."/atom:name/text()", $context)->item(0)->nodeValue; $author["name"] = $xpath->evaluate($element."/atom:name/text()", $context)->item(0)->nodeValue;
$author["link"] = $xpath->evaluate($element."/atom:uri/text()", $context)->item(0)->nodeValue; $author["link"] = $xpath->evaluate($element."/atom:uri/text()", $context)->item(0)->nodeValue;
$contact_old = dba::fetch_first("SELECT `id`, `uid`, `url`, `network`, `avatar-date`, `avatar`, `name-date`, `uri-date`, `addr`, $fields = ['id', 'uid', 'url', 'network', 'avatar-date', 'avatar', 'name-date', 'uri-date', 'addr',
`name`, `nick`, `about`, `location`, `keywords`, `xmpp`, `bdyear`, `bd`, `hidden`, `contact-type` 'name', 'nick', 'about', 'location', 'keywords', 'xmpp', 'bdyear', 'bd', 'hidden', 'contact-type'];
FROM `contact` WHERE `uid` = ? AND `nurl` = ? AND `network` != ?", $condition = ["`uid` = ? AND `nurl` = ? AND `network` != ?",
$importer["importer_uid"], $importer["importer_uid"], normalise_link($author["link"]), NETWORK_STATUSNET];
normalise_link($author["link"]), $contact_old = dba::selectFirst('contact', $fields, $condition);
NETWORK_STATUSNET
);
if (DBM::is_result($contact_old)) { if (DBM::is_result($contact_old)) {
$author["contact-id"] = $contact_old["id"]; $author["contact-id"] = $contact_old["id"];

View file

@ -1971,14 +1971,13 @@ class OStatus
$conversation_uri = $conversation_href; $conversation_uri = $conversation_href;
if (isset($parent_item)) { if (isset($parent_item)) {
$r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $parent_item); $conversation = dba::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $parent_item]);
if (DBM::is_result($conversation)) {
if (DBM::is_result($r)) {
if ($r['conversation-uri'] != '') { if ($r['conversation-uri'] != '') {
$conversation_uri = $r['conversation-uri']; $conversation_uri = $conversation['conversation-uri'];
} }
if ($r['conversation-href'] != '') { if ($r['conversation-href'] != '') {
$conversation_href = $r['conversation-href']; $conversation_href = $conversation['conversation-href'];
} }
} }
} }