You are here

twitter.install in Twitter 6.5

Install, update and uninstall functions for the twitter module.

File

twitter.install
View source
<?php

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

/**
 * Implements hook_requirements()
 */
function twitter_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'runtime') {

    // Verify that the Twitter Application keys are set.
    $requirements['twitter_keys'] = array(
      'title' => $t('Twitter Application keys'),
    );
    $consumer_key = variable_get('twitter_consumer_key', NULL);
    $consumer_secret = variable_get('twitter_consumer_secret', NULL);
    if (empty($consumer_key) || empty($consumer_secret)) {
      $requirements['twitter_keys']['value'] = $t('Missing');
      $requirements['twitter_keys']['description'] = $t('In order to interact with Twitter, you need to create an application at !twitter_dev and set the generated Application keys at the !twitter_settings_page.', array(
        '!twitter_dev' => l('https://dev.twitter.com', 'https://dev.twitter.com'),
        '!twitter_settings_page' => l($t('Twitter settings page'), 'admin/config/services/twitter'),
      ));
      $requirements['twitter_keys']['severity'] = REQUIREMENT_ERROR;
    }
    else {
      $requirements['twitter_keys']['value'] = $t('Configured');
      $requirements['twitter_keys']['severity'] = REQUIREMENT_OK;
    }

    // Verify that the OAuth module is installed and supported - if the
    // lib/OAuth.php file isn't available then the wrong version of OAuth is
    // installed.
    $path = drupal_get_path('module', 'oauth_common') . '/lib/OAuth.php';
    if (!file_exists($path)) {
      $requirements['twitter_oauth'] = array(
        'title' => $t('Twitter module requirements'),
        'severity' => REQUIREMENT_ERROR,
        'value' => $t('OAuth module v6.x-3.x is required'),
        'description' => $t('Upgrade to the latest v6.x-3.x release of the <a href="@oauth">OAuth module</a> in order for the Twitter module to work correctly, the v6.x-2.x releases will not work.', array(
          '@oauth' => 'https://www.drupal.org/project/oauth',
        )),
      );
    }
    else {
      $requirements['twitter_oauth'] = array(
        'title' => $t('Twitter module requirements'),
        'severity' => REQUIREMENT_OK,
        'value' => $t('OAuth module v6.x-3.x is installed'),
        'description' => $t('A compatible version of the OAuth module is installed.'),
      );
    }
  }
  return $requirements;
}

/**
 * Implements hook_schema().
 */
