You are here

function acquia_purge_update_7106 in Acquia Purge 7

Introduce the new permission 'use manual purge blocks'.

Assign the new permission 'use manual purge blocks' to all roles already holding the 'purge on-screen' permission. The blocks used the latter first, but got its own permission as of version 7.x-1.2.

File

./acquia_purge.install, line 196
Installation file for the Acquia Purge module.

Code

function acquia_purge_update_7106(&$sandbox) {

  // See if there are roles that already have the new permission, unlikely.
  $rids_to_avoid = array();
  $roles_manualpurgeblocks = db_select('role_permission', 'r')
    ->fields('r')
    ->condition('permission', 'use manual purge blocks')
    ->execute();
  foreach ($roles_manualpurgeblocks as $role) {
    $rids_to_avoid[] = $role->rid;
  }

  // Get the roles that have 'purge on-screen' and assign them the new one.
  $roles_onscreen = db_select('role_permission', 'r')
    ->fields('r')
    ->condition('permission', 'purge on-screen')
    ->execute();
  foreach ($roles_onscreen as $role) {
    if (!in_array($role->rid, $rids_to_avoid)) {
      db_merge('role_permission')
        ->key(array(
        'rid' => $role->rid,
        'permission' => 'use manual purge blocks',
      ))
        ->fields(array(
        'module' => 'acquia_purge',
      ))
        ->execute();
    }
  }

  // Clear the user access cache.
  drupal_static_reset('user_access');
  drupal_static_reset('user_role_permissions');
}