You are here

class UserUpdate in Apigee Edge 8

A job to update a Drupal user based on an Apigee Edge developer.

Hierarchy

Expanded class hierarchy of UserUpdate

File

src/Job/UserUpdate.php, line 28

Namespace

Drupal\apigee_edge\Job
View source
class UserUpdate extends UserCreateUpdate {

  /**
   * {@inheritdoc}
   */
  protected function beforeUserSave(DeveloperToUserConversionResult $result) : void {
    parent::beforeUserSave($result);

    /** @var \Drupal\user\UserInterface $original_user */
    $original_user = \Drupal::entityTypeManager()
      ->getStorage('user')
      ->loadUnchanged($result
      ->getUser()
      ->id());

    // Even if the developer has been blocked in Apigee Edge we should not block
    // its Drupal user automatically when syncing.
    if ($original_user
      ->isActive() && $result
      ->getUser()
      ->isBlocked()) {
      $result
        ->getUser()
        ->activate();
    }
    $context = [
      'link' => $result
        ->getUser()
        ->toLink(t('View user'))
        ->toString(),
    ];
    $this
      ->logConversionProblems($result
      ->getProblems(), $context);

    // Rollback a synchronised field's value if the related attribute's value
    // contained an incorrect field value.
    if (count($result
      ->getProblems()) > 0) {

      /** @var \Drupal\user\UserInterface $original_user */
      foreach ($result
        ->getProblems() as $problem) {

        // Do not apply rollback on base fields.
        if ($problem instanceof DeveloperToUserConversationInvalidValueException && !in_array($problem
          ->getTarget(), $this
          ->userDeveloperConverter()::DEVELOPER_PROP_USER_BASE_FIELD_MAP, TRUE)) {
          $result
            ->getUser()
            ->set($problem
            ->getTarget(), $original_user
            ->get($problem
            ->getTarget())
            ->getValue());
        }
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function __toString() : string {
    return t('Updating user (@email) from Apigee Edge.', [
      '@email' => $this->email,
    ])
      ->render();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EdgeJob::$request protected property Request data.
EdgeJob::$response protected property Response data.
EdgeJob::execute public function Executes this job. Overrides Job::execute 1
EdgeJob::getConnector protected function Returns the SDK connector instance from the global container.
EdgeJob::renderArray public function Returns this job's visual representation. Overrides Job::renderArray
Job::$exceptions protected property Exception storage.
Job::$id private property Job ID.
Job::$messages protected property Messages storage.
Job::$retry protected property Remaining retries.
Job::$status protected property Job status.
Job::$tag private property The tag of the job.
Job::ALL_STATUSES protected constant Job statuses.
Job::consumeRetry public function Consumes a retry.
Job::FAILED public constant Job is failed, and it won't be retried.
Job::FINISHED public constant Job is finished successfully.
Job::getExceptions public function Gets all stored exception data.
Job::getId public function Gets the job id.
Job::getMessages public function Gets all stored messages.
Job::getStatus public function Gets the status of the job.
Job::getTag public function Gets the job tag.
Job::IDLE public constant Job is waiting to be picked up by a worker.
Job::recordException public function Adds an exception to the exception storage.
Job::recordMessage public function Adds a message to the message storage.
Job::RESCHEDULED public constant Job failed, waiting to be retried.
Job::RUNNING public constant Job is running.
Job::SELECTED public constant Job is claimed by a worker, but not running yet.
Job::setStatus public function Sets the status of the job.
Job::setTag public function Sets the job tag.
Job::shouldRetry public function Whether this job should be retried when an exception is thrown.
UserCreateUpdate::$email protected property The Apigee Edge developer's email.
UserCreateUpdate::afterUserSave protected function Execute actions after the user has been saved. 1
UserCreateUpdate::executeRequest protected function Executes the request itself. Overrides EdgeJob::executeRequest
UserCreateUpdate::logConversionProblem protected function Logs an entity conversation problems encountered meanwhile syncing. Overrides UserDeveloperSyncJobTrait::logConversionProblem
UserCreateUpdate::__construct public function UserCreateUpdate constructor. Overrides Job::__construct
UserDeveloperSyncJobTrait::fieldAttributeConverter protected function Field-attribute converter service.
UserDeveloperSyncJobTrait::logConversionProblems protected function Logs all entity conversion problems encountered meanwhile syncing.
UserDeveloperSyncJobTrait::logger protected function Logger interface.
UserDeveloperSyncJobTrait::userDeveloperConverter protected function User-developer converter service.
UserUpdate::beforeUserSave protected function Execute actions before the user gets saved. Overrides UserCreateUpdate::beforeUserSave
UserUpdate::__toString public function Returns this job's textual representation. Overrides Job::__toString