You are here

tweet_feed.install in Tweet Feed 7

File

tweet_feed.install
View source
<?php

/**
 * Implements hook_schema().
 */
function tweet_feed_schema() {
  $schema['tweet_feed'] = array(
    'description' => 'A cache for twitter feeds.',
    'fields' => array(
      'tweet_id' => array(
        'description' => 'The twitter tweet id for this tweet.',
        'type' => 'int',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'tweet' => array(
        'description' => 'The text of the tweet.',
        'type' => 'text',
        'size' => 'normal',
        'not null' => TRUE,
      ),
      'created_at' => array(
        'description' => 'The date the tweet was posted (timestamp).',
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
      ),
      'user_id' => array(
        'description' => 'The user ID of the poster.',
        'type' => 'varchar',
        'length' => 24,
        'not null' => TRUE,
      ),
      'profile_image_url' => array(
        'description' => 'The URL of the image for the poster of this tweet.',
        'type' => 'text',
        'size' => 'normal',
        'not null' => FALSE,
      ),
      'profile_image_https_url' => array(
        'description' => 'The secure URL of the image for the poster of this tweet.',
        'type' => 'text',
        'size' => 'normal',
        'not null' => FALSE,
      ),
      'screen_name' => array(
        'description' => 'The screen name of the person tweeting.',
        'type' => 'varchar',
        'length' => 24,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'The name of the person tweeting',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'hashtags' => array(
        'description' => 'A comma separated list of hashtags without the hash.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'is_reply' => array(
        'description' => 'Is this tweet a reply to another?',
        'type' => 'int',
        'length' => 1,
        'not null' => TRUE,
        'default' => 0,
      ),
      'media_url' => array(
        'description' => 'The URL of the image for the poster of this tweet.',
        'type' => 'text',
        'size' => 'normal',
        'not null' => FALSE,
      ),
      'media_url_https' => array(
        'description' => 'The secure URL of the image for the poster of this tweet.',
        'type' => 'text',
        'size' => 'normal',
        'not null' => FALSE,
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 *
 * This is necessary because of our update hook 7109. we can't add a primary key to 
 * a field that is null. so we need to remove it from the schema on install and add 
 * it later for fresh installs
 */
function tweet_feed_install() {
  db_add_primary_key('tweet_feed', array(
    'tweet_id',
  ));
}

/**
 * Implements hook_uninstall().
 */
function tweet_feed_uninstall() {
  variable_del('tweet_feed_consumer_key');
  variable_del('tweet_feed_consumer_key');
  variable_del('tweet_feed_consumer_secret');
  variable_del('tweet_feed_oauth_token');
  variable_del('tweet_feed_oauth_token_secret');
  variable_del('tweet_feed_query_type');
  variable_del('tweet_feed_search_query');
  variable_del('tweet_feed_user_id');
  variable_del('tweet_feed_pull_count');
  variable_del('tweet_feed_new_window');
  variable_del('tweet_feed_truncate');
}

/**
 * Alter the user_id field to be a varchar for handling larger user id numbers.
 */
function tweet_feed_update_7104() {
  db_change_field('tweet_feed', 'user_id', 'user_id', array(
    'description' => 'The user ID of the poster',
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
  ));
}

/**
 * Convert system variable settings from twitter_ to tweet_feed_ 
 */
function tweet_feed_update_7105() {
  variable_set('tweet_feed_consumer_key', variable_get('twitter_consumer_key', NULL));
  variable_set('tweet_feed_consumer_secret', variable_get('twitter_consumer_secret', NULL));
  variable_set('tweet_feed_oauth_token', variable_get('twitter_oauth_token', NULL));
  variable_set('tweet_feed_oauth_token_secret', variable_get('twitter_oauth_token_secret', NULL));
  variable_set('tweet_feed_search_query', variable_get('twitter_search_query', NULL));
  variable_set('tweet_feed_pull_count', variable_get('twitter_pull_count', 50));
  variable_set('tweet_feed_new_window', variable_get('twitter_new_window', 0));
  variable_del('twitter_pull_count');
  variable_del('twitter_search_query');
  variable_del('twitter_oauth_token_secret');
  variable_del('twitter_oauth_token');
  variable_del('twitter_consumer_secret');
  variable_del('twitter_consumer_key');
  variable_del('twitter_new_window');
}

/**
 * Add a field to hold our comma delimited list of hashtags.
 */
function tweet_feed_update_7108() {
  $schema = tweet_feed_schema();
  db_add_field('tweet_feed', 'hashtags', $schema['tweet_feed']['fields']['hashtags']);
}

/**
 * Add a field to hold our tweet id's and remove the meaningless tid.
 */
function tweet_feed_update_7109() {
  $schema = tweet_feed_schema();
  if (db_field_exists('tweet_feed', 'tid')) {
    db_add_index('tweet_feed', 'tid', array(
      'tid',
    ));
    db_drop_primary_key('tweet_feed');
    db_drop_field('tweet_feed', 'tid');
  }
  if (!db_field_exists('tweet_feed', 'tweet_id')) {
    $id = 1;
    db_add_field('tweet_feed', 'tweet_id', $schema['tweet_feed']['fields']['tweet_id']);
    $result = db_query('SELECT created_at, user_id FROM {tweet_feed}');
    while ($data = $result
      ->fetchObject()) {
      db_update('tweet_feed')
        ->fields(array(
        'tweet_id' => $id++,
      ))
        ->condition('created_at', $data->created_at, '=')
        ->condition('user_id', $data->user_id, '=')
        ->execute();
    }
    db_add_primary_key('tweet_feed', array(
      'tweet_id',
    ));
  }
}

/**
 * Add the field for holding the secure profile image for SSL enabled web sites.
 */
function tweet_feed_update_7111() {
  $schema = tweet_feed_schema();
  if (!db_field_exists('tweet_feed', 'profile_image_https_url')) {
    db_add_field('tweet_feed', 'profile_image_https_url', $schema['tweet_feed']['fields']['profile_image_https_url']);
  }
}

/**
 * Add our flag to tweets that are replies and fields for media urls.
 */
function tweet_feed_update_7113() {
  $schema = tweet_feed_schema();
  if (!db_field_exists('tweet_feed', 'is_reply')) {
    db_add_field('tweet_feed', 'is_reply', $schema['tweet_feed']['fields']['is_reply']);
  }
  if (!db_field_exists('tweet_feed', 'media_url')) {
    db_add_field('tweet_feed', 'media_url', $schema['tweet_feed']['fields']['media_url']);
  }
  if (!db_field_exists('tweet_feed', 'media_url_https')) {
    db_add_field('tweet_feed', 'media_url_https', $schema['tweet_feed']['fields']['media_url_https']);
  }
}

/**
 * Add the field for holding the real name of the person tweeting.
 */
function tweet_feed_update_7115() {
  $schema = tweet_feed_schema();
  db_add_field('tweet_feed', 'name', $schema['tweet_feed']['fields']['name']);
}

Functions

Namesort descending Description
tweet_feed_install Implements hook_install().
tweet_feed_schema Implements hook_schema().
tweet_feed_uninstall Implements hook_uninstall().
tweet_feed_update_7104 Alter the user_id field to be a varchar for handling larger user id numbers.
tweet_feed_update_7105 Convert system variable settings from twitter_ to tweet_feed_
tweet_feed_update_7108 Add a field to hold our comma delimited list of hashtags.
tweet_feed_update_7109 Add a field to hold our tweet id's and remove the meaningless tid.
tweet_feed_update_7111 Add the field for holding the secure profile image for SSL enabled web sites.
tweet_feed_update_7113 Add our flag to tweets that are replies and fields for media urls.
tweet_feed_update_7115 Add the field for holding the real name of the person tweeting.