You are here

fb_user.install in Drupal for Facebook 6.3

Install file for fb_user.module.

File

fb_user.install
View source
<?php

/**
 * @file
 * Install file for fb_user.module.
 *
 */

/**
 * Implementation of hook_install().
 */
function fb_user_install() {
  _fb_user_install_set_weight();

  // Create tables.
  drupal_install_schema('fb_user');
}

/**
 * Implementation of hook_uninstall().
 */
function fb_user_uninstall() {

  // Remove tables.
  drupal_uninstall_schema('fb_user');
  foreach (array(
    FB_USER_VAR_USERNAME_STYLE,
    FB_USER_VAR_ALTER_REGISTER,
    FB_USER_VAR_ALTER_LOGIN,
    FB_USER_VAR_ALTER_LOGIN_BLOCK,
    FB_USER_VAR_ALTER_CONTACT,
    FB_USER_VAR_TEXT_REGISTER,
    FB_USER_VAR_TEXT_LOGIN,
    FB_USER_VAR_TEXT_LOGIN_BLOCK,
  ) as $var) {
    variable_del($var);
  }
}

/**
 * Usually it is best if fb_user_form_alter acts before third party modules.
 * So, we lower the module weight here.
 */
function _fb_user_install_set_weight() {
  db_query("UPDATE {system} SET weight=-1 WHERE name='fb_user'");
}
function fb_user_schema() {

  // Note fb_user_app table has been moved to fb_user_app.module.
  $schema['fb_user'] = array(
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'fbu' => array(
        // http://forum.developers.facebook.net/viewtopic.php?pid=4676
        'type' => 'int',
        'size' => 'big',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'uid',
    ),
    'unique keys' => array(
      'fbu' => array(
        'fbu',
      ),
    ),
  );
  return $schema;
}

//// Note that update functions referring to fb_user_app table are old (through 6005), but not safe to delete from this file.
function fb_user_update_1() {
  fb_user_install();

  // Changed name of table to fb_user_app
  $ret[] = update_sql("DROP TABLE IF EXISTS {fb_app_user}");
  return $ret;
}
function fb_user_update_2() {
  $ret = array();

  // Add local uid to fb_user_app table.
  $ret[] = update_sql("ALTER TABLE {fb_user_app} ADD COLUMN uid int(11) DEFAULT NULL");
  $ret[] = update_sql("ALTER TABLE {fb_user_app} ADD INDEX (uid)");

  //$ret[] = update_sql("ALTER TABLE {fb_user_app} ADD UNIQUE INDEX (uid, apikey)");
  return $ret;
}
function fb_user_update_3() {

  // populate the uid column we created in update 2
  $ret[] = update_sql("UPDATE {fb_user_app},{authmap} SET {fb_user_app}.uid={authmap}.uid WHERE substring_index(authname, '@', 1)=fbu");
  return $ret;
}
function fb_user_update_6000() {
  $ret = array();

  // We used to alter users.mail column here, to make it long enough for proxied emails.  But we no longer do this, instead we store proxied email in the fb_user_app table.
  // See update 6001.
  return $ret;
}
function fb_user_update_6001() {
  $ret = array();

  // Add column for proxied email.
  // http://wiki.developers.facebook.com/index.php/Proxied_Email
  db_add_column($ret, 'fb_user_app', 'proxied_email', 'varchar(255)', array(
    'not null' => TRUE,
  ));
  return $ret;
}
function fb_user_update_6002() {
  $ret = array();

  // Allow session_key to be null, and 255 chars
  $ret[] = update_sql("ALTER TABLE {fb_user_app} CHANGE session_key session_key varchar(255)");

  // Allow NULL
  $ret[] = update_sql("ALTER TABLE {fb_user_app} CHANGE session_key_expires session_key_expires int(11)");
  return $ret;
}
function fb_user_update_6004() {
  $ret = array();

  // Increase FBU to 64 bit as per announcement at http://developers.facebook.com/news.php?blog=1&story=226
  db_drop_primary_key($ret, 'fb_user_app');
  db_change_field($ret, 'fb_user_app', 'fbu', 'fbu', array(
    'type' => 'int',
    'size' => 'big',
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'apikey',
      'fbu',
    ),
  ));
  return $ret;
}
function fb_user_update_6005() {
  $ret = array();

  // Making uid unique was a bad idea.  It can be 0.
  // One of the following should work, depending on whether the key was added during install or update.
  // The other will create a warning, unfortunately.
  db_drop_unique_key($ret, 'fb_user_app', 'apikey_uid');
  db_drop_unique_key($ret, 'fb_user_app', 'uid_2');
  db_drop_unique_key($ret, 'fb_user_app', 'uid_4');
  drupal_set_message(t('Note that if you see a warning about "Can\'t DROP ...", it is safe to ignore that message.  See fb_user.install.'));
  return $ret;
}

