-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
1 changed file
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,22 @@ public function sanitize($result, CommandData $commandData): void | |
$messages[] = dt('User emails sanitized.'); | ||
} | ||
|
||
if (!empty($options['ignored-roles'])) { | ||
$roles = explode(',', $options['ignored-roles']); | ||
/** @var \Drupal\Core\Database\Query\SelectInterface $roles_query */ | ||
$roles_query = $this->database->select('user__roles', 'ur'); | ||
$roles_query | ||
->condition('roles_target_id', $roles, 'IN') | ||
->fields('ur', ['entity_id']); | ||
$roles_query_results = $roles_query->execute(); | ||
$ignored_users = $roles_query_results->fetchCol(); | ||
|
||
if (!empty($ignored_users)) { | ||
$query->condition('uid', $ignored_users, 'NOT IN'); | ||
$messages[] = dt('User emails and passwords for the specified roles preserved.'); | ||
} | ||
} | ||
|
||
if ($messages) { | ||
$query->execute(); | ||
$this->entityTypeManager->getStorage('user')->resetCache(); | ||
|
@@ -86,7 +102,8 @@ public function sanitize($result, CommandData $commandData): void | |
#[CLI\Hook(type: HookManager::OPTION_HOOK, target: SanitizeCommands::SANITIZE)] | ||
#[CLI\Option(name: 'sanitize-email', description: 'The pattern for test email addresses in the sanitization operation, or <info>no</info> to keep email addresses unchanged. May contain replacement patterns <info>%uid</info>, <info>%mail</info> or <info>%name</info>.')] | ||
#[CLI\Option(name: 'sanitize-password', description: 'By default, passwords are randomized. Specify <info>no</info> to disable that. Specify any other value to set all passwords to that value.')] | ||
public function options($options = ['sanitize-email' => 'user+%[email protected]', 'sanitize-password' => null]): void | ||
#[CLI\Option(name: 'ignored-roles', description: 'A comma delimited list of roles. Users with at least one of the roles will be exempt from sanitization.')] | ||
public function options($options = ['sanitize-email' => 'user+%[email protected]', 'sanitize-password' => null, 'ignored-roles' => null]): void | ||
{ | ||
} | ||
|
||
|
@@ -100,6 +117,9 @@ public function messages(&$messages, InputInterface $input): void | |
if ($this->isEnabled($options['sanitize-email'])) { | ||
$messages[] = dt('Sanitize user emails.'); | ||
} | ||
if (in_array('ignored-roles', $options)) { | ||
$messages[] = dt('Preserve user emails and passwords for the specified roles.'); | ||
} | ||
} | ||
|
||
/** | ||
|