class AcsfDuplicationScrubUserHandler in Acquia Cloud Site Factory Connector 8.2
Same name and namespace in other branches
- 8 src/Event/AcsfDuplicationScrubUserHandler.php \Drupal\acsf\Event\AcsfDuplicationScrubUserHandler
Handles the scrubbing of Drupal users.
Hierarchy
- class \Drupal\acsf\Event\AcsfEventHandler
- class \Drupal\acsf\Event\AcsfDuplicationScrubEntityHandler
- class \Drupal\acsf\Event\AcsfDuplicationScrubUserHandler
- class \Drupal\acsf\Event\AcsfDuplicationScrubEntityHandler
Expanded class hierarchy of AcsfDuplicationScrubUserHandler
1 file declares its use of AcsfDuplicationScrubUserHandler
- AcsfDuplicationCommands.php in acsf_duplication/
src/ Commands/ AcsfDuplicationCommands.php
File
- src/
Event/ AcsfDuplicationScrubUserHandler.php, line 8
Namespace
Drupal\acsf\EventView source
class AcsfDuplicationScrubUserHandler extends AcsfDuplicationScrubEntityHandler {
/**
* Constructor.
*
* @param AcsfEvent $event
* The event that has been initiated.
*/
public function __construct(AcsfEvent $event) {
$this->entityTypeId = 'user';
parent::__construct($event);
}
/**
* Implements AcsfEventHandler::handle().
*/
public function handle() {
$options = $this->event->context['scrub_options'];
if ($options['retain_users']) {
// We still want to log that we were here.
$this
->consoleLog(dt('Entered @class', [
'@class' => get_class($this),
]));
return;
}
parent::handle();
}
/**
* {@inheritdoc}
*/
protected function deleteEntities(array $entities) {
// Delete the entities one by one. This may be slower than mass deleting
// them, but this way we can catch an exception without a mass delete
// being fully rolled back.
foreach ($entities as $entity) {
try {
$this
->reassignFiles($entity
->id());
$entity
->delete();
} catch (\Exception $e) {
// OK, we'll live with not scrubbing this.
}
}
}
/**
* {@inheritdoc}
*/
protected function getBaseQuery() {
$entity_query = parent::getBaseQuery();
$entity_query
->condition('uid', $this
->getPreservedUsers(), 'NOT IN');
return $entity_query;
}
/**
* Reassigns files owned by the given user ID to the anonymous user.
*
* Prior to deleting the user, re-assign {file_managed}.uid to anonymous.
* Re-assign files only: allow nodes and comments to be deleted. It would be
* more proper to call File::load_multiple(), iterate each loaded file entity,
* set its uid property, and call save() (see comment_user_cancel() for a
* similar example for comments). It would be even more proper if file.module
* implemented hook_user_cancel(), so we could just call that hook. But for
* performance, we just update the {file_managed} table directly.
*
* @param int $uid
* The user ID for which to reassign files.
*/
protected function reassignFiles($uid) {
\Drupal::database()
->update('file_managed')
->fields([
'uid' => 0,
])
->condition('uid', $uid)
->execute();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AcsfDuplicationScrubEntityHandler:: |
protected | property | The ACSF variable storage. | |
AcsfDuplicationScrubEntityHandler:: |
protected | property | The entity type to scrub. | |
AcsfDuplicationScrubEntityHandler:: |
protected | property | The entity manager. | |
AcsfDuplicationScrubEntityHandler:: |
protected | property | The module handler. | |
AcsfDuplicationScrubEntityHandler:: |
public | function | Counts the entities that still need to be processed. | 1 |
AcsfDuplicationScrubEntityHandler:: |
protected | function | Gets a list of user IDs which should not be scrubbed. | 1 |
AcsfDuplicationScrubEntityHandler:: |
public | function | Gets a list of site admins. | |
AcsfDuplicationScrubUserHandler:: |
protected | function |
Deletes entities. Overrides AcsfDuplicationScrubEntityHandler:: |
|
AcsfDuplicationScrubUserHandler:: |
protected | function |
Gets an initialized entity query instance. Overrides AcsfDuplicationScrubEntityHandler:: |
|
AcsfDuplicationScrubUserHandler:: |
public | function |
Implements AcsfEventHandler::handle(). Overrides AcsfDuplicationScrubEntityHandler:: |
|
AcsfDuplicationScrubUserHandler:: |
protected | function | Reassigns files owned by the given user ID to the anonymous user. | |
AcsfDuplicationScrubUserHandler:: |
public | function |
Constructor. Overrides AcsfDuplicationScrubEntityHandler:: |
|
AcsfEventHandler:: |
public | property | The time that the handler was completed. | |
AcsfEventHandler:: |
public | property | Any messages triggered by the handler. | |
AcsfEventHandler:: |
public | property | The time that the handler was started. | |
AcsfEventHandler:: |
public | function | Writes a log message to the console. |