You are here

function file_entity_update_7104 in File Entity (fieldable files) 7.3

Same name and namespace in other branches
  1. 7 file_entity.install \file_entity_update_7104()
  2. 7.2 file_entity.install \file_entity_update_7104()

Assign view file permission when updating without the Media module.

File

./file_entity.install, line 374
Install, update and uninstall functions for the file_entity module.

Code

function file_entity_update_7104() {
  if (!module_exists('media')) {
    $roles = user_roles(FALSE, 'view file');
    if (empty($roles)) {

      // Set permissions.
      $roles = user_roles();
      foreach ($roles as $rid => $role) {

        // Do not use user_role_grant_permission() since it relies on
        // hook_permission(), which will not run for file entity module if it
        // is disabled or the permission is renamed or removed.
        db_merge('role_permission')
          ->fields(array(
          'rid' => $rid,
          'permission' => 'view file',
          'module' => 'file_entity',
        ))
          ->condition('rid', $rid)
          ->condition('permission', 'view file')
          ->execute();
      }
    }
  }
}