Index: permissions_api/permissions_api.drush.inc =================================================================== --- permissions_api/permissions_api.drush.inc (revision 18883) +++ permissions_api/permissions_api.drush.inc (working copy) @@ -23,8 +23,10 @@ return dt("Copy permissions from one role to another."); case 'drush:perm-list': return dt("List permissions assigned to a role."); - case 'drush:perm-create': + case 'drush:role-create': return dt("Create a role."); + case 'drush:role-delete': + return dt("Delete a role."); } } @@ -87,17 +89,28 @@ ), ); - $items['perm-create'] = array( - 'callback' => 'drush_permissions_api_perm_create', + $items['role-create'] = array( + 'callback' => 'drush_permissions_api_role_create', 'description' => dt('Create a role.'), 'arguments' => array( 'role' => dt('The name of the role you are creating.'), ), 'examples' => array( - 'drush perm-create Admin' => dt('Create Admin role.'), + 'drush role-create Admin' => dt('Create Admin role.'), ), ); + $items['role-delete'] = array( + 'callback' => 'drush_permissions_api_role_delete', + 'description' => dt('Delete a role.'), + 'arguments' => array( + 'role' => dt('The name of the role you are deleting.'), + ), + 'examples' => array( + 'drush role-delete Admin' => dt('Delete Admin role.'), + ), + ); + $items['perm-list'] = array( 'callback' => 'drush_permissions_api_perm_list', 'description' => dt('List permissions for a role.'), @@ -168,10 +181,18 @@ } } -function drush_permissions_api_perm_create() { +function drush_permissions_api_role_create() { $args = func_get_args(); foreach($args as $role) { permissions_create_role($role); drush_print(dt('Role !role created.', array('!role' => $role))); } } + +function drush_permissions_api_role_delete() { + $args = func_get_args(); + foreach ($args as $role) { + permissions_delete_role($role); + drush_print(dt('Role !role deleted.', array('!role' => $role))); + } +} \ No newline at end of file Index: permissions_api/permissions_api.module =================================================================== --- permissions_api/permissions_api.module (revision 18883) +++ permissions_api/permissions_api.module (working copy) @@ -329,6 +329,29 @@ } /** + * Helper function to delete a role from the database. + * + * @param $role_name + * String representing the name of the role to be deleted, e.g. 'site administrator'. + * @return + * Returns either an object representing the newly created (or previously existing) role, or FALSE if there was an error + */ +function permissions_delete_role($role_name) { + // Look up the role to see if it exists already + $role = permissions_get_role($role_name); + if ($role) { + db_query('DELETE FROM {role} WHERE rid = %d', $role->rid); + db_query('DELETE FROM {permission} WHERE rid = %d', $role->rid); + // Update the users who have this role set: + db_query('DELETE FROM {users_roles} WHERE rid = %d', $role->rid); + watchdog('permissions_api', 'permissions_delete_role: role %rolename deleted', array('%rolename' => $role->name), WATCHDOG_NOTICE); + return $role; + } + watchdog('permissions_api', 'permissions_delete_role: role %rolename not found', array('%rolename' => $role_name), WATCHDOG_WARNING); + return FALSE; +} + +/** * This function allows a role to inherit either all the permissions of another role * * @param