Commit d55abe10 authored by Daniel Speicher's avatar Daniel Speicher
Browse files

Issue #3259057 by danielspeicher: Return of NULL value in Zendesk.php

parent 1bd5f2f1
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -370,12 +370,13 @@ class Zendesk extends PluginBase {
        $remote_users = $client->users()
          ->search(['query' => $user->getEmail()]);
        if (!empty($remote_users->users)) {
          $userFromPlatform = $this->updateUser($client, $remote_users->users[0], $user);
          $this->updateUser($client, $remote_users->users[0], $user);
          return $remote_users->users[0]->id;
        }
        else {
          $userFromPlatform = $this->createUser($client, $user);
        }
          return $userFromPlatform->user->id;
        }

      }
    } catch (Exception $e) {
@@ -397,12 +398,11 @@ class Zendesk extends PluginBase {
   * @param object $remoteUser
   * @param \Drupal\user\UserInterface $user
   *
   * @return object|null
   * @throws \Zendesk\API\Exceptions\ApiResponseException
   * @throws \Zendesk\API\Exceptions\AuthException
   * @throws \Zendesk\API\Exceptions\MissingParametersException
   */
  private function updateUser(HttpClient $client, object $remoteUser, UserInterface $user): ?object {
  private function updateUser(HttpClient $client, object $remoteUser, UserInterface $user): void {
    $hasChanged = FALSE;
    if($remoteUser->email !== $user->getEmail()) {
      $hasChanged = TRUE;
@@ -411,10 +411,9 @@ class Zendesk extends PluginBase {
      $hasChanged = TRUE;
    }
    if($hasChanged) {
      $remoteUser = $client->users()->update($remoteUser->id, $this->getUserArray($user));
      $this->deleteAllOldEmailIdentities($client, $remoteUser->user->id, $user->getEmail());
      $client->users()->update($remoteUser->id, $this->getUserArray($user));
      $this->deleteAllOldEmailIdentities($client, $remoteUser->id, $user->getEmail());
    }
    return $remoteUser;
  }

  /**