You are here

hashtags.install in Hashtags 7

Install, update and uninstall functions for the hashtags module.

File

hashtags.install
View source
<?php

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

/**
* Implementation of hook_enable().
*/
function hashtags_enable() {
  $vocabulary = taxonomy_vocabulary_load(variable_get('hashtags_vocabulary', 0));
  if (!$vocabulary) {
    $edit = array(
      'name' => t('Hashtags'),
      'machine_name' => 'hashtags',
      'description' => t('Hashtag vocabulary'),
      'hierarchy' => 1,
      'module' => 'hashtags',
      'weight' => -11,
    );
    $vocabulary = (object) $edit;
    taxonomy_vocabulary_save($vocabulary);
    variable_set('hashtags_vocabulary', $vocabulary->vid);
  }
  $field_name = 'field_' . $vocabulary->machine_name;
  if (!field_info_field($field_name)) {
    $field = array(
      'field_name' => $field_name,
      'type' => 'taxonomy_term_reference',
      // Set cardinality to unlimited for tagging.
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'settings' => array(
        'allowed_values' => array(
          array(
            'vocabulary' => $vocabulary->machine_name,
            'parent' => 0,
          ),
        ),
      ),
    );
    field_create_field($field);
    variable_set('hashtags_terms_field', $field_name);
    hashtags_add_filter();
    drupal_set_message('Hashtags module: go to ' . l(t('hashtags configuration page'), 'admin/config/content/hashtags') . ', check content types that you want Hashtags to work and submit a form');
  }
}

/**
* Implementation of hook_uninstall().
*/
function hashtags_uninstall() {
  drupal_load('module', 'taxonomy');
  $vid = variable_get('hashtags_vocabulary', '');
  $field_name = variable_get('hashtags_terms_field', '');
  field_delete_field($field_name);
  taxonomy_vocabulary_delete($vid);

  // Purge field data now to allow taxonomy module to be uninstalled
  // if this is the only field remaining.
  field_purge_batch(11);
  variable_del('hashtags_vocabulary');
  variable_del('hashtags_terms_field');
  variable_del('hashtags_output_type');

  // Remove Hashtags filter out of all input formats
  $module = 'hashtags';
  db_query("DELETE FROM {filter} WHERE module = :module", array(
    ':module' => $module,
  ));

  // clear filter caches
  filter_formats_reset();
  drupal_set_message(t('Hashtags filter has been removed from all input format'));
  watchdog('Input format', t('Hashtags filter has been removed from all input format'));
}

/**
 * Implementation of hook_schema().
 */
function hashtags_schema() {
  $schema['hashtags_index'] = array(
    'description' => 'Stores relation between nodes (entites), terms and comments of the nodes',
    'fields' => array(
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The tid of hashtag',
      ),
      'entity_id' => array(
        'description' => 'The id of entity (node) that contains Hashtags field',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'type' => array(
        'description' => 'The entity bundle.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'comment_id' => array(
        'description' => 'Sum of same hashtags that are used for current entity
        and its comments',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => NULL,
      ),
    ),
    'indexes' => array(
      'entity_tid' => array(
        'entity_id',
        'type',
        'tid',
      ),
      'entity_id' => array(
        'entity_id',
      ),
      'comment_id' => array(
        'comment_id',
      ),
    ),
  );
  return $schema;
}

/**
 * Integrate Hashtag filter with Filter HTML and Full HTML 
 * input formats.
 */
function hashtags_update_7001() {

  // add Hashtags filter to system input formats
  hashtags_add_filter();

  // this variable has been deleted from new version
  variable_del('hashtags_output_type');
}

/**
 * 1) Create a table for storing relations between hashtags, 
 * nodes and comments {hashtags_index}
 * 2) Update Hashtags taxonomy: clean hash symbol for all saved 
 * hashtags #hash1 => hash1
 * 3) Activate body fields for selected content types (that have 
 * Hashtags field attached)
 */
function hashtags_update_7002() {

  // create a hashtags_index table
  db_create_table('hashtags_index', drupal_get_schema('hashtags_index', 'hashtags_index'));

  // update terms in hashtags vocabulary - remove first # symbol
  hashtags_clean_hash_symbol();

  // activate hashtags for Body field for selected content types
  hashtags_fields_activate();

  // import hashtags data to index table
  hashtags_index_import();
}

Functions

Namesort descending Description
hashtags_enable Implementation of hook_enable().
hashtags_schema Implementation of hook_schema().
hashtags_uninstall Implementation of hook_uninstall().
hashtags_update_7001 Integrate Hashtag filter with Filter HTML and Full HTML input formats.
hashtags_update_7002 1) Create a table for storing relations between hashtags, nodes and comments {hashtags_index} 2) Update Hashtags taxonomy: clean hash symbol for all saved hashtags #hash1 => hash1 3) Activate body fields for selected content types (that have…