Make admin role and grant all permission

Public

Taken from the standard install profile that profiler_builder generates if you check the "make an admin role" box

Get raw version
php
  1. // Create a default role for site administrators, with all available permissions assigned.
  2. $admin_role = new stdClass();
  3. $admin_role->name = 'administrator';
  4. $admin_role->weight = 10;
  5. user_role_save($admin_role);
  6. user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
  7. // Set this as the administrator role.
  8. variable_set('user_admin_role', $admin_role->rid);
  9.  
  10. // Assign user 1 the "administrator" role.
  11. db_insert('users_roles')
  12. ->fields(array('uid' => 1, 'rid' => $admin_role->rid))
  13. ->execute();