abstract class UserCreateUpdate in Apigee Edge 8
Base class for user create/update sync jobs.
Hierarchy
- class \Drupal\apigee_edge\Job\Job- class \Drupal\apigee_edge\Job\EdgeJob- class \Drupal\apigee_edge\Job\UserCreateUpdate uses UserDeveloperSyncJobTrait
 
 
- class \Drupal\apigee_edge\Job\EdgeJob
Expanded class hierarchy of UserCreateUpdate
File
- src/Job/ UserCreateUpdate.php, line 37 
Namespace
Drupal\apigee_edge\JobView source
abstract class UserCreateUpdate extends EdgeJob {
  use UserDeveloperSyncJobTrait;
  /**
   * The Apigee Edge developer's email.
   *
   * @var string
   */
  protected $email;
  /**
   * UserCreateUpdate constructor.
   *
   * @param string $email
   *   The email address of the user.
   */
  public function __construct(string $email) {
    parent::__construct();
    $this->email = $email;
  }
  /**
   * {@inheritdoc}
   */
  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);
      }
    }
  }
  /**
   * Execute actions before the user gets saved.
   *
   * @param \Drupal\apigee_edge\Structure\DeveloperToUserConversionResult $result
   *   Result of the entity conversion.
   *
   * @throws \Exception
   *   Can throw an exception to abort user save.
   */
  protected function beforeUserSave(DeveloperToUserConversionResult $result) : void {
    // Abort the operation if any of these special problems occurred
    // meanwhile the conversation.
    foreach ($result
      ->getProblems() as $problem) {
      // Skip user save if username is already taken or the username
      // is too long instead of getting a database exception in a lower layer.
      // (Username field's value is not limited on Apigee Edge and it is not
      // unique either.)
      if ($problem instanceof DeveloperToUserConversationInvalidValueException && $problem
        ->getTarget() === 'name') {
        throw $problem;
      }
    }
    // It's necessary because changed time is automatically updated on the
    // UI only.
    $result
      ->getUser()
      ->setChangedTime(\Drupal::time()
      ->getCurrentTime());
  }
  /**
   * Execute actions after the user has been saved.
   *
   * Actions here always gets executed even if the user save has failed.
   *
   * @param \Drupal\apigee_edge\Structure\DeveloperToUserConversionResult $result
   *   Result of the entity conversion.
   */
  protected function afterUserSave(DeveloperToUserConversionResult $result) : void {
  }
  /**
   * {@inheritdoc}
   */
  protected function logConversionProblem(UserDeveloperConversionException $problem, array $context = []) : void {
    $ro = new \ReflectionObject($this);
    $context += [
      '%mail' => $this->email,
      '@operation' => $ro
        ->getShortName(),
    ];
    if ($problem instanceof DeveloperToUserConversionAttributeDoesNotExistException) {
      $message = '@operation: %field_name field value on %mail user has not changed because the relevant developer does not have %attribute_name attribute on Apigee Edge.';
      $context += [
        '%field_name' => $this
          ->fieldAttributeConverter()
          ->getFieldName($problem
          ->getAttributeName()),
        '%attribute_name' => $problem
          ->getAttributeName(),
      ];
      $this
        ->logger()
        ->warning($message, $context);
      $this
        ->recordMessage(t("%field_name field value on %mail user has not changed because the relevant developer does not have %attribute_name attribute on Apigee Edge.", $context)
        ->render());
    }
    elseif ($problem instanceof UserDeveloperConversionUserFieldDoesNotExistException) {
      $message = '@operation: %attribute_name attribute has been skipped because %field_name field does not exist on user.';
      $context += [
        '%field_name' => $problem
          ->getFieldName(),
        '%attribute_name' => $this
          ->fieldAttributeConverter()
          ->getAttributeName($problem
          ->getFieldName()),
      ];
      $this
        ->logger()
        ->warning($message, $context);
      $this
        ->recordMessage(t("%attribute_name attribute has been skipped because %field_name field does not exist on user.", $context)
        ->render());
    }
    elseif ($problem instanceof UserDeveloperConversionNoStorageFormatterFoundException) {
      $message = '@operation: %field_name field has been skipped because there is no available storage formatter for %field_type field type.';
      $context += [
        '%field_name' => $problem
          ->getFieldDefinition()
          ->getName(),
        '%field_type' => $problem
          ->getFieldDefinition()
          ->getType(),
      ];
      $this
        ->logger()
        ->warning($message, $context);
      $this
        ->recordMessage(t('%field_name field has been skipped because there is no available storage formatter for %field_type field type.', $context)
        ->render());
    }
    elseif ($problem instanceof DeveloperToUserConversationInvalidValueException) {
      $message = "@operation: %field_name field value on %mail user has not changed because %attribute_name attribute's value is invalid as a field value: %message";
      $context += [
        '%field_name' => $problem
          ->getTarget(),
        '%attribute_name' => $problem
          ->getSource(),
        '%field_value' => is_object($problem
          ->getViolation()
          ->getInvalidValue()) ? $problem
          ->getViolation()
          ->getInvalidValue() instanceof ItemList ? var_export($problem
          ->getViolation()
          ->getInvalidValue()
          ->getValue(), TRUE) : $problem
          ->getViolation()
          ->getInvalidValue()->value : $problem
          ->getViolation()
          ->getInvalidValue(),
        '%message' => $problem
          ->getViolation()
          ->getMessage(),
      ];
      $this
        ->logger()
        ->warning($message, $context);
      $this
        ->recordMessage(t("%field_name field value on %mail user has not changed because %attribute_name attribute's value is invalid as a field value: %message", $context)
        ->render());
    }
    else {
      $context += Error::decodeException($problem);
      $this
        ->logger()
        ->warning('@operation: Unexpected problem occurred while creating %mail user: @message %function (line %line of %file). <pre>@backtrace_string</pre>');
      $this
        ->recordMessage(t("Unexpected problem occurred while processing %mail user: @message", $context)
        ->render());
    }
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| EdgeJob:: | protected | property | Request data. | |
| EdgeJob:: | protected | property | Response data. | |
| EdgeJob:: | public | function | Executes this job. Overrides Job:: | 1 | 
| EdgeJob:: | protected | function | Returns the SDK connector instance from the global container. | |
| EdgeJob:: | public | function | Returns this job's visual representation. Overrides Job:: | |
| Job:: | protected | property | Exception storage. | |
| Job:: | private | property | Job ID. | |
| Job:: | protected | property | Messages storage. | |
| Job:: | protected | property | Remaining retries. | |
| Job:: | protected | property | Job status. | |
| Job:: | private | property | The tag of the job. | |
| Job:: | protected | constant | Job statuses. | |
| Job:: | public | function | Consumes a retry. | |
| Job:: | public | constant | Job is failed, and it won't be retried. | |
| Job:: | public | constant | Job is finished successfully. | |
| Job:: | public | function | Gets all stored exception data. | |
| Job:: | public | function | Gets the job id. | |
| Job:: | public | function | Gets all stored messages. | |
| Job:: | public | function | Gets the status of the job. | |
| Job:: | public | function | Gets the job tag. | |
| Job:: | public | constant | Job is waiting to be picked up by a worker. | |
| Job:: | public | function | Adds an exception to the exception storage. | |
| Job:: | public | function | Adds a message to the message storage. | |
| Job:: | public | constant | Job failed, waiting to be retried. | |
| Job:: | public | constant | Job is running. | |
| Job:: | public | constant | Job is claimed by a worker, but not running yet. | |
| Job:: | public | function | Sets the status of the job. | |
| Job:: | public | function | Sets the job tag. | |
| Job:: | public | function | Whether this job should be retried when an exception is thrown. | |
| Job:: | abstract public | function | Returns this job's textual representation. | 5 | 
| UserCreateUpdate:: | protected | property | The Apigee Edge developer's email. | |
| UserCreateUpdate:: | protected | function | Execute actions after the user has been saved. | 1 | 
| UserCreateUpdate:: | protected | function | Execute actions before the user gets saved. | 1 | 
| UserCreateUpdate:: | protected | function | Executes the request itself. Overrides EdgeJob:: | |
| UserCreateUpdate:: | protected | function | Logs an entity conversation problems encountered meanwhile syncing. Overrides UserDeveloperSyncJobTrait:: | |
| UserCreateUpdate:: | public | function | UserCreateUpdate constructor. Overrides Job:: | |
| UserDeveloperSyncJobTrait:: | protected | function | Field-attribute converter service. | |
| UserDeveloperSyncJobTrait:: | protected | function | Logs all entity conversion problems encountered meanwhile syncing. | |
| UserDeveloperSyncJobTrait:: | protected | function | Logger interface. | |
| UserDeveloperSyncJobTrait:: | protected | function | User-developer converter service. | 
