如何通过drush将用户设置为特定角色?就我而言,我想将管理员角色授予用户。
如何通过drush将用户设置为特定角色?就我而言,我想将管理员角色授予用户。
Answers:
drush help user-add-role
Add a role to the specified user accounts.
Examples:
drush user-add-role "power user" 5,user3 Add the "power user" role to the accounts with name, id, or email 5 or user3, uids 2
--uid=2,3 --name=someguy,somegal and 3, names someguy and somegal, and email address of billgates@microsoft.com
--mail=billgates@microsoft.com
Arguments:
role The name of the role to add
users (optional) A comma delimited list of uids, user names, or email addresses.
Options:
--mail=<me@example.com> A comma delimited list of user mail addresses of users to operate on.
--name=<foo> A comma delimited list of user names of users to operate on.
--uid=<3,5> A comma delimited list of uids of users to operate on.
Aliases: urol
因此,对于您的用例:
drush user-add-role administrator USERNAME
首先,您需要像这样在users表中获取用户的ID(UID):
drush sqlq 'select * from users \Gamma'
我想要的uid是 uid = 444
然后通过执行以下操作,获取要分配给该用户的角色ID:
drush sqlq 'select * from role'
管理员角色摆脱= 3
现在我有了uid并摆脱了,我执行以下操作:
drush sqlq 'insert into users_roles (uid, rid) values (444, 3);'