Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix call on null in SocialApiService #2351

Merged
merged 2 commits into from Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Cron/SocialUpdate.php
Expand Up @@ -46,7 +46,7 @@ protected function run($arguments) {
$offsetContact = $arguments['offsetContact'] ?? null;

// update contacts with first available social media profile
$result = $this->social->updateAddressbooks('any', $userId, $offsetBook, $offsetContact);
$result = $this->social->updateAddressbooks($userId, $offsetBook, $offsetContact);

if ($result->getStatus() === Http::STATUS_PARTIAL_CONTENT) {
// not finished; schedule a follow-up
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/DiasporaProvider.php
Expand Up @@ -49,6 +49,9 @@ public function __construct(IClientService $httpClient) {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfileIds($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/FacebookProvider.php
Expand Up @@ -45,6 +45,9 @@ public function __construct(IClientService $httpClient) {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfiles($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/GravatarProvider.php
Expand Up @@ -38,6 +38,9 @@ public function __construct() {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("EMAIL",$contact)) {
return false;
}
$emails = $contact['EMAIL'];
return isset($emails) && count($emails);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/InstagramProvider.php
Expand Up @@ -55,6 +55,9 @@ public function __construct(IClientService $httpClient,
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfiles($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/MastodonProvider.php
Expand Up @@ -45,6 +45,9 @@ public function __construct(IClientService $httpClient) {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$profiles = $this->getProfileIds($contact);
return isset($profiles) && count($profiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/TumblrProvider.php
Expand Up @@ -38,6 +38,9 @@ public function __construct() {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfileIds($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/TwitterProvider.php
Expand Up @@ -54,6 +54,9 @@ public function __construct(IClientService $httpClient,
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfileIds($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/XingProvider.php
Expand Up @@ -45,6 +45,9 @@ public function __construct(IClientService $httpClient) {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfileIds($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/SocialApiService.php
Expand Up @@ -342,12 +342,12 @@ protected function sortContacts(array $a, array $b) {
/**
* Updates social profile data for all contacts of an addressbook
*
* @param {String} network the social network to use (fallback: take first match)
* @param {String|null} network the social network to use (take first match if unset)
* @param {String} userId the address book owner
*
* @returns {JSONResponse} JSONResponse with the list of changed and failed contacts
*/
public function updateAddressbooks(string $network, string $userId, string $offsetBook = null, string $offsetContact = null) : JSONResponse {
public function updateAddressbooks(string $userId, string $offsetBook = null, string $offsetContact = null, string $network = null) : JSONResponse {

// double check!
$syncAllowedByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes');
Expand Down
20 changes: 15 additions & 5 deletions tests/unit/Service/SocialApiServiceTest.php
Expand Up @@ -237,7 +237,7 @@ public function testUpdateContactWithNetworkVersion3() {
'VERSION' => $contact['VERSION'],
'PHOTO;ENCODING=b;TYPE=' . $imageType . ';VALUE=BINARY' => base64_encode($body)
];

$this->socialProvider
->expects($this->once())->method("getSocialConnector")->with($network);
$provider->expects($this->once())->method("supportsContact")->with($contact);
Expand Down Expand Up @@ -306,7 +306,7 @@ public function testUpdateContactWithNetworkVersion4() {
'VERSION' => $contact['VERSION'],
'PHOTO' => "data:".$imageType.";base64," . base64_encode($body)
];

$this->socialProvider
->expects($this->once())->method("getSocialConnector")->with($network);
$provider->expects($this->once())->method("supportsContact")->with($contact);
Expand Down Expand Up @@ -442,7 +442,17 @@ public function testUpdateAddressbooks($syncAllowedByAdmin, $bgSyncEnabledByUser

$this->setupAddressbooks();

$result = $this->service->updateAddressbooks('any', 'mrstest');
if ($syncAllowedByAdmin === 'yes' && $bgSyncEnabledByUser === 'yes') {
$this->socialProvider
->expects($this->atLeastOnce())
->method('getSocialConnectors');
}

$this->socialProvider
->expects($this->never())
->method('getSocialConnector');

$result = $this->service->updateAddressbooks('mrstest');

$this->assertEquals($expected, $result->getStatus());

Expand Down Expand Up @@ -474,7 +484,7 @@ public function testUpdateAddressbooksTimeout() {

$this->setupAddressbooks();

$result = $this->service->updateAddressbooks('any', 'msstest');
$result = $this->service->updateAddressbooks('msstest');

$this->assertEquals(Http::STATUS_PARTIAL_CONTENT, $result->getStatus());

Expand Down Expand Up @@ -502,7 +512,7 @@ public function testUpdateAddressbooksContinued($syncAllowedByAdmin, $bgSyncEnab

$this->setupAddressbooks();

$result = $this->service->updateAddressbooks('any', 'mrstest', 'contacts2', '22222222-2222-2222-2222-222222222222');
$result = $this->service->updateAddressbooks('mrstest', 'contacts2', '22222222-2222-2222-2222-222222222222');

$this->assertEquals($expected, $result->getStatus());

Expand Down