You are here

shoutbox_tags.install in Shoutbox 7

Install, update and uninstall functions for the shoutbox_tags module.

File

shoutbox_tags/shoutbox_tags.install
View source
<?php

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

/**
 * Implements hook_schema().
 */
function shoutbox_tags_schema() {
  $schema['shoutbox_tags'] = array(
    'description' => 'Link shouts to their tags',
    'fields' => array(
      'shout_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The shout id',
      ),
      'tag' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'The shout tag',
      ),
    ),
    'primary key' => array(
      'shout_id',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function shoutbox_tags_install() {

  // Load the module.
  module_load_include('module', 'shoutbox_tags');

  // Index all available shouts.
  $result = db_query("SELECT * FROM {shoutbox}");
  foreach ($result as $shout) {

    // Get the tags.
    $tags = shoutbox_tags_extract($shout);

    // Save the tags.
    foreach ($tags as $tag) {
      $id = db_insert('shoutbox_tags')
        ->fields(array(
        'shout_id' => $shout->shout_id,
        'tag' => $tag,
      ))
        ->execute();
    }
  }
}

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

/**
 * Update for Drupal 7.0.
 *
 * Drop the primary key so that a shout can have
 * multiple tags.
 */
function shoutbox_tags_update_7000() {
  db_drop_primary_key('shoutbox_tags');
}

Functions