The developer stages need their user names and email address anonymised. I did not find anything googling the subject matter. Maybe somebody developed a Drush extension for this? Any other suggestions are welcome too.
-
I've found module to anonymize user comment comment anonymizer– Артем ИльинJan 15, 2018 at 13:13
-
@АртемИльин the module is not related. The idea is to protect the identity of site users when developers work on their experimental or developer instance of the site.– ñullJan 16, 2018 at 11:23
3 Answers
You can use drush sql-sync
command to sync the database and obscure email addresses and the user passwords during db deployment.
--sanitize
Obscure email addresses and reset passwords in the user table post-sync.
Check drush help sql-sync
for help.
-
Thanks! Good to know! However in my case the sync is produced from a daily backup using mysqldump, but I might change that system to use drush instead. Below what I did using some SQL queries.– ñullJan 16, 2018 at 11:04
I came up with this:
drush sql-query "
UPDATE users
SET
name=CONCAT('User-',uid),
mail=CONCAT(uid,'@anon.com'),
init=CONCAT(uid,'[email protected]')
WHERE uid > 0;"
drush upwd User-1 --password=SecureAdminPassword
You need, drush sql-sanitize
$ drush sql-sanitize -h
Run sanitization operations on the current database. You can add more sanitization to this command by implementing hook_drush_sql_sync_sanitize().
Examples:
drush sql-sanitize Sanitize database without modifying any passwords.
--sanitize-password=no
drush sql-sanitize Sanitizes database but exempts two user fields from modification.
--whitelist-fields=field_biography,field
_phone_number
Options:
--db-prefix Enable replacement of braces in sanitize queries.
--db-url A Drupal 6 style database URL. E.g., mysql://root:[email protected]/db
--sanitize-email The pattern for test email addresses in the sanitization operation, or "no" to keep email addresses unchanged. May contain replacement patterns %uid, %mail or %name. Example value: user+%uid@localhost
--sanitize-password The password to assign to all accounts in the sanitization operation, or "no" to keep passwords unchanged. Example value: password
--whitelist-fields A comma delimited list of fields exempt from sanitization.
Aliases: sqlsan
-
I would need to write hook_drush_sql_sync_sanitize() to also sanitize the user names.– ñullJan 17, 2018 at 19:27