You are here

function media_update_7200 in D7 Media 7.4

Same name and namespace in other branches
  1. 7.2 media.install \media_update_7200()
  2. 7.3 media.install \media_update_7200()

Replace 'view media' perm from all users having the role with 'view file'.

File

./media.install, line 553
Install, update and uninstall functions for the Media module.

Code

function media_update_7200() {
  $perms = user_permission_get_modules();
  if (!isset($perms['view files'])) {
    throw new DrupalUpdateException('The File Entity module needs to be upgraded before continuing.');
  }
  else {
    $roles = user_roles(FALSE, 'view media');
    $permissions = array(
      'view media' => FALSE,
      'view files' => TRUE,
    );
    foreach ($roles as $rid => $role) {
      user_role_change_permissions($rid, $permissions);
    }
    $roles = user_roles(FALSE, 'edit media');
    $permissions = array(
      'edit media' => FALSE,
      'edit any files' => TRUE,
    );
    if (function_exists('file_entity_list_permissions')) {
      unset($permissions['edit any files']);
      foreach (file_entity_permissions_get_configured_types() as $type) {
        $permissions += file_entity_list_permissions($type);
      }
    }
    foreach ($roles as $rid => $role) {
      user_role_change_permissions($rid, $permissions);
    }
    $roles = user_roles(FALSE, 'administer media');
    $permissions = array(
      'administer media' => FALSE,
      'administer files' => TRUE,
    );
    foreach ($roles as $rid => $role) {
      user_role_change_permissions($rid, $permissions);
    }
  }
}