You are here

function taxonomy_access_enable in Taxonomy Access Control 7

Same name and namespace in other branches
  1. 5.2 taxonomy_access.module \taxonomy_access_enable()
  2. 5 taxonomy_access.module \taxonomy_access_enable()
  3. 6 taxonomy_access.module \taxonomy_access_enable()

Implements hook_enable().

Housekeeping: while we were away, did you delete any terms/vocabs/roles? 1: Weight this module below the Taxonomy module. 2: Delete ta, tad rows for missing roles. 3: Delete ta rows for missing terms. 4: Delete tad rows for missing vocabs.

File

./taxonomy_access.install, line 244
Install, update, and uninstall functions for Taxonomy Access Control.

Code

function taxonomy_access_enable() {

  // Weight this module below the Taxonomy module.
  $tax_weight = db_query("SELECT weight FROM {system}\n      WHERE name = 'taxonomy'")
    ->fetchField();
  db_update('system')
    ->fields(array(
    'weight' => $tax_weight + 1,
  ))
    ->condition('name', 'taxonomy_access')
    ->execute();

  // Delete any records for roles not in {roles}.
  $roles = _taxonomy_access_user_roles();
  $config_roles = db_query("SELECT DISTINCT rid FROM {taxonomy_access_default}")
    ->fetchCol();
  $missing_roles = array_diff($config_roles, array_keys($roles));

  // Core flags node access for rebuild on enable, so skip node updates.
  foreach ($missing_roles as $rid) {
    taxonomy_access_delete_role_grants($rid, FALSE);
  }

  // Delete any term configurations not in {taxonomy_term_data}.
  $term_ids = db_query("SELECT ta.tid\n      FROM {taxonomy_access_term} ta\n      LEFT JOIN {taxonomy_term_data} td ON ta.tid = td.tid\n      WHERE ta.tid <> :tid AND td.tid IS NULL", array(
    ':tid' => TAXONOMY_ACCESS_VOCABULARY_DEFAULT,
  ))
    ->fetchCol();

  // Core flags node access for rebuild on enable, so skip node updates.
  taxonomy_access_delete_term_grants($term_ids, NULL, FALSE);
  unset($term_ids);

  // Delete any defaults for vocabularies not in {taxonomy_vocabulary}.
  $vocab_ids = db_query("SELECT tad.vid\n      FROM {taxonomy_access_default} tad\n      LEFT JOIN {taxonomy_vocabulary} tv ON tad.vid = tv.vid\n      WHERE tad.vid <> :vid AND tv.vid IS NULL", array(
    ':vid' => TAXONOMY_ACCESS_GLOBAL_DEFAULT,
  ))
    ->fetchCol();

  // Core flags node access for rebuild on enable, so skip node updates.
  taxonomy_access_delete_default_grants($vocab_ids, FALSE);
  unset($vocab_ids);
}