More "q" calls have been replaced

This commit is contained in:
Michael 2021-10-03 15:02:20 +00:00
parent 3634009c0a
commit 763e264196
10 changed files with 105 additions and 222 deletions

View File

@ -3627,17 +3627,12 @@ function api_direct_messages_new($type)
$recipient = null; $recipient = null;
if (!empty($_POST['screen_name'])) { if (!empty($_POST['screen_name'])) {
$r = q( $contacts = Contact::selectFirst(['id', 'nurl', 'network'], ['uid' => api_user(), 'nick' => $_POST['screen_name']]);
"SELECT `id`, `nurl`, `network` FROM `contact` WHERE `uid`=%d AND `nick`='%s'", if (DBA::isResult($contacts)) {
intval(api_user()),
DBA::escape($_POST['screen_name'])
);
if (DBA::isResult($r)) {
// Selecting the id by priority, friendica first // Selecting the id by priority, friendica first
api_best_nickname($r); api_best_nickname($contacts);
$recipient = api_get_user($a, $r[0]['nurl']); $recipient = api_get_user($a, $contacts[0]['nurl']);
} }
} else { } else {
$recipient = api_get_user($a, $_POST['user_id']); $recipient = api_get_user($a, $_POST['user_id']);
@ -3649,13 +3644,9 @@ function api_direct_messages_new($type)
$replyto = ''; $replyto = '';
if (!empty($_REQUEST['replyto'])) { if (!empty($_REQUEST['replyto'])) {
$r = q( $mail = DBA::selectFirst('mail', ['parent-uri', 'title'], ['uid' => api_user(), 'id' => $_REQUEST['replyto']]);
'SELECT `parent-uri`, `title` FROM `mail` WHERE `uid`=%d AND `id`=%d', $replyto = $mail['parent-uri'];
intval(api_user()), $sub = $mail['title'];
intval($_REQUEST['replyto'])
);
$replyto = $r[0]['parent-uri'];
$sub = $r[0]['title'];
} else { } else {
if (!empty($_REQUEST['title'])) { if (!empty($_REQUEST['title'])) {
$sub = $_REQUEST['title']; $sub = $_REQUEST['title'];
@ -3667,8 +3658,8 @@ function api_direct_messages_new($type)
$id = Mail::send($recipient['cid'], $_POST['text'], $sub, $replyto); $id = Mail::send($recipient['cid'], $_POST['text'], $sub, $replyto);
if ($id > -1) { if ($id > -1) {
$r = q("SELECT * FROM `mail` WHERE id=%d", intval($id)); $mail = DBA::selectFirst('mail', [], ['id' => $id]);
$ret = api_format_messages($r[0], $recipient, $sender); $ret = api_format_messages($mail, $recipient, $sender);
} else { } else {
$ret = ["error" => $id]; $ret = ["error" => $id];
} }
@ -5084,25 +5075,19 @@ function api_friendica_group_show($type)
// get data of the specified group id or all groups if not specified // get data of the specified group id or all groups if not specified
if ($gid != 0) { if ($gid != 0) {
$r = q( $groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid, 'id' => $gid]);
"SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d AND `id` = %d",
intval($uid),
intval($gid)
);
// error message if specified gid is not in database // error message if specified gid is not in database
if (!DBA::isResult($r)) { if (!DBA::isResult($groups)) {
throw new BadRequestException("gid not available"); throw new BadRequestException("gid not available");
} }
} else { } else {
$r = q( $groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid]);
"SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d",
intval($uid)
);
} }
// loop through all groups and retrieve all members for adding data in the user array // loop through all groups and retrieve all members for adding data in the user array
$grps = []; $grps = [];
foreach ($r as $rr) { foreach ($groups as $rr) {
$members = Contact\Group::getById($rr['id']); $members = Contact\Group::getById($rr['id']);
$users = []; $users = [];
@ -5158,26 +5143,13 @@ function api_friendica_group_delete($type)
throw new BadRequestException('gid or name not specified'); throw new BadRequestException('gid or name not specified');
} }
// get data of the specified group id
$r = q(
"SELECT * FROM `group` WHERE `uid` = %d AND `id` = %d",
intval($uid),
intval($gid)
);
// error message if specified gid is not in database // error message if specified gid is not in database
if (!DBA::isResult($r)) { if (!DBA::exists('group', ['uid' => $uid, 'id' => $gid])) {
throw new BadRequestException('gid not available'); throw new BadRequestException('gid not available');
} }
// get data of the specified group id and group name
$rname = q(
"SELECT * FROM `group` WHERE `uid` = %d AND `id` = %d AND `name` = '%s'",
intval($uid),
intval($gid),
DBA::escape($name)
);
// error message if specified gid is not in database // error message if specified gid is not in database
if (!DBA::isResult($rname)) { if (!DBA::exists('group', ['uid' => $uid, 'id' => $gid, 'name' => $name])) {
throw new BadRequestException('wrong group name'); throw new BadRequestException('wrong group name');
} }
@ -5261,25 +5233,13 @@ function group_create($name, $uid, $users = [])
throw new BadRequestException('group name not specified'); throw new BadRequestException('group name not specified');
} }
// get data of the specified group name
$rname = q(
"SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' AND `deleted` = 0",
intval($uid),
DBA::escape($name)
);
// error message if specified group name already exists // error message if specified group name already exists
if (DBA::isResult($rname)) { if (DBA::exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => false])) {
throw new BadRequestException('group name already exists'); throw new BadRequestException('group name already exists');
} }
// check if specified group name is a deleted group // Check if the group needs to be reactivated
$rname = q( if (DBA::exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => true])) {
"SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' AND `deleted` = 1",
intval($uid),
DBA::escape($name)
);
// error message if specified group name already exists
if (DBA::isResult($rname)) {
$reactivate_group = true; $reactivate_group = true;
} }
@ -5296,13 +5256,7 @@ function group_create($name, $uid, $users = [])
$errorusers = []; $errorusers = [];
foreach ($users as $user) { foreach ($users as $user) {
$cid = $user['cid']; $cid = $user['cid'];
// check if user really exists as contact if (DBA::exists('contact', ['id' => $cid, 'uid' => $uid])) {
$contact = q(
"SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
intval($cid),
intval($uid)
);
if (count($contact)) {
Group::addMember($gid, $cid); Group::addMember($gid, $cid);
} else { } else {
$erroraddinguser = true; $erroraddinguser = true;
@ -5444,14 +5398,8 @@ function api_friendica_group_update($type)
$errorusers = []; $errorusers = [];
foreach ($users as $user) { foreach ($users as $user) {
$cid = $user['cid']; $cid = $user['cid'];
// check if user really exists as contact
$contact = q(
"SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
intval($cid),
intval($uid)
);
if (count($contact)) { if (DBA::exists('contact', ['id' => $cid, 'uid' => $uid])) {
Group::addMember($gid, $cid); Group::addMember($gid, $cid);
} else { } else {
$erroraddinguser = true; $erroraddinguser = true;

View File

@ -79,13 +79,8 @@ function fbrowser_content(App $a)
$filename_e = $rr['filename']; $filename_e = $rr['filename'];
// Take the largest picture that is smaller or equal 640 pixels // Take the largest picture that is smaller or equal 640 pixels
$p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1", $photo = Photo::selectFirst(['scale'], ["`resource-id` = ? AND `height` <= ? AND `width` <= ?", $rr['resource-id'], 640, 640, ['order' => ['scale']]]);
DBA::escape($rr['resource-id'])); $scale = $photo['scale'] ?? $rr['loq'];
if ($p) {
$scale = $p[0]["scale"];
} else {
$scale = $rr['loq'];
}
return [ return [
DI::baseUrl() . '/photos/' . $a->getLoggedInUserNickname() . '/image/' . $rr['resource-id'], DI::baseUrl() . '/photos/' . $a->getLoggedInUserNickname() . '/image/' . $rr['resource-id'],
@ -110,9 +105,7 @@ function fbrowser_content(App $a)
break; break;
case "file": case "file":
if (DI::args()->getArgc()==2) { if (DI::args()->getArgc()==2) {
$files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ", $files = DBA::selectToArray('attach', ['id', 'filename', 'filetype'], ['uid' => local_user()]);
intval(local_user())
);
function _map_files2($rr) function _map_files2($rr)
{ {

View File

@ -214,11 +214,7 @@ function photos_post(App $a)
// RENAME photo album // RENAME photo album
$newalbum = Strings::escapeTags(trim($_POST['albumname'])); $newalbum = Strings::escapeTags(trim($_POST['albumname']));
if ($newalbum != $album) { if ($newalbum != $album) {
q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d", Photo::update(['album' => $newalbum], ['album' => $album, 'uid' => $page_owner_uid]);
DBA::escape($newalbum),
DBA::escape($album),
intval($page_owner_uid)
);
// Update the photo albums cache // Update the photo albums cache
Photo::clearAlbumCache($page_owner_uid); Photo::clearAlbumCache($page_owner_uid);

View File

@ -37,40 +37,26 @@ function repair_ostatus_content(App $a) {
$uid = local_user(); $uid = local_user();
$counter = intval($_REQUEST['counter']); $counter = intval($_REQUEST['counter'] ?? 0);
$r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE $condition = ['uid' => $uid, 'network' => Protocol::OSTATUS, 'rel' => [Contact::FRIEND, Contact::SHARING]];
`uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)", $total = DBA::count('contact', $condition);
intval($uid),
DBA::escape(Protocol::OSTATUS),
intval(Contact::FRIEND),
intval(Contact::SHARING));
if (!DBA::isResult($r)) { if (!$total) {
return ($o . DI::l10n()->t("Error")); return ($o . DI::l10n()->t("Error"));
} }
$total = $r[0]["total"]; $contact = Contact::selectToArray(['url'], $condition, ['order' => ['url'], 'limit' => [$counter++, 1]]);
if (!DBA::isResult($contact)) {
$r = q("SELECT `url` FROM `contact` WHERE
`uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)
ORDER BY `url`
LIMIT %d, 1",
intval($uid),
DBA::escape(Protocol::OSTATUS),
intval(Contact::FRIEND),
intval(Contact::SHARING), $counter++);
if (!DBA::isResult($r)) {
$o .= DI::l10n()->t("Done"); $o .= DI::l10n()->t("Done");
return $o; return $o;
} }
$o .= "<p>".$counter."/".$total.": ".$r[0]["url"]."</p>"; $o .= "<p>" . $counter . "/" . $total . ": " . $contact[0]["url"] . "</p>";
$o .= "<p>" . DI::l10n()->t("Keep this window open until done.") . "</p>"; $o .= "<p>" . DI::l10n()->t("Keep this window open until done.") . "</p>";
Contact::createFromProbeForUser($a->getLoggedInUserId(), $r[0]["url"]); Contact::createFromProbeForUser($a->getLoggedInUserId(), $contact[0]["url"]);
DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="1; URL=' . DI::baseUrl() . '/repair_ostatus?counter=' . $counter . '">'; DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="1; URL=' . DI::baseUrl() . '/repair_ostatus?counter=' . $counter . '">';

View File

@ -93,11 +93,7 @@ function settings_post(App $a)
$mail_pubmail = $_POST['mail_pubmail'] ?? ''; $mail_pubmail = $_POST['mail_pubmail'] ?? '';
if (function_exists('imap_open') && !DI::config()->get('system', 'imap_disabled')) { if (function_exists('imap_open') && !DI::config()->get('system', 'imap_disabled')) {
$failed = false; if (!DBA::exists('mailacct', ['uid' => local_user()])) {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
intval(local_user())
);
if (!DBA::isResult($r)) {
DBA::insert('mailacct', ['uid' => local_user()]); DBA::insert('mailacct', ['uid' => local_user()]);
} }
if (strlen($mail_pass)) { if (strlen($mail_pass)) {
@ -105,34 +101,30 @@ function settings_post(App $a)
openssl_public_encrypt($mail_pass, $pass, $user['pubkey']); openssl_public_encrypt($mail_pass, $pass, $user['pubkey']);
DBA::update('mailacct', ['pass' => bin2hex($pass)], ['uid' => local_user()]); DBA::update('mailacct', ['pass' => bin2hex($pass)], ['uid' => local_user()]);
} }
$r = q("UPDATE `mailacct` SET `server` = '%s', `port` = %d, `ssltype` = '%s', `user` = '%s',
`action` = %d, `movetofolder` = '%s',
`mailbox` = 'INBOX', `reply_to` = '%s', `pubmail` = %d WHERE `uid` = %d",
DBA::escape($mail_server),
intval($mail_port),
DBA::escape($mail_ssl),
DBA::escape($mail_user),
intval($mail_action),
DBA::escape($mail_movetofolder),
DBA::escape($mail_replyto),
intval($mail_pubmail),
intval(local_user())
);
Logger::notice('updating mailaccount', ['response' => $r]);
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
intval(local_user())
);
if (DBA::isResult($r)) {
$eacct = $r[0];
$mb = Email::constructMailboxName($eacct);
if (strlen($eacct['server'])) { $r = DBA::update('mailacct', [
'server' => $mail_server,
'port' => $mail_port,
'ssltype' => $mail_ssl,
'user' => $mail_user,
`action` => $mail_action,
'movetofolder' => $mail_movetofolder,
'mailbox' => 'INBOX',
'reply_to' => $mail_replyto,
'pubmail' => $mail_pubmail
], ['uid' => local_user()]);
Logger::notice('updating mailaccount', ['response' => $r]);
$mailacct = DBA::selectFirst('mailacct', [], ['uid' => local_user()]);
if (DBA::isResult($mailacct)) {
$mb = Email::constructMailboxName($mailacct);
if (strlen($mailacct['server'])) {
$dcrpass = ''; $dcrpass = '';
openssl_private_decrypt(hex2bin($eacct['pass']), $dcrpass, $user['prvkey']); openssl_private_decrypt(hex2bin($mailacct['pass']), $dcrpass, $user['prvkey']);
$mbox = Email::connect($mb, $mail_user, $dcrpass); $mbox = Email::connect($mb, $mail_user, $dcrpass);
unset($dcrpass); unset($dcrpass);
if (!$mbox) { if (!$mbox) {
$failed = true;
notice(DI::l10n()->t('Failed to connect with email account using the settings provided.')); notice(DI::l10n()->t('Failed to connect with email account using the settings provided.'));
} }
} }
@ -510,22 +502,20 @@ function settings_content(App $a)
$mail_disabled = ((function_exists('imap_open') && (!DI::config()->get('system', 'imap_disabled'))) ? 0 : 1); $mail_disabled = ((function_exists('imap_open') && (!DI::config()->get('system', 'imap_disabled'))) ? 0 : 1);
if (!$mail_disabled) { if (!$mail_disabled) {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", $mailacct = DBA::selectFirst('mailacct', [], ['uid' => local_user()]);
local_user()
);
} else { } else {
$r = null; $mailacct = null;
} }
$mail_server = ((DBA::isResult($r)) ? $r[0]['server'] : ''); $mail_server = $mailacct['server'] ?? '';
$mail_port = ((DBA::isResult($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : ''); $mail_port = (!empty($mailacct['port']) && is_numeric($mailacct['port'])) ? (int)$mailacct['port'] : '';
$mail_ssl = ((DBA::isResult($r)) ? $r[0]['ssltype'] : ''); $mail_ssl = $mailacct['ssltype'] ?? '';
$mail_user = ((DBA::isResult($r)) ? $r[0]['user'] : ''); $mail_user = $mailacct['user'] ?? '';
$mail_replyto = ((DBA::isResult($r)) ? $r[0]['reply_to'] : ''); $mail_replyto = $mailacct['reply_to'] ?? '';
$mail_pubmail = ((DBA::isResult($r)) ? $r[0]['pubmail'] : 0); $mail_pubmail = $mailacct['pubmail'] ?? 0;
$mail_action = ((DBA::isResult($r)) ? $r[0]['action'] : 0); $mail_action = $mailacct['action'] ?? 0;
$mail_movetofolder = ((DBA::isResult($r)) ? $r[0]['movetofolder'] : ''); $mail_movetofolder = $mailacct['movetofolder'] ?? '';
$mail_chk = ((DBA::isResult($r)) ? $r[0]['last_check'] : DBA::NULL_DATETIME); $mail_chk = $mailacct['last_check'] ?? DBA::NULL_DATETIME;
$tpl = Renderer::getMarkupTemplate('settings/connectors.tpl'); $tpl = Renderer::getMarkupTemplate('settings/connectors.tpl');

View File

@ -24,6 +24,7 @@ use Friendica\App;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\UserImport; use Friendica\Core\UserImport;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
function uimport_post(App $a) function uimport_post(App $a)
@ -48,9 +49,9 @@ function uimport_content(App $a)
$max_dailies = intval(DI::config()->get('system', 'max_daily_registrations')); $max_dailies = intval(DI::config()->get('system', 'max_daily_registrations'));
if ($max_dailies) { if ($max_dailies) {
$r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day"); $total = DBA::count('user', ["`register_date` > UTC_TIMESTAMP - INTERVAL 1 DAY"]);
if ($r && $r[0]['total'] >= $max_dailies) { if ($total >= $max_dailies) {
Logger::log('max daily registrations exceeded.'); Logger::notice('max daily registrations exceeded.');
notice(DI::l10n()->t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.')); notice(DI::l10n()->t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.'));
return; return;
} }

View File

@ -255,12 +255,8 @@ function wall_upload_post(App $a, $desktopmode = true)
} }
if (!$desktopmode) { if (!$desktopmode) {
$r = q("SELECT `id`, `datasize`, `width`, `height`, `type` FROM `photo` $photo = Photo::selectFirst(['id', 'datasize', 'width', 'height', 'type'], ['resource-id' => $resource_id], ['order' => ['width']]);
WHERE `resource-id` = '%s' if (!$photo) {
ORDER BY `width` DESC LIMIT 1",
$resource_id
);
if (!$r) {
if ($r_json) { if ($r_json) {
echo json_encode(['error' => '']); echo json_encode(['error' => '']);
exit(); exit();
@ -269,11 +265,11 @@ function wall_upload_post(App $a, $desktopmode = true)
} }
$picture = []; $picture = [];
$picture["id"] = $r[0]["id"]; $picture["id"] = $photo["id"];
$picture["size"] = $r[0]["datasize"]; $picture["size"] = $photo["datasize"];
$picture["width"] = $r[0]["width"]; $picture["width"] = $photo["width"];
$picture["height"] = $r[0]["height"]; $picture["height"] = $photo["height"];
$picture["type"] = $r[0]["type"]; $picture["type"] = $photo["type"];
$picture["albumpage"] = DI::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id; $picture["albumpage"] = DI::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id;
$picture["picture"] = DI::baseUrl() . "/photo/{$resource_id}-0." . $Image->getExt(); $picture["picture"] = DI::baseUrl() . "/photo/{$resource_id}-0." . $Image->getExt();
$picture["preview"] = DI::baseUrl() . "/photo/{$resource_id}-{$smallest}." . $Image->getExt(); $picture["preview"] = DI::baseUrl() . "/photo/{$resource_id}-{$smallest}." . $Image->getExt();

View File

@ -26,6 +26,7 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Mail; use Friendica\Model\Mail;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Util\Strings; use Friendica\Util\Strings;
function wallmessage_post(App $a) { function wallmessage_post(App $a) {
@ -44,27 +45,19 @@ function wallmessage_post(App $a) {
return; return;
} }
$r = q("select * from user where nickname = '%s' limit 1", $user = User::getByNickname($recipient);
DBA::escape($recipient) if (empty($r)) {
); Logger::notice('wallmessage: no recipient');
if (! DBA::isResult($r)) {
Logger::log('wallmessage: no recipient');
return; return;
} }
$user = $r[0]; if (!$user['unkmail']) {
if (! intval($user['unkmail'])) {
notice(DI::l10n()->t('Permission denied.')); notice(DI::l10n()->t('Permission denied.'));
return; return;
} }
$r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1", $total = DBA::count('mail', ["`uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 1 DAY AND `unknown`", $user['uid']]);
intval($user['uid']) if ($total > $user['cntunkmail']) {
);
if ($r[0]['total'] > $user['cntunkmail']) {
notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])); notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
return; return;
} }
@ -104,28 +97,21 @@ function wallmessage_content(App $a) {
return; return;
} }
$r = q("select * from user where nickname = '%s' limit 1", $user = User::getByNickname($recipient);
DBA::escape($recipient)
);
if (! DBA::isResult($r)) { if (empty($user)) {
notice(DI::l10n()->t('No recipient.')); notice(DI::l10n()->t('No recipient.'));
Logger::log('wallmessage: no recipient'); Logger::notice('wallmessage: no recipient');
return; return;
} }
$user = $r[0]; if (!$user['unkmail']) {
if (!intval($user['unkmail'])) {
notice(DI::l10n()->t('Permission denied.')); notice(DI::l10n()->t('Permission denied.'));
return; return;
} }
$r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1", $total = DBA::count('mail', ["`uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 1 DAY AND `unknown`", $user['uid']]);
intval($user['uid']) if ($total > $user['cntunkmail']) {
);
if ($r[0]['total'] > $user['cntunkmail']) {
notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])); notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
return; return;
} }

View File

@ -121,14 +121,9 @@ class FContact
{ {
Logger::info('fcontact', ['guid' => $fcontact_guid]); Logger::info('fcontact', ['guid' => $fcontact_guid]);
$r = q( $fcontact = DBA::selectFirst('fcontact', ['url'], ["`url` != ? AND `network` = ? AND `guid` = ?", '', Protocol::DIASPORA, $fcontact_guid]);
"SELECT `url` FROM `fcontact` WHERE `url` != '' AND `network` = '%s' AND `guid` = '%s'", if (DBA::isResult($fcontact)) {
DBA::escape(Protocol::DIASPORA), return $fcontact['url'];
DBA::escape($fcontact_guid)
);
if (DBA::isResult($r)) {
return $r[0]['url'];
} }
return null; return null;

View File

@ -37,6 +37,7 @@ use Friendica\Model\Item;
use Friendica\Model\ItemURI; use Friendica\Model\ItemURI;
use Friendica\Model\Mail; use Friendica\Model\Mail;
use Friendica\Model\Notification; use Friendica\Model\Notification;
use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\Tag; use Friendica\Model\Tag;
@ -299,15 +300,12 @@ class DFRN
DI::config()->set('system', 'site_pubkey', $res['pubkey']); DI::config()->set('system', 'site_pubkey', $res['pubkey']);
} }
$rp = q( $profilephotos = Photo::selectToArray(['resource-id' , 'scale'], ['profile' => true, 'uid' => $uid], ['order' => ['scale']]);
"SELECT `resource-id` , `scale`, type FROM `photo`
WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;",
$uid
);
$photos = []; $photos = [];
$ext = Images::supportedTypes(); $ext = Images::supportedTypes();
foreach ($rp as $p) { foreach ($profilephotos as $p) {
$photos[$p['scale']] = DI::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']]; $photos[$p['scale']] = DI::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
} }
@ -1379,19 +1377,13 @@ class DFRN
} }
// update contact // update contact
$r = q( $old = Contact::selectFirst(['photo', 'url'], ['id' => $importer["id"], 'uid' => $importer["importer_uid"]]);
"SELECT `photo`, `url` FROM `contact` WHERE `id` = %d AND `uid` = %d",
intval($importer["id"]),
intval($importer["importer_uid"])
);
if (!DBA::isResult($r)) { if (!DBA::isResult($old)) {
Logger::log("Query failed to execute, no result returned in " . __FUNCTION__); Logger::notice("Query failed to execute, no result returned in " . __FUNCTION__);
return false; return false;
} }
$old = $r[0];
// Update the contact table. We try to find every entry. // Update the contact table. We try to find every entry.
$fields = ['name' => $relocate["name"], 'avatar' => $relocate["avatar"], $fields = ['name' => $relocate["name"], 'avatar' => $relocate["avatar"],
'url' => $relocate["url"], 'nurl' => Strings::normaliseLink($relocate["url"]), 'url' => $relocate["url"], 'nurl' => Strings::normaliseLink($relocate["url"]),