You are here

protected function UserCreateUpdate::logConversionProblem in Apigee Edge 8

Logs an entity conversation problems encountered meanwhile syncing.

TODO Consider to add a translatable operation to message logged by recordMessage() if we actually start using that method something.

Parameters

\Drupal\apigee_edge\Exception\UserDeveloperConversionException $problem: Entity conversion problem.

array $context: Additional problem for log messages.

Overrides UserDeveloperSyncJobTrait::logConversionProblem

File

src/Job/UserCreateUpdate.php, line 138

Class

UserCreateUpdate
Base class for user create/update sync jobs.

Namespace

Drupal\apigee_edge\Job

Code

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());
  }
}