/**
 * Originally, we wrote authmap entries like 'NNNNN@facebook.com'.  This was
 * necessary in D5.  In D6 we can make queries more efficient using just the
 * fbu ('NNNNN') as the authname, and 'fb_user' as the module.
 */
function fb_user_update_6006() {
  $ret = array();

  // Update authmap entries.  We no longer use '@facebook...'.
  $ret[] = update_sql("UPDATE {authmap} SET authname=SUBSTRING(authname, 1, LOCATE('@facebook.com', authname)-1) WHERE module='fb_user' AND LOCATE('@facebook.com', authname) > 1");
  return $ret;
}

/**
 * Install fb_user table and move entries in authmap table to fb_user.
 */
function fb_user_update_6007() {
  $table_schema = fb_user_schema();
  $ret = '';
  db_create_table($ret, 'fb_user', $table_schema['fb_user']);

  // Move everything across
  $sql = "INSERT INTO {fb_user} SELECT uid, authname FROM {authmap} WHERE module = 'fb_user'";
  $ret[] = update_sql($sql);

  // Delete authmap table entries, careful to only delete after above insert.
  $sql = "DELETE FROM {authmap} WHERE module = 'fb_user' AND uid IN (SELECT uid FROM {fb_user})";
  $ret[] = update_sql($sql);
  return $ret;
}
function fb_user_update_6008() {
  $ret = array();
  $message = 'Manual action required!  If you have a custom implementation of hook_fb() which responds to user operations (i.e. FB_OP_PRE_USER or FB_OP_POST_USER), those operations have been moved to a new hook, hook_fb_user().  You will have to edit your code.';
  $args = array();
  drupal_set_message(t($message, $args), 'warning', FALSE);
  watchdog('fb_user', $message, $args, WATCHDOG_WARNING);
  $ret[] = array(
    'success' => FALSE,
    'query' => $message,
    array(),
  );
  return $ret;
}
function fb_user_update_6009() {
  $ret = array();
  _fb_user_install_set_weight();
  $message = 'Lowered weight of fb_user.module, so that its hooks will be invoked before third-party modules.';
  $args = array();
  drupal_set_message(t($message, $args), 'warning', FALSE);
  watchdog('fb_user', $message, $args, WATCHDOG_WARNING);
  $ret[] = array(
    'success' => TRUE,
    'query' => $message,
    array(),
  );
  return $ret;
}

Functions

Namesort descending Description
fb_user_install Implementation of hook_install().
fb_user_schema
fb_user_uninstall Implementation of hook_uninstall().
fb_user_update_1
fb_user_update_2
fb_user_update_3
fb_user_update_6000
fb_user_update_6001
fb_user_update_6002
fb_user_update_6004
fb_user_update_6005
fb_user_update_6006 Originally, we wrote authmap entries like 'NNNNN@facebook.com'. This was necessary in D5. In D6 we can make queries more efficient using just the fbu ('NNNNN') as the authname, and 'fb_user' as the module.
fb_user_update_6007 Install fb_user table and move entries in authmap table to fb_user.
fb_user_update_6008
fb_user_update_6009
_fb_user_install_set_weight Usually it is best if fb_user_form_alter acts before third party modules. So, we lower the module weight here.