The title is a bit misleading, as ‘programmatically’, in this case means just writing a simple SQL update query.
For our pushes to production, we never do configuration by hand. With Drupal, there is a lot of configuration that is stored in the db, so we script all of our configuration changes that are then run by our release process during a push to production, or to staging for our QA team to test.
One of the updates I had to do today was to update add permissions to a role. If you are not familiar with what permissions are or what roles are, log in to your Drupal site with an admin user and navigate to User Management –> Permissions (/admin/user/permissions). Permissions are listed as the left most column going down. Each of your roles are listed in the top row from left to right.
I just created a new module and need to grant permissions to administer that module to one of our site admin roles. To do this, I completed the following steps:
- Query my db to get the current permissions for my role – “SELECT perm FROM permission WHERE rid = 99;”*
- Add the following SQL update statement to a script file for running during release “UPDATE permission SET perm = ‘<text list of permissions returned in step one above>’ WHERE rid = 99′;”
* 99 is sample data. This would be replaced with the id of the role you would like to change.