1

I can create a user and add a user to a role from the command line:

$ drush user-create organizer1

$ drush user-add-role organizer organizer1
There is no role named: organizer

However, I don't know how to create a role from the command line.

I found this module to modify the perms of a role:

http://drupal.org/project/drush_role

But still I am not able to find a way to create a role

Freeman
  • 5,810
  • 3
  • 47
  • 48

5 Answers5

3

The answer is here: https://drupal.stackexchange.com/questions/56451/creating-a-new-user-role-with-drush

Summary is: update to the latest Drush to be able to do it.

Community
  • 1
  • 1
beth
  • 1,916
  • 4
  • 23
  • 39
1

Apparently thee is no drush command to do it. I have resolved it by accessing the database directly:

$ drush sql-query --db-prefix "INSERT INTO {role} (name, weight) VALUES('organizer', 3)"
test_command "sql-query --db-prefix \"INSERT INTO {role} (name, weight) VALUES('organizer', 3)\"" $?

$ drush sql-query --db-prefix "UPDATE {role} SET weight=4 WHERE (name='administrator')"

Please take into account that this solution only works for MySQL.

Freeman
  • 5,810
  • 3
  • 47
  • 48
0

Should be used by drush command.

drush user-add-role "power user" 5,user3  

Add the "power user" role to the accounts with name, id, or email 5 or user3

beth
  • 1,916
  • 4
  • 23
  • 39
Lalit Jain
  • 138
  • 7
0

This works for me in D7:

drush php-eval 'user_role_save((object) array("name"=>"administrator"));'

If you also want to make the new role the super-admin role:

drush php-eval 'variable_set("user_admin_role", end(array_keys(user_roles())))'; 

Afterwards, the following creates a new "super-admin" user:

drush user-create Dries --mail="dries@example.com" --password="iheartjoomla"
drush user-add-role administrator Dries
Dergachev
  • 348
  • 3
  • 6
0
drush rcrt 'test role'

Source: http://drushcommands.com/drush-7x/role/role-create

Mazzi
  • 939
  • 4
  • 12
  • 30