You are here

protected function DeveloperCreateUpdate::executeRequest in Apigee Edge 8

Executes the request itself.

Overrides EdgeJob::executeRequest

File

src/Job/DeveloperCreateUpdate.php, line 59

Class

DeveloperCreateUpdate
Base class for user create/update sync jobs.

Namespace

Drupal\apigee_edge\Job

Code

protected function executeRequest() {
  try {

    /** @var \Drupal\user\UserInterface $account */
    $account = user_load_by_mail($this->email);
    if (!$account) {
      throw new UserDoesNotExistWithEmail($this->email);
    }
    $result = $this
      ->userDeveloperConverter()
      ->convertUser($account);
    $this
      ->beforeDeveloperSave($result, $account);

    // Do not save user if there were no changes.
    if ($result
      ->getSuccessfullyAppliedChanges() > 0) {
      $result
        ->getDeveloper()
        ->save();
    }
  } catch (\Exception $exception) {
    $message = '@operation: Skipping %mail developer. @message %function (line %line of %file). <pre>@backtrace_string</pre>';
    $context = [
      '%mail' => $this->email,
      'link' => $account
        ->toLink(t('View user'))
        ->toString(),
      '@operation' => get_class($this),
    ];
    $context += Error::decodeException($exception);
    $this
      ->logger()
      ->error($message, $context);
    $this
      ->recordMessage(t('Skipping %mail developer: @message', $context)
      ->render());
  } finally {
    if (isset($result)) {
      $this
        ->afterDeveloperSave($result, $account);
    }
  }
}