From 4ba8c5acd150f5fd5e8d2eba77dfa67065ab569b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 27 Jul 2022 08:55:16 +0200 Subject: Avoid Undefined offset: 0 error by testing if the element exists before accessing it Signed-off-by: Thomas Citharel --- lib/Service/SocialApiService.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php index 3959eaf6..26a9adb2 100644 --- a/lib/Service/SocialApiService.php +++ b/lib/Service/SocialApiService.php @@ -186,12 +186,14 @@ class SocialApiService { } // search contact in that addressbook, get social data - $contact = $addressBook->search($contactId, ['UID'], ['types' => true])[0]; + $contacts = $addressBook->search($contactId, ['UID'], ['types' => true]); - if (!isset($contact)) { + if (!isset($contacts[0])) { return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED); } + $contact = $contacts[0]; + if ($network) { $allConnectors = [$this->socialProvider->getSocialConnector($network)]; } -- cgit v1.2.3