diff --git a/src/Database/Database.php b/src/Database/Database.php index 361a3248d..28283b1c8 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -1461,8 +1461,12 @@ class Database $row = $this->fetchFirst($sql, $condition); - // Ensure to always return either a "null" or a numeric value - return is_numeric($row['count']) ? (int)$row['count'] : $row['count']; + if (!isset($row['count'])) { + $this->logger->notice('Invalid count.', ['table' => $table, 'row' => $row, 'expression' => $expression, 'condition' => $condition_string, 'callstack' => System::callstack()]); + return 0; + } else { + return (int)$row['count']; + } } /** diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 93e745456..3a214d00b 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2757,12 +2757,14 @@ class Contact return null; } - public static function removeFollower($importer, $contact) + public static function removeFollower(array $contact) { - if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::SHARING)) { + if (in_array($contact['rel'] ?? [], [self::FRIEND, self::SHARING])) { DBA::update('contact', ['rel' => self::SHARING], ['id' => $contact['id']]); - } else { + } elseif (!empty($contact['id'])) { self::remove($contact['id']); + } else { + DI::logger()->info('Couldn\'t remove follower because of invalid contact array', ['contact' => $contact, 'callstack' => System::callstack()]); } } diff --git a/src/Module/Contact.php b/src/Module/Contact.php index ceb2b6757..281e69008 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -290,11 +290,17 @@ class Contact extends BaseModule $contact_id = $data['user']; } - $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'deleted' => false]); + if (!empty($data)) { + $contact = DBA::selectFirst('contact', [], [ + 'id' => $contact_id, + 'uid' => [0, local_user()], + 'deleted' => false + ]); - // Don't display contacts that are about to be deleted - if ($contact['network'] == Protocol::PHANTOM) { - $contact = false; + // Don't display contacts that are about to be deleted + if (DBA::isResult($contact) && !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM) { + $contact = false; + } } } diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 47a530035..1fe527f40 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -1102,7 +1102,7 @@ class Processor return; } - Contact::removeFollower($owner, $contact); + Contact::removeFollower($contact); Logger::info('Undo following request', ['contact' => $cid, 'user' => $uid]); } diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 4ccd259f2..6797608e6 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1584,7 +1584,7 @@ class DFRN } if ($activity->match($item["verb"], Activity::UNFOLLOW)) { Logger::log("Lost follower"); - Contact::removeFollower($importer, $contact, $item); + Contact::removeFollower($contact); return false; } if ($activity->match($item["verb"], Activity::REQ_FRIEND)) { diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 48d7a3371..8ab89d950 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2211,7 +2211,7 @@ class Diaspora return true; } else { Logger::log("Author ".$author." doesn't want to follow us anymore.", Logger::DEBUG); - Contact::removeFollower($importer, $contact); + Contact::removeFollower($contact); return true; } } diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 2404db2df..4f16f40f1 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -471,7 +471,7 @@ class OStatus if ($item["verb"] == Activity::O_UNFOLLOW) { $dummy = null; - Contact::removeFollower($importer, $contact, $item, $dummy); + Contact::removeFollower($contact); continue; }