function twitter_schema() {
  $schema['twitter'] = array(
    'description' => "Stores individual Twitter posts.",
    'fields' => array(
      'twitter_id' => array(
        'description' => "Unique identifier for each {twitter} post.",
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'big',
        'not null' => TRUE,
        'default' => 0,
      ),
      'screen_name' => array(
        'description' => "Screen Name of the {twitter_account} user.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'created_at' => array(
        'description' => "Date and time the {twitter} post was created.",
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'created_time' => array(
        'description' => "A duplicate of {twitter}.created_at in UNIX timestamp format.",
        'type' => 'int',
        'not null' => TRUE,
      ),
      'text' => array(
        'description' => "The text of the {twitter} post.",
        // Using a blob instead of a text type make it possible for MySQL to
        // handle extended UTF8 characters, like emoji.
        // @see https://www.drupal.org/node/1910376
        'type' => 'blob',
        // Balance size vs performance. The August 2015 update allows for DMs
        // that are 10,000 characters in length, so in theory MySQL's default
        // blob length of 16KB should be enough.
        'size' => 'normal',
        'not null' => FALSE,
      ),
      'source' => array(
        'description' => "The application that created the {twitter} post.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'in_reply_to_status_id' => array(
        'description' => "Unique identifier of a status this {twitter} post was replying to.",
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'big',
        'not null' => FALSE,
        'default' => 0,
      ),
      'in_reply_to_user_id' => array(
        'description' => "Unique identifier for the {twitter_account} this post was replying to.",
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'big',
        'not null' => FALSE,
        'default' => 0,
      ),
      'in_reply_to_screen_name' => array(
        'description' => "Screen name of the {twitter} user this post was replying to.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'truncated' => array(
        'description' => "Boolean flag indicating whether the {twitter} status was cut off to fit in the 140 character limit.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'twitter_id',
    ),
    'indexes' => array(
      'screen_name' => array(
        'screen_name',
      ),
      'created_time' => array(
        'created_time',
      ),
    ),
  );
  $schema['twitter_account'] = array(
    'description' => "Stores information on specific Twitter user accounts.",
    'fields' => array(
      'twitter_uid' => array(
        'description' => "The unique identifier of the {twitter_account}.",
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'big',
        'not null' => TRUE,
        'default' => 0,
      ),
      'host' => array(
        'description' => 'The host for this account can be a laconi.ca instance',
        'type' => 'varchar',
        'length' => 255,
      ),
      'screen_name' => array(
        'description' => "The unique login name of the {twitter_account} user.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'oauth_token' => array(
        'description' => 'The token_key for oauth-based access.',
        'type' => 'varchar',
        'length' => 64,
      ),
      'oauth_token_secret' => array(
        'description' => 'The token_secret for oauth-based access.',
        'type' => 'varchar',
        'length' => 64,
      ),
      'name' => array(
        'description' => "The full name of the {twitter_account} user.",
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => "The description/biography associated with the {twitter_account}.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'location' => array(
        'description' => "The location of the {twitter_account}'s owner.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'followers_count' => array(
        'description' => "The number of users following this {twitter_account}.",
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'friends_count' => array(
        'description' => "The number of users this {twitter_account} is following.",
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'statuses_count' => array(
        'description' => "The total number of status updates performed by a user, excluding direct messages sent.",
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'favourites_count' => array(
        'description' => "The  number of statuses a user has marked as favorite.",
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'url' => array(
        'description' => "The url of the {twitter_account}'s home page.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'profile_image_url' => array(
        'description' => "The url of the {twitter_account}'s profile image.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'protected' => array(
        'description' => "Boolean flag indicating whether the {twitter_account}'s posts are publicly accessible.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'profile_background_color' => array(
        'description' => "hex RGB value for a user's background color",
        'type' => 'varchar',
        'length' => 6,
        'not null' => TRUE,
        'default' => '',
      ),
      'profile_text_color' => array(
        'description' => "hex RGB value for a user's text color",
        'type' => 'varchar',
        'length' => 6,
        'not null' => TRUE,
        'default' => '',
      ),
      'profile_link_color' => array(
        'description' => "hex RGB value for a user's link color",
        'type' => 'varchar',
        'length' => 6,
        'not null' => TRUE,
        'default' => '',
      ),
      'profile_sidebar_fill_color' => array(
        'description' => "hex RGB value for a user's sidebar color",
        'type' => 'varchar',
        'length' => 6,
        'not null' => TRUE,
        'default' => '',
      ),
      'profile_sidebar_border_color' => array(
        'description' => "hex RGB value for a user's border color",
        'type' => 'varchar',
        'length' => 6,
        'not null' => TRUE,
        'default' => '',
      ),
      'profile_background_image_url' => array(
        'description' => "The url of the {twitter_account}'s profile image.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'profile_background_tile' => array(
        'description' => "Boolean indicating if a user's background is tiled.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'verified' => array(
        'description' => "Indicates if a user is verified.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'created_at' => array(
        'description' => "Date and time the {twitter_account} was created.",
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'created_time' => array(
        'description' => "A duplicate of {twitter_account}.created_at in UNIX timestamp format.",
        'type' => 'int',
        'not null' => TRUE,
      ),
      'utc_offset' => array(
        'description' => "A duplicate of {twitter_account}.created_at in UNIX timestamp format.",
        'type' => 'int',
        'not null' => TRUE,
      ),
      'import' => array(
        'description' => "Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'mentions' => array(
        'description' => "Boolean flag indicating whether the {twitter_user}'s mentions should be pulled in by the site.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'last_refresh' => array(
        'description' => "A UNIX timestamp marking the date Twitter statuses were last fetched on.",
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'is_global' => array(
        'description' => "Boolean flag indicating if this account is available for global use",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => "The uid of the user who added this Twitter account",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'screen_name' => array(
        'screen_name',
      ),
      'uid' => array(
        'uid',
      ),
    ),
    'primary key' => array(
      'twitter_uid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function twitter_install() {
  drupal_install_schema('twitter');

  // Set the weight to 3, making it heavier than Pathauto.
  db_query("UPDATE {system} SET weight = 3 WHERE name = 'twitter'");
}

/**
 * Implements hook_uninstall()
 */
function twitter_uninstall() {

  // Remove tables.
  drupal_uninstall_schema('twitter');

  // Remove variables.
  variable_del('twitter_post_default_state');
  variable_del('twitter_consumer_key');
  variable_del('twitter_consumer_secret');
  variable_del('twitter_import');
  variable_del('twitter_expire');
  variable_del('twitter_host');
  variable_del('twitter_api');
  variable_del('twitter_search');
  variable_del('twitter_tinyurl');

  // These ones are generated by appending a content type, plus there
  // are two default ones
  $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'twitter_post_default_%'");
  while ($var_name = db_result($result)) {
    variable_del($var_name);
  }
  variable_del('twitter_signin_button');
  variable_del('twitter_signin_register');
  variable_del('twitter_use_default_views');
  variable_del('twitter_oauth_callback_url');
}

/**
 * Previous versions of the Twitter module had no database schema.
 * We're safe just running the basic install for update_1.
 */
function twitter_update_6000() {
  $ret = array();
  twitter_install();
  return $ret;
}

/**
 * Adding a handful of additional flags on accounts, and saving more metadata
 * when Twitter sends it to us.
 */
function twitter_update_6001() {
  $ret = array();
  $attributes = array(
    'description' => t("Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site."),
    'unsigned' => TRUE,
    'default' => 1,
    'not null' => TRUE,
  );
  db_add_column($ret, 'twitter_user', 'import', 'int', $attributes);
  $attributes = array(
    'description' => t("The location of the {twitter_account}'s owner."),
    'length' => 255,
  );
  db_add_column($ret, 'twitter_account', 'location', 'varchar(255)', $attributes);
  $attributes = array(
    'description' => t("The number of users following this {twitter_account}."),
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_column($ret, 'twitter_account', 'followers_count', 'int', $attributes);
  return $ret;
}

/**
 * Set the weight a little heavier to allow Pathauto and other modules to do
 * their work on the title, path alias, etc. before the twitter post is sent.
 */
function twitter_update_6002() {
  $ret = array();
  $ret[] = update_sql("UPDATE {system} SET weight = 3 WHERE name = 'twitter'");
  return $ret;
}

/**
 * Twitter status IDs are hitting the rollover point for signed ints. Let's
 * be sure we're ready. See http://bit.ly/kokvi for details.
 */
function twitter_update_6003() {
  $ret = array();
  db_drop_primary_key($ret, 'twitter');
  db_change_field($ret, 'twitter', 'twitter_id', 'twitter_id', array(
    'description' => t("Unique identifier for each {twitter} post."),
    'type' => 'int',
    'size' => 'big',
    'unsigned' => 'true',
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'twitter_id',
    ),
  ));
  return $ret;
}

/**
 * Add NOT NULL constraint and DEFAULT value to the screen_name field of the 
 * twitter and twitter_user tables per updated schema definition.
 *
 * @see https://www.drupal.org/node/336048
 * @see https://www.drupal.org/node/430442
 */
function twitter_update_6004() {
  $ret = array();

  // Have to drop PRIMARY KEY and indexes that use the field being changed.
  // twitter
  db_drop_index($ret, 'twitter', 'screen_name');
  db_change_field($ret, 'twitter', 'screen_name', 'screen_name', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ), array(
    'indexes' => array(
      'screen_name' => array(
        'screen_name',
      ),
    ),
  ));

  // twitter_user
  db_drop_index($ret, 'twitter_user', 'screen_name');
  db_drop_primary_key($ret, 'twitter_user');
  db_change_field($ret, 'twitter_user', 'screen_name', 'screen_name', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ), array(
    'primary key' => array(
      'uid',
      'screen_name',
    ),
    'indexes' => array(
      'screen_name' => array(
        'screen_name',
      ),
    ),
  ));
  return $ret;
}

/**
 * Dear PHP, I hate you so bad. Love, Jeff.
 *
 * Workaround for drupal_write_record(), which treats a DB bigint as a signed 32
 * bit int on 32 bit PHP builds. We can STORE bigints, and PHP automatically
 * converts them to floats in memory while we work with them, but db_placeholders()
 * always treats them as %d and casts them back to dumb signed ints.
 *
 * Instead we'll set the column type to 'string' which is a little like jumping
 * off the Sears Tower because the elevator's broken. But that's life.
 *
 * @see https://www.drupal.org/node/333788
 */
function twitter_update_6005() {
  $ret = array();

  // First clear out any borked statuses.
  $ret[] = update_sql("DELETE FROM {twitter} WHERE twitter_id = 2147483647");
  db_drop_primary_key($ret, 'twitter');
  db_change_field($ret, 'twitter', 'twitter_id', 'twitter_id', array(
    'description' => t("Unique identifier for each {twitter} post."),
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ), array(
    'primary key' => array(
      'twitter_id',
    ),
  ));
  return $ret;
}

/**
 * Dear PHP, I'm sorry baby. I know I said a lotta things last night, but I was
 * angry. I didn't mean it, you know that. I'll use numbers from now on -- no!
 * No, I'll use *decimals*. You'll like that, won't you, PHP? We're cool, right?
 *
 * Yeah. Yeah, we're cool.
 *
 * Also, while we're at it we'll add support for some of the additional Twitter
 * API data for replies, and convert the twitter_uid field to a numeric type, too.
 */
function twitter_update_6006() {
  $ret = array();
  db_drop_primary_key($ret, 'twitter');
  db_change_field($ret, 'twitter', 'twitter_id', 'twitter_id', array(
    'description' => t("Unique identifier for each {twitter} post."),
    'type' => 'numeric',
    'unsigned' => TRUE,
    'precision' => 20,
    'scale' => 0,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'primary key' => array(
      'twitter_id',
    ),
  ));
  db_add_field($ret, 'twitter', 'in_reply_to_status_id', array(
    'description' => t("Unique identifier of a status this {twitter} post was replying to."),
    'type' => 'numeric',
    'precision' => 20,
    'scale' => 0,
    'unsigned' => TRUE,
    'not null' => FALSE,
  ));
  db_add_field($ret, 'twitter', 'in_reply_to_user_id', array(
    'description' => t("Unique identifier for the {twitter_account} this post was replying to."),
    'type' => 'numeric',
    'precision' => 20,
    'scale' => 0,
    'unsigned' => TRUE,
    'not null' => FALSE,
  ));
  db_add_field($ret, 'twitter', 'in_reply_to_screen_name', array(
    'description' => t("Screen name of the {twitter} user this post was replying to."),
    'type' => 'varchar',
    'length' => 255,
    'not null' => FALSE,
  ));
  db_add_field($ret, 'twitter', 'truncated', array(
    'description' => t("Boolean flag indicating whether the {twitter} status was cut off to fit in the 140 character limit."),
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_drop_primary_key($ret, 'twitter_account');
  db_change_field($ret, 'twitter_account', 'twitter_uid', 'twitter_uid', array(
    'description' => t("The unique identifier of the {twitter_account}."),
    'type' => 'numeric',
    'unsigned' => TRUE,
    'precision' => 20,
    'scale' => 0,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'primary key' => array(
      'twitter_uid',
    ),
  ));
  return $ret;
}

/**
 * Update the last_refresh column to supply a default value.
 *
 * @see https://www.drupal.org/node/301317
 */
function twitter_update_6007() {
  $ret = array();
  db_change_field($ret, 'twitter_account', 'last_refresh', 'last_refresh', array(
    'description' => t("A UNIX timestamp marking the date Twitter statuses were last fetched on."),
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Update from 2.x to 3.x 
 */
function twitter_update_6300() {
  $ret = array();

  // add additional fields to {twitter_account}
  db_add_field($ret, 'twitter_account', 'uid', array(
    'description' => t("The {users}.uid of the owner of this account"),
    'type' => 'int',
    'unsigned' => TRUE,
    'size' => 'big',
    'not null' => TRUE,
  ));
  db_add_field($ret, 'twitter_account', 'host', array(
    'description' => t('The host for this account can be a laconi.ca instance'),
    'type' => 'varchar',
    'length' => 255,
  ));
  db_add_field($ret, 'twitter_account', 'password', array(
    'description' => t("The password for the Twitter account."),
    'type' => 'varchar',
    'length' => 64,
  ));
  db_add_field($ret, 'twitter_account', 'oauth_token', array(
    'description' => t('The token_key for oauth-based access.'),
    'type' => 'varchar',
    'length' => 64,
  ));
  db_add_field($ret, 'twitter_account', 'oauth_token_secret', array(
    'description' => t('The token_secret for oauth-based access.'),
    'type' => 'varchar',
    'length' => 64,
  ));
  db_add_field($ret, 'twitter_account', 'friends_count', array(
    'description' => t("The number of users this {twitter_account} is following."),
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field($ret, 'twitter_account', 'statuses_count', array(
    'description' => t("The total number of status updates performed by a user, excluding direct messages sent."),
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field($ret, 'twitter_account', 'favourites_count', array(
    'description' => t("The  number of statuses a user has marked as favorite."),
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field($ret, 'twitter_account', 'profile_background_color', array(
    'description' => t("hex RGB value for a user's background color"),
    'type' => 'varchar',
    'length' => 6,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'twitter_account', 'profile_text_color', array(
    'description' => t("hex RGB value for a user's text color"),
    'type' => 'varchar',
    'length' => 6,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'twitter_account', 'profile_link_color', array(
    'description' => t("hex RGB value for a user's link color"),
    'type' => 'varchar',
    'length' => 6,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'twitter_account', 'profile_sidebar_fill_color', array(
    'description' => t("hex RGB value for a user's sidebar color"),
    'type' => 'varchar',
    'length' => 6,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'twitter_account', 'profile_sidebar_border_color', array(
    'description' => t("hex RGB value for a user's border color"),
    'type' => 'varchar',
    'length' => 6,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'twitter_account', 'profile_background_image_url', array(
    'description' => t("The url of the {twitter_account}'s profile image."),
    'type' => 'varchar',
    'length' => 255,
  ));
  db_add_field($ret, 'twitter_account', 'profile_background_tile', array(
    'description' => t("Boolean indicating if a user's background is tiled."),
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 1,
  ));
  db_add_field($ret, 'twitter_account', 'verified', array(
    'description' => t("Indicates if a user is verified."),
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 1,
  ));
  db_add_field($ret, 'twitter_account', 'created_at', array(
    'description' => t("Date and time the {twitter_account} was created."),
    'type' => 'varchar',
    'length' => 64,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'twitter_account', 'created_time', array(
    'description' => t("A duplicate of {twitter_account}.created_at in UNIX timestamp format."),
    'type' => 'int',
    'not null' => TRUE,
  ));
  db_add_field($ret, 'twitter_account', 'utc_offset', array(
    'description' => t("A duplicate of {twitter_account}.created_at in UNIX timestamp format."),
    'type' => 'int',
    'not null' => TRUE,
  ));
  db_add_field($ret, 'twitter_account', 'import', array(
    'description' => t("Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site."),
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 1,
  ));
  db_add_field($ret, 'twitter_account', 'is_global', array(
    'description' => t("Boolean flag indicating if this account is available for global use"),
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  if (db_table_exists('twitter_user')) {
    $result = db_query("SELECT * FROM {twitter_user} ORDER BY uid DESC");
    while ($row = db_fetch_array($result)) {
      db_query("UPDATE {twitter_account} SET uid=%d, password='%s', import=%d WHERE screen_name='%s'", $row['uid'], $row['password'], $row['import'], $row['screen_name']);
    }
    db_drop_table($ret, 'twitter_user');
  }
  drupal_install_modules(array(
    'twitter_post',
  ));
  return $ret;
}
function twitter_update_6301() {
  $ret = array();

  // add additional fields to {twitter_account}
  db_add_field($ret, 'twitter_account', 'include_retweets', array(
    'description' => t("Boolean flag indicating whether the {twitter_user}'s retweets should be pulled in by the site. Currently does not support native retweets."),
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Update new default_state variable to preserve existing settings.
 */
function twitter_update_6302() {
  $ret = array();
  $default_seting = variable_get('twitter_default_state', NULL);
  if ($default_setting === NULL) {
    variable_set('twitter_post_default_state', 'create');
  }
  return $ret;
}

/**
 * Remove passwords no longer stored/used.
 */
function twitter_update_6303() {
  $ret = array();
  db_drop_field($ret, 'twitter_account', 'password');
  return $ret;
}

/**
 * Removes include_retweets field.
 */
function twitter_update_6500() {
  $ret = array();
  if (db_column_exists('twitter_account', 'include_retweets')) {
    db_drop_field($ret, 'twitter_account', 'include_retweets');
  }
  return $ret;
}

/**
 * Adds field mentions to twitter_account table.
 */
function twitter_update_6501() {
  $ret = array();
  $data = array(
    'description' => "Boolean flag indicating whether the {twitter_user}'s mentions should be pulled in by the site.",
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_field($ret, 'twitter_account', 'mentions', $data);
  return $ret;
}

/**
 * Drops field uid at twitter_account.
 *
 * This update has been set empty afterwards as the field is actually needed.
 */
function twitter_update_6502() {
}

/**
 * Makes the import field not enabled by default at twitter_account table.
 */
function twitter_update_6503() {
  $ret = array();
  $spec = array(
    'description' => "Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site.",
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_change_field($ret, 'twitter_account', 'import', 'import', $spec);
  return $ret;
}

/**
 * Adds field added_by_uid to twitter_account table.
 */
function twitter_update_6504() {
  $ret = array();
  $data = array(
    'description' => "The uid of the user who added this Twitter account",
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_field($ret, 'twitter_account', 'added_by_uid', $data);
  return $ret;
}

/**
 * Renames twitter_account.added_by_uid to twitter_account.uid.
 *
 * If the {twitter_account}.uid field already exists, don't do anything.
 */
function twitter_update_6505() {
  $ret = array();

  // If there is no {twitter_account}.uid field, add it.
  if (!db_column_exists('twitter_account', 'uid')) {
    $spec = array(
      'description' => "The uid of the user who added this Twitter account",
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    );

    // If the 'added_by_uid' field exists, as was added by update 6504 and needs
    // to be renamed.
    if (db_column_exists('twitter_account', 'added_by_uid')) {
      db_change_field($ret, 'twitter_account', 'added_by_uid', 'uid', $spec);
    }
    else {
      db_add_field($ret, 'twitter_account', 'uid', $spec);
    }
  }
  return $ret;
}

/**
 * Convert the twitter_id to a BIGINT. Yes, this is going back to how it was in
 * twitter_update_6003(). Sorry.
 */
function twitter_update_6506() {
  $ret = array();
  $spec = array(
    'description' => t("Unique identifier for each {twitter} post."),
    'type' => 'int',
    'unsigned' => TRUE,
    'size' => 'big',
    'not null' => TRUE,
    'default' => 0,
  );
  $keys = array(
    'primary key' => array(
      'twitter_id',
    ),
  );

  // Drop the existing primary key.
  db_drop_primary_key($ret, 'twitter');

  // Adjust the table, adding back the primary key again.
  db_change_field($ret, 'twitter', 'twitter_id', 'twitter_id', $spec, $keys);
  return $ret;
}

/**
 * Update the twitter_account.uid column to accept NULL values.
 */
function twitter_update_6507() {
  $ret = array();
  $spec = array(
    'description' => "The uid of the user who added this Twitter account.",
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
    'default' => 0,
  );
  db_change_field($ret, 'twitter_account', 'uid', 'uid', $spec);
  return $ret;
}

/**
 * Change {twitter}.in_reply_to_status_id to BIGINT.
 */
function twitter_update_6508() {
  $ret = array();
  $spec = array(
    'description' => "Unique identifier of a status this {twitter} post was replying to.",
    'type' => 'int',
    'unsigned' => TRUE,
    'size' => 'big',
    'not null' => FALSE,
    'default' => 0,
  );
  db_change_field($ret, 'twitter', 'in_reply_to_status_id', 'in_reply_to_status_id', $spec);
  return $ret;
}

/**
 * Change {twitter}.in_reply_to_user_id to BIGINT.
 */
function twitter_update_6509() {
  $ret = array();
  $spec = array(
    'description' => "Unique identifier for the {twitter_account} this post was replying to.",
    'type' => 'int',
    'unsigned' => TRUE,
    'size' => 'big',
    'not null' => FALSE,
    'default' => 0,
  );
  db_change_field($ret, 'twitter', 'in_reply_to_user_id', 'in_reply_to_user_id', $spec);
  return $ret;
}

/**
 * Change {twitter_account}.twitter_uid to BIGINT.
 */
function twitter_update_6510() {
  $ret = array();
  db_drop_primary_key($ret, 'twitter_account');
  $spec = array(
    'description' => "The unique identifier of the {twitter_account}.",
    'type' => 'int',
    'unsigned' => TRUE,
    'size' => 'big',
    'not null' => TRUE,
    'default' => 0,
  );
  $index_spec = array(
    'primary key' => array(
      'twitter_uid',
    ),
  );
  db_change_field($ret, 'twitter_account', 'twitter_uid', 'twitter_uid', $spec, $index_spec);
  return $ret;
}

/**
 * Change Twitter text field to blob to accommodate utf8mb4 characters.
 *
 * @todo This schema update is a workaround and should be reverted as soon as
 *   Drupal's MySQL implementation properly supports the utf8mb4 character set.
 *   However, it's unlikely that D6 will be updated to support this.
 *
 * @see https://www.drupal.org/node/1910376
 */
function twitter_update_6511() {
  $ret = array();
  $spec = array(
    'description' => "The text of the {twitter} post.",
    // Using a blob instead of a text type make it possible for MySQL to
    // handle extended UTF8 characters, like emoji.
    // @see https://www.drupal.org/node/1910376
    'type' => 'blob',
    // Balance size vs performance. The August 2015 update allows for DMs
    // that are 10,000 characters in length, so in theory MySQL's default
    // blob length of 16KB should be enough.
    'size' => 'normal',
    'not null' => FALSE,
  );
  db_change_field($ret, 'twitter', 'text', 'text', $spec);
  return $ret;
}

/**
 * Replaced by update 7511.
 */
function twitter_update_6512() {
  $ret = array();

  // This is used to clear the caches. However, because update 7511 also runs
  // it, remove this one so that any site that runs both updates won't
  // inadvertently rebuild the menu multiple times, which can be a huge
  // performance drain.
  // menu_rebuild();
  return $ret;
}

/**
 * Add an extra index on {twitter}.created_time.
 */
function twitter_update_6513() {
  $ret = array();
  db_add_index($ret, 'twitter', 'created_time', array(
    'created_time',
  ));
  return $ret;
}

/**
 * Add the new "administer twitter" permission to all roles that have the
 * "administer site configuration" permission.
 */
function twitter_update_6514() {
  $ret = array();
  $result = db_query("SELECT rid\n    FROM {permission}\n    WHERE perm = 'administer site configuration'");
  while ($row = db_fetch_object($result)) {
    $record = new StdClass();
    $record->rid = $row->rid;
    $record->perm = 'administer twitter';
    $record->tid = 0;
    drupal_write_record('permission', $record);
  }

  // Also reload the menus so the new permission is adopted.
  menu_rebuild();
  return $ret;
}

/**
 * Add index on {twitter_account}.uid.
 */
function twitter_update_6515() {
  $ret = array();
  db_add_index($ret, 'twitter_account', 'uid', array(
    'uid',
  ));
  return $ret;
}

/**
 * Updates twitter_search variable to point to https://twitter.com/ if they
 * still point to the unsecured URL.
 */
function twitter_update_6516() {
  if (variable_get('twitter_search', 'https://twitter.com/') == 'http://twitter.com') {
    variable_set('twitter_search', 'https://twitter.com/');
  }
}

Functions

Namesort descending Description
twitter_install Implements hook_install().
twitter_requirements Implements hook_requirements()
twitter_schema Implements hook_schema().
twitter_uninstall Implements hook_uninstall()
twitter_update_6000 Previous versions of the Twitter module had no database schema. We're safe just running the basic install for update_1.
twitter_update_6001 Adding a handful of additional flags on accounts, and saving more metadata when Twitter sends it to us.
twitter_update_6002 Set the weight a little heavier to allow Pathauto and other modules to do their work on the title, path alias, etc. before the twitter post is sent.
twitter_update_6003 Twitter status IDs are hitting the rollover point for signed ints. Let's be sure we're ready. See http://bit.ly/kokvi for details.
twitter_update_6004 Add NOT NULL constraint and DEFAULT value to the screen_name field of the twitter and twitter_user tables per updated schema definition.
twitter_update_6005 Dear PHP, I hate you so bad. Love, Jeff.
twitter_update_6006 Dear PHP, I'm sorry baby. I know I said a lotta things last night, but I was angry. I didn't mean it, you know that. I'll use numbers from now on -- no! No, I'll use *decimals*. You'll like that, won't you, PHP?…
twitter_update_6007 Update the last_refresh column to supply a default value.
twitter_update_6300 Update from 2.x to 3.x
twitter_update_6301
twitter_update_6302 Update new default_state variable to preserve existing settings.
twitter_update_6303 Remove passwords no longer stored/used.
twitter_update_6500 Removes include_retweets field.
twitter_update_6501 Adds field mentions to twitter_account table.
twitter_update_6502 Drops field uid at twitter_account.
twitter_update_6503 Makes the import field not enabled by default at twitter_account table.
twitter_update_6504 Adds field added_by_uid to twitter_account table.
twitter_update_6505 Renames twitter_account.added_by_uid to twitter_account.uid.
twitter_update_6506 Convert the twitter_id to a BIGINT. Yes, this is going back to how it was in twitter_update_6003(). Sorry.
twitter_update_6507 Update the twitter_account.uid column to accept NULL values.
twitter_update_6508 Change {twitter}.in_reply_to_status_id to BIGINT.
twitter_update_6509 Change {twitter}.in_reply_to_user_id to BIGINT.
twitter_update_6510 Change {twitter_account}.twitter_uid to BIGINT.
twitter_update_6511 Change Twitter text field to blob to accommodate utf8mb4 characters.
twitter_update_6512 Replaced by update 7511.
twitter_update_6513 Add an extra index on {twitter}.created_time.
twitter_update_6514 Add the new "administer twitter" permission to all roles that have the "administer site configuration" permission.
twitter_update_6515 Add index on {twitter_account}.uid.
twitter_update_6516 Updates twitter_search variable to point to https://twitter.com/ if they still point to the unsecured URL.