Browse Source

Merge pull request #8753 from MrPetovan/bug/fatal-errors

Remove dependency to App in Contact::createFromProbe
pull/8767/head
Michael Vogel GitHub 3 weeks ago
parent
commit
aedbb0d627
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 33 deletions
  1. +1
    -2
      mod/follow.php
  2. +1
    -1
      mod/ostatus_subscribe.php
  3. +1
    -1
      mod/repair_ostatus.php
  4. +3
    -7
      mod/salmon.php
  5. +18
    -18
      src/Model/Contact.php
  6. +2
    -3
      src/Module/Contact.php
  7. +6
    -1
      src/Worker/AddContact.php

+ 1
- 2
mod/follow.php View File

@@ -40,7 +40,6 @@ function follow_post(App $a)
DI::baseUrl()->redirect('contact');
}

$uid = local_user();
$url = Probe::cleanURI($_REQUEST['url']);
$return_path = 'follow?url=' . urlencode($url);

@@ -48,7 +47,7 @@ function follow_post(App $a)
// This is just a precaution if maybe this page is called somewhere directly via POST
$_SESSION['fastlane'] = $url;

$result = Contact::createFromProbe($uid, $url, true);
$result = Contact::createFromProbe($a->user, $url, true);

if ($result['success'] == false) {
// Possibly it is a remote item and not an account


+ 1
- 1
mod/ostatus_subscribe.php View File

@@ -91,7 +91,7 @@ function ostatus_subscribe_content(App $a)

$probed = Probe::uri($url);
if ($probed['network'] == Protocol::OSTATUS) {
$result = Contact::createFromProbe($uid, $url, true, Protocol::OSTATUS);
$result = Contact::createFromProbe($a->user, $url, true, Protocol::OSTATUS);
if ($result['success']) {
$o .= ' - ' . DI::l10n()->t('success');
} else {


+ 1
- 1
mod/repair_ostatus.php View File

@@ -70,7 +70,7 @@ function repair_ostatus_content(App $a) {

$o .= "<p>".DI::l10n()->t("Keep this window open until done.")."</p>";

Contact::createFromProbe($uid, $r[0]["url"], true);
Contact::createFromProbe($a->user, $r[0]["url"], true);

DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="1; URL=' . DI::baseUrl() . '/repair_ostatus?counter='.$counter.'">';



+ 3
- 7
mod/salmon.php View File

@@ -42,15 +42,11 @@ function salmon_post(App $a, $xml = '') {

$nick = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : '');

$r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
DBA::escape($nick)
);
if (! DBA::isResult($r)) {
$importer = DBA::selectFirst('user', [], ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false]);
if (! DBA::isResult($importer)) {
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
}

$importer = $r[0];

// parse the xml

$dom = simplexml_load_string($xml,'SimpleXMLElement',0, ActivityNamespace::SALMON_ME);
@@ -175,7 +171,7 @@ function salmon_post(App $a, $xml = '') {
Logger::log('Author ' . $author_link . ' unknown to user ' . $importer['uid'] . '.');

if (DI::pConfig()->get($importer['uid'], 'system', 'ostatus_autofriend')) {
$result = Contact::createFromProbe($importer['uid'], $author_link);
$result = Contact::createFromProbe($importer, $author_link);

if ($result['success']) {
$r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND ( `url` = '%s' OR `alias` = '%s')


+ 18
- 18
src/Model/Contact.php View File

@@ -2272,20 +2272,20 @@ class Contact
* $return['message'] error text if success is false.
*
* Takes a $uid and a url/handle and adds a new contact
* @param int $uid
* @param string $url
*
* @param array $user The user the contact should be created for
* @param string $url The profile URL of the contact
* @param bool $interactive
* @param string $network
* @return array
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\NotFoundException
* @throws \ImagickException
*/
public static function createFromProbe($uid, $url, $interactive = false, $network = '')
public static function createFromProbe(array $user, $url, $interactive = false, $network = '')
{
$result = ['cid' => -1, 'success' => false, 'message' => ''];

$a = DI::app();

// remove ajax junk, e.g. Twitter
$url = str_replace('/#!/', '/', $url);

@@ -2316,7 +2316,7 @@ class Contact
if (!empty($arr['contact']['name'])) {
$ret = $arr['contact'];
} else {
$ret = Probe::uri($url, $network, $uid, false);
$ret = Probe::uri($url, $network, $user['uid'], false);
}

if (($network != '') && ($ret['network'] != $network)) {
@@ -2328,10 +2328,10 @@ class Contact
// the poll url is more reliable than the profile url, as we may have
// indirect links or webfinger links

$condition = ['uid' => $uid, 'poll' => [$ret['poll'], Strings::normaliseLink($ret['poll'])], 'network' => $ret['network'], 'pending' => false];
$condition = ['uid' => $user['uid'], 'poll' => [$ret['poll'], Strings::normaliseLink($ret['poll'])], 'network' => $ret['network'], 'pending' => false];
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
if (!DBA::isResult($contact)) {
$condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($url), 'network' => $ret['network'], 'pending' => false];
$condition = ['uid' => $user['uid'], 'nurl' => Strings::normaliseLink($url), 'network' => $ret['network'], 'pending' => false];
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
}

@@ -2340,9 +2340,9 @@ class Contact
if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) {
if ($interactive) {
if (strlen(DI::baseUrl()->getUrlPath())) {
$myaddr = bin2hex(DI::baseUrl() . '/profile/' . $a->user['nickname']);
$myaddr = bin2hex(DI::baseUrl() . '/profile/' . $user['nickname']);
} else {
$myaddr = bin2hex($a->user['nickname'] . '@' . DI::baseUrl()->getHostname());
$myaddr = bin2hex($user['nickname'] . '@' . DI::baseUrl()->getHostname());
}

DI::baseUrl()->redirect($ret['request'] . "&addr=$myaddr");
@@ -2417,7 +2417,7 @@ class Contact

// create contact record
self::insert([
'uid' => $uid,
'uid' => $user['uid'],
'created' => DateTimeFormat::utcNow(),
'url' => $ret['url'],
'nurl' => Strings::normaliseLink($ret['url']),
@@ -2445,7 +2445,7 @@ class Contact
]);
}

$contact = DBA::selectFirst('contact', [], ['url' => $ret['url'], 'network' => $ret['network'], 'uid' => $uid]);
$contact = DBA::selectFirst('contact', [], ['url' => $ret['url'], 'network' => $ret['network'], 'uid' => $user['uid']]);
if (!DBA::isResult($contact)) {
$result['message'] .= DI::l10n()->t('Unable to retrieve contact information.') . EOL;
return $result;
@@ -2454,16 +2454,16 @@ class Contact
$contact_id = $contact['id'];
$result['cid'] = $contact_id;

Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact_id);
Group::addMember(User::getDefaultGroup($user['uid'], $contact["network"]), $contact_id);

// Update the avatar
self::updateAvatar($ret['photo'], $uid, $contact_id);
self::updateAvatar($ret['photo'], $user['uid'], $contact_id);

// pull feed and consume it, which should subscribe to the hub.

Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");

$owner = User::getOwnerDataById($uid);
$owner = User::getOwnerDataById($user['uid']);

if (DBA::isResult($owner)) {
if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
@@ -2483,7 +2483,7 @@ class Contact
Salmon::slapper($owner, $contact['notify'], $slap);
}
} elseif ($protocol == Protocol::DIASPORA) {
$ret = Diaspora::sendShare($a->user, $contact);
$ret = Diaspora::sendShare($owner, $contact);
Logger::log('share returns: ' . $ret);
} elseif ($protocol == Protocol::ACTIVITYPUB) {
$activity_id = ActivityPub\Transmitter::activityIDFromContact($contact_id);
@@ -2492,7 +2492,7 @@ class Contact
return false;
}

$ret = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid, $activity_id);
$ret = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $user['uid'], $activity_id);
Logger::log('Follow returns: ' . $ret);
}
}
@@ -2677,7 +2677,7 @@ class Contact
}
} elseif (DBA::isResult($user) && in_array($user['page-flags'], [User::PAGE_FLAGS_SOAPBOX, User::PAGE_FLAGS_FREELOVE, User::PAGE_FLAGS_COMMUNITY])) {
if (($user['page-flags'] == User::PAGE_FLAGS_FREELOVE) && ($network != Protocol::DIASPORA)) {
self::createFromProbe($importer['uid'], $url, false, $network);
self::createFromProbe($importer, $url, false, $network);
}

$condition = ['uid' => $importer['uid'], 'url' => $url, 'pending' => true];


+ 2
- 3
src/Module/Contact.php View File

@@ -167,10 +167,9 @@ class Contact extends BaseModule
return;
}

$uid = $contact['uid'];

if ($contact['network'] == Protocol::OSTATUS) {
$result = Model\Contact::createFromProbe($uid, $contact['url'], false, $contact['network']);
$user = Model\User::getById($contact['uid']);
$result = Model\Contact::createFromProbe($user, $contact['url'], false, $contact['network']);

if ($result['success']) {
DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]);


+ 6
- 1
src/Worker/AddContact.php View File

@@ -23,6 +23,7 @@ namespace Friendica\Worker;

use Friendica\Core\Logger;
use Friendica\Model\Contact;
use Friendica\Model\User;

class AddContact
{
@@ -33,7 +34,11 @@ class AddContact
*/
public static function execute(int $uid, string $url)
{
$result = Contact::createFromProbe($uid, $url, '', false);
$user = User::getById($uid);
if (empty($user)) {
return;
}
$result = Contact::createFromProbe($user, $url, '', false);
Logger::info('Added contact', ['uid' => $uid, 'url' => $url, 'result' => $result]);
}
}

Loading…
Cancel
Save