imagestyleflush.install 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * @file
  4. * Contains install and update functions for imagestyleflush.
  5. */
  6. /**
  7. * A new permission has been defined. Give it to all roles that currently
  8. * have the 'administer image styles' permission.
  9. */
  10. function imagestyleflush_update_7000() {
  11. // Since hook_update_N() can run on disabled modules, ensure the module
  12. // file is loaded so we can get the list of permissions.
  13. module_load_include('module', 'imagestyleflush', 'imagestyleflush');
  14. $permissions = array_keys(imagestyleflush_permission());
  15. // Get existing role_permissions.
  16. $rids = db_select('role_permission', 'rp')
  17. ->fields('rp', array('rid'))
  18. ->condition('permission', 'administer image styles')
  19. ->execute()
  20. ->fetchCol();
  21. // Add the permissions for each role.
  22. foreach ($rids as $rid) {
  23. foreach ($permissions as $name) {
  24. db_merge('role_permission')
  25. ->key(array(
  26. 'rid' => $rid,
  27. 'permission' => $name,
  28. ))
  29. ->fields(array(
  30. 'module' => 'imagestyleflush',
  31. ))
  32. ->execute();
  33. }
  34. }
  35. }