abstract class DeveloperCreateUpdate 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\DeveloperCreateUpdate uses UserDeveloperSyncJobTrait
- class \Drupal\apigee_edge\Job\EdgeJob
Expanded class hierarchy of DeveloperCreateUpdate
File
- src/
Job/ DeveloperCreateUpdate.php, line 34
Namespace
Drupal\apigee_edge\JobView source
abstract class DeveloperCreateUpdate extends EdgeJob {
use UserDeveloperSyncJobTrait;
/**
* The Drupal user's email.
*
* @var string
*/
protected $email;
/**
* DeveloperCreateUpdate constructor.
*
* @param string $email
* The email address of the developer.
*/
public function __construct(string $email) {
parent::__construct();
$this->email = $email;
}
/**
* {@inheritdoc}
*/
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);
}
}
}
/**
* Execute actions before the developer gets saved.
*
* @param \Drupal\apigee_edge\Structure\UserToDeveloperConversionResult $result
* The result of the entity conversion.
* @param \Drupal\user\UserInterface $user
* The converted user entity.
*
* @throws \Exception
* Can throw exception to abort developer save.
*/
protected function beforeDeveloperSave(UserToDeveloperConversionResult $result, UserInterface $user) : void {
$context = [
'link' => $user
->toLink(t('View user'))
->toString(),
];
$this
->logConversionProblems($result
->getProblems(), $context);
}
/**
* Execute actions after the developer has been saved.
*
* Actions here always gets executed even if the developer save has failed.
*
* @param \Drupal\apigee_edge\Structure\UserToDeveloperConversionResult $result
* The result of the entity conversion.
* @param \Drupal\user\UserInterface $user
* The converted user entity.
*/
protected function afterDeveloperSave(UserToDeveloperConversionResult $result, UserInterface $user) : void {
}
/**
* {@inheritdoc}
*/
protected function logConversionProblem(UserDeveloperConversionException $problem, array $context = []) : void {
$ro = new \ReflectionObject($this);
$context = [
'%mail' => $this->email,
'@operation' => $ro
->getShortName(),
];
if ($problem instanceof UserDeveloperConversionUserFieldDoesNotExistException) {
$message = "@operation: %mail developer's %attribute_name attribute has been skipped because %field_name field does not exist.";
$context['%field_name'] = $problem
->getFieldName();
$context['%attribute_name'] = $this
->fieldAttributeConverter()
->getAttributeName($problem
->getFieldName());
$this
->logger()
->warning($message, $context);
$this
->recordMessage(t("%mail developer's %attribute_name attribute has been skipped because %field_name field does not exist.", $context)
->render());
}
elseif ($problem instanceof UserDeveloperConversionNoStorageFormatterFoundException) {
$message = "@operation: %mail developer's %attribute_name attribute has been skipped because there is no available storage formatter for %field_type field type.";
$context['%field_type'] = $problem
->getFieldDefinition()
->getType();
$context['%attribute_name'] = $this
->fieldAttributeConverter()
->getAttributeName($problem
->getFieldDefinition()
->getName());
$this
->logger()
->warning($message, $context);
$this
->recordMessage(t("%mail developer's %attribute_name attribute has been skipped because there is no available storage formatter for %field_type field type.", $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 developer: @message", $context)
->render());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeveloperCreateUpdate:: |
protected | property | The Drupal user's email. | |
DeveloperCreateUpdate:: |
protected | function | Execute actions after the developer has been saved. | |
DeveloperCreateUpdate:: |
protected | function | Execute actions before the developer gets saved. | |
DeveloperCreateUpdate:: |
protected | function |
Executes the request itself. Overrides EdgeJob:: |
|
DeveloperCreateUpdate:: |
protected | function |
Logs an entity conversation problems encountered meanwhile syncing. Overrides UserDeveloperSyncJobTrait:: |
|
DeveloperCreateUpdate:: |
public | function |
DeveloperCreateUpdate constructor. Overrides Job:: |
|
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 |
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. |