You are here

taxonomy_permissions.install in Taxonomy Permissions 7

Same filename and directory in other branches
  1. 8 taxonomy_permissions.install

Install, update and uninstall functions for the taxonomy_permissions module.

File

taxonomy_permissions.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the taxonomy_permissions module.
 *
 */

/*
 * Implements hook_install().
 *
 * Give 'view terms' access to all vocabularies to all users to avoid surprises
 * upon installation.
 */
function taxonomy_permissions_install() {
  $perms = array();
  foreach (taxonomy_get_vocabularies() as $vocabulary) {
    $perms[] = 'view terms in ' . $vocabulary->machine_name;
  }
  user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, $perms);
  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $perms);
}

/*
 * Implements hook_disable().
 */
function taxonomy_permissions_disable() {

  // Re-register taxonomy.module's permissions under its own name to keep them
  // from being purged in case we're uninstalled.
  taxonomy_permissions_disabling(TRUE);
  module_implements('permission', FALSE, TRUE);
  cache_clear_all('module_implements', 'cache_bootstrap');
  $modules = user_permission_get_modules();
  $perms = user_role_permissions(user_roles());
  foreach ($perms as $rid => $perm) {
    foreach (array_keys($perm) as $p) {
      if (!isset($modules[$p]) || $modules[$p] != 'taxonomy') {
        unset($perm[$p]);
      }
    }
    user_role_change_permissions($rid, $perm);
  }
}

/*
 * Implements hook_uninstall().
 */
function taxonomy_permissions_uninstall() {
}

/**
 * Fix permission names.
 */
function taxonomy_permissions_update_7101() {
  foreach (taxonomy_get_vocabularies() as $vocabulary) {
    db_update('role_permission')
      ->condition('permission', 'view terms in ' . $vocabulary->vid)
      ->fields(array(
      'permission' => 'view terms in ' . $vocabulary->machine_name,
    ));
  }
  drupal_flush_all_caches();
}