Role6.php

  1. 8.0.x lib/Drush/Role/Role6.php
  2. 7.x lib/Drush/Role/Role6.php

Namespace

Drush\Role

Classes

Namesort descending Description
Role6

File

lib/Drush/Role/Role6.php
View source
  1. <?php
  2. namespace Drush\Role;
  3. class Role6 extends RoleBase {
  4. public $perms = array();
  5. public function getPerms() {
  6. if (empty($this->perms)) {
  7. $perms = db_result(db_query("SELECT perm FROM {permission} pm LEFT JOIN {role} r ON r.rid = pm.rid WHERE r.rid = '%d'", $this->rid));
  8. $role_perms = explode(", ", $perms);
  9. $this->perms = array_filter($role_perms);
  10. }
  11. return $this->perms;
  12. }
  13. public function getModulePerms($module) {
  14. return module_invoke($module, 'perm');
  15. }
  16. public function role_create($role_machine_name, $role_human_readable_name = '') {
  17. $this->_admin_user_role_op($role_machine_name, t('Add role'));
  18. return TRUE;
  19. }
  20. public function delete() {
  21. $this->_admin_user_role_op($this->rid, t('Delete role'));
  22. }
  23. function _admin_user_role_op($role_machine_name, $op) {
  24. // c.f. http://drupal.org/node/283261
  25. require_once(drupal_get_path('module', 'user') . "/user.admin.inc");
  26. $form_id = "user_admin_new_role";
  27. $form_values = array();
  28. $form_values["name"] = $role_machine_name;
  29. $form_values["op"] = $op;
  30. $form_state = array();
  31. $form_state["values"] = $form_values;
  32. drupal_execute($form_id, $form_state);
  33. }
  34. public function grant_permissions($perms_to_add) {
  35. $perms = $this->getPerms();
  36. $this->perms = array_unique(array_merge($this->perms, $perms_to_add));
  37. $this->updatePerms();
  38. }
  39. public function revoke_permissions($perms_to_remove) {
  40. $perms = $this->getPerms();
  41. $this->perms = array_diff($this->perms, $perms_to_remove);
  42. $this->updatePerms();
  43. }
  44. function updatePerms() {
  45. $new_perms = implode(", ", $this->perms);
  46. drush_op('db_query', "UPDATE {permission} SET perm = '%s' WHERE rid= %d", $new_perms, $this->rid);
  47. }
  48. }