Merge pull request #7251 from annando/fix-fatal

Avoid fatal error when AP contact has no photo
This commit is contained in:
Philipp 2019-06-11 08:45:49 +02:00 committed by GitHub
commit f4d20c577b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View File

@ -152,7 +152,13 @@ class APContact extends BaseObject
$apcontact['alias'] = JsonLD::fetchElement($compacted['as:url'], 'as:href', '@id'); $apcontact['alias'] = JsonLD::fetchElement($compacted['as:url'], 'as:href', '@id');
} }
if (empty($apcontact['url']) || empty($apcontact['inbox'])) { // Quit if none of the basic values are set
if (empty($apcontact['url']) || empty($apcontact['inbox']) || empty($apcontact['type'])) {
return false;
}
// Quit if this doesn't seem to be an account at all
if (!in_array($apcontact['type'], ActivityPub::ACCOUNT_TYPES)) {
return false; return false;
} }
@ -228,11 +234,13 @@ class APContact extends BaseObject
DBA::update('contact', $contact_fields, ['nurl' => Strings::normaliseLink($url)]); DBA::update('contact', $contact_fields, ['nurl' => Strings::normaliseLink($url)]);
$contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => Strings::normaliseLink($url)]); if (!empty($apcontact['photo'])) {
while ($contact = DBA::fetch($contacts)) { $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => Strings::normaliseLink($url)]);
Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']); while ($contact = DBA::fetch($contacts)) {
Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']);
}
DBA::close($contacts);
} }
DBA::close($contacts);
// Update the gcontact table // Update the gcontact table
// These two fields don't exist in the gcontact table // These two fields don't exist in the gcontact table

View File

@ -413,7 +413,11 @@ class Photo extends BaseObject
$photo_failure = false; $photo_failure = false;
$filename = basename($image_url); $filename = basename($image_url);
$img_str = Network::fetchUrl($image_url, true); if (!empty($image_url)) {
$img_str = Network::fetchUrl($image_url, true);
} else {
$img_str = '';
}
if ($quit_on_error && ($img_str == "")) { if ($quit_on_error && ($img_str == "")) {
return false; return false;

View File

@ -436,7 +436,7 @@ class Transmitter
$data['to'][] = $profile['url']; $data['to'][] = $profile['url'];
} else { } else {
$data['cc'][] = $profile['url']; $data['cc'][] = $profile['url'];
if (!$item['private']) { if (!$item['private'] && !empty($actor_profile['followers'])) {
$data['cc'][] = $actor_profile['followers']; $data['cc'][] = $actor_profile['followers'];
} }
} }