You are here

function acquia_purge_update_7103 in Acquia Purge 7

Rename the 'purge notification' permission into 'purge on-screen'.

Since version 7.x-1.0, this permission got renamed as its name became too specific. Before it only reflected on the on-screen purging progress bar but is now also used for permission to the manual purge form blocks.

File

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

Code

function acquia_purge_update_7103(&$sandbox) {
  $old = 'purge notification';
  $new = 'purge on-screen';

  // Query the old 'purge notification' permission to rename it to the new one.
  $old_permissions = db_select('role_permission', 'r')
    ->fields('r')
    ->condition('permission', $old)
    ->execute();
  foreach ($old_permissions as $old_permission) {

    // Prevent duplicate entries by prequering if the new permission exists.
    $already_exists = db_select('role_permission', 'r')
      ->fields('r')
      ->condition('permission', $new)
      ->condition('module', $old_permission->module)
      ->condition('rid', $old_permission->rid)
      ->execute()
      ->fetchAssoc();
    if ($already_exists) {
      db_delete('role_permission')
        ->condition('permission', $old_permission->permission)
        ->condition('module', $old_permission->module)
        ->condition('rid', $old_permission->rid)
        ->execute();
    }
    else {
      db_update('role_permission')
        ->fields(array(
        'permission' => $new,
      ))
        ->condition('permission', $old_permission->permission)
        ->condition('module', $old_permission->module)
        ->condition('rid', $old_permission->rid)
        ->execute();
    }
  }

  // Asure the role permissions are reset.
  drupal_static_reset('user_role_permissions');
}