You are here

protected function UserCreateUpdate::executeRequest in Apigee Edge 8

Executes the request itself.

Overrides EdgeJob::executeRequest

File

src/Job/UserCreateUpdate.php, line 62

Class

UserCreateUpdate
Base class for user create/update sync jobs.

Namespace

Drupal\apigee_edge\Job

Code

protected function executeRequest() {
  try {

    /** @var \Drupal\apigee_edge\Entity\DeveloperInterface $developer */
    $developer = Developer::load($this->email);
    if ($developer === NULL) {
      throw new DeveloperDoesNotExistException($this->email);
    }
    $result = $this
      ->userDeveloperConverter()
      ->convertDeveloper($developer);
    $this
      ->beforeUserSave($result);

    // Do not save user if there were no changes.
    if ($result
      ->getSuccessfullyAppliedChanges() > 0) {

      // If the developer-user synchronization is in progress, then saving
      // the same developer in apigee_edge_user_presave() while creating
      // Drupal user based on a developer should be avoided.
      _apigee_edge_set_sync_in_progress(TRUE);
      $result
        ->getUser()
        ->save();
    }
  } catch (\Exception $exception) {
    $message = '@operation: Skipping %mail user. @message %function (line %line of %file). <pre>@backtrace_string</pre>';
    $context = [
      '%mail' => $this->email,
      '@operation' => get_class($this),
    ];
    $context += Error::decodeException($exception);
    $this
      ->logger()
      ->error($message, $context);
    $this
      ->recordMessage(t('Skipping %mail user: @message', $context)
      ->render());
  } finally {
    _apigee_edge_set_sync_in_progress(FALSE);
    if (isset($result)) {
      $this
        ->afterUserSave($result);
    }
  }
}