You are here

termstatus.install in Taxonomy Term Status 7

Install, update and uninstall functions for the termstatus module.

File

termstatus.install
View source
<?php

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

/**
 * Implemets hook_enable().
 *
 * Disable term status per default in order to protect people from having all
 * their terms disappear when enabling the module. Do not disable the module
 * when installing into a pristine system - i.e. when there are no terms.
 */
function termstatus_enable() {
  $any_tid = db_query('SELECT tid FROM {taxonomy_term_data} LIMIT 1')
    ->fetchField();
  variable_set('termstatus_enable', empty($any_tid));
}

/**
 * Implements hook_uninstall().
 */
function termstatus_uninstall() {
  variable_del('termstatus_enable');
}

/**
 * Implements hook_requirements().
 */
function termstatus_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time.
  $t = get_t();
  if ($phase != 'install') {

    // Check if term status is enabled.
    if (!variable_get('termstatus_enable', FALSE)) {
      $requirements['taxonomy_term_status'] = array(
        'title' => $t('Taxonomy Term Status'),
        'value' => $t('Term status is not configured yet. First visit the <a href="@config_link">configuration page</a> in order to build the status records and then enable it.', array(
          '@config_link' => url('admin/config/system/termstatus'),
        )),
        'severity' => REQUIREMENT_WARNING,
      );
    }
    else {
      $requirements['taxonomy_term_status'] = array(
        'title' => $t('Taxonomy Term Status'),
        'value' => $t('Term status is configured and active. If the site is experiencing problems with visibility of taxonomy terms, you may have to rebuild the term status records using the <a href="@config_link">configuration page</a>.', array(
          '@config_link' => url('admin/config/system/termstatus'),
        )),
        'severity' => REQUIREMENT_OK,
      );
    }
  }
  return $requirements;
}

/**
 * Implements hook_schema().
 */
function termstatus_schema() {
  $schema['termstatus'] = array(
    'description' => 'The base table for termstatus.',
    'fields' => array(
      'tid' => array(
        'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'status' => array(
        'description' => 'Boolean indicating whether the term is published (visible to non-administrators).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'primary key' => array(
      'tid',
    ),
    'term_status' => array(
      'tid',
      'status',
    ),
    'foreign keys' => array(
      'taxonomy_term_data' => array(
        'table' => 'taxonomy_term_data',
        'columns' => array(
          'tid' => 'tid',
        ),
      ),
    ),
  );
  return $schema;
}

/**
 * Remove taxonomy_ prefix from variable names.
 */
function termstatus_update_7000() {
  if (variable_get('taxonomy_term_status_enable', FALSE)) {
    variable_set('termstatus_enable', TRUE);
  }
  variable_del('taxonomy_term_status_enable');
  $termstatus_vars = db_query("SELECT name FROM {variable} WHERE name LIKE 'taxonomy_termstatus_%'")
    ->fetchCol();
  foreach ($termstatus_vars as $old_name) {
    $new_name = substr($old_name, 9);
    variable_set($new_name, variable_get($old_name));
    variable_del($old_name);
  }
}

Functions

Namesort descending Description
termstatus_enable Implemets hook_enable().
termstatus_requirements Implements hook_requirements().
termstatus_schema Implements hook_schema().
termstatus_uninstall Implements hook_uninstall().
termstatus_update_7000 Remove taxonomy_ prefix from variable names.