You are here

fb_app.install in Drupal for Facebook 6.3

Installs database tables and settings required by fb_app module.

File

fb_app.install
View source
<?php

/**
 * @file
 * Installs database tables and settings required by fb_app module.
 *
 */

/**
 * hook_install()
 */
function fb_app_install() {

  // Create tables.
  drupal_install_schema('fb_app');
  drupal_set_message(st('Facebook Application module installed. Please grant yourself <a href="!perm">permissions</a> and then browse to <a href="!create">Admin >> Facebook Applications</a> to get started.', array(
    '!perm' => url('admin/user/permissions'),
    '!create' => url('admin/build/fb'),
  )));
}

/**
 * hook_uninstall()
 */
function fb_app_uninstall() {

  // Remove tables.
  drupal_uninstall_schema('fb_app');
}
function fb_app_schema() {
  $schema['fb_app'] = array(
    'description' => 'Main fb_app table',
    'fields' => array(
      'fba_id' => array(
        'description' => 'The primary identifier for an app.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'status' => array(
        'description' => 'Boolean indicating whether the app is enabled.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      // nid for backward-compatibility only.  DEPRECATED and will be removed!
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'label' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'Unique textual id for app.',
      ),
      'apikey' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'Provided by facebook, copy and pasted by user',
      ),
      'id' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'Provided by facebook, copy and pasted by user',
      ),
      'secret' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'Provided by facebook, copy and pasted by user',
      ),
      'canvas' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'We learn this from facebook app properties, facebook now calls it namespace',
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'We learn this from facebook app properties',
      ),
      'data' => array(
        'type' => 'text',
        'size' => 'big',
        'description' => 'Module-specific additional settings.',
      ),
    ),
    'unique keys' => array(
      'apikey' => array(
        'apikey',
      ),
      'label' => array(
        'label',
      ),
    ),
    'primary key' => array(
      'fba_id',
    ),
  );
  return $schema;
}
function fb_app_update_6100() {

  // Add id field
  $ret = array();
  db_add_field($ret, 'fb_app', 'id', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  ));
  return $ret;
}
function fb_app_update_6101() {
  $ret = array();

  // The rid field is no longer used, and causes problems for databases in strict mode.
  db_drop_field($ret, 'fb_app', 'rid');

  // Other columns have been moved to fb_user.module, and are stored in data
  db_drop_field($ret, 'fb_app', 'require_login');
  db_drop_field($ret, 'fb_app', 'create_account');
  db_drop_field($ret, 'fb_app', 'unique_account');

  // canvas moved to fb_canvas.module
  db_drop_field($ret, 'fb_app', 'canvas');

  // BAD IDEA!  see update 6202
  return $ret;
}
function fb_app_update_6202() {

  // canvas is too important, let's support it.
  $ret = array();
  db_add_field($ret, 'fb_app', 'canvas', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  ));
  drupal_set_message(t('If any of your Facebook Applications support canvas pages, go to those applications, click edit and submit.  This must be done manually.  Sorry for the inconvenience.'));
  return $ret;
}
function fb_app_update_6203() {
  $ret = array();
  db_drop_primary_key($ret, 'fb_app');

  // replace primary key nid with fba_id.
  db_add_field($ret, 'fb_app', 'fba_id', array(
    'type' => 'int',
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array(
    'unique keys' => array(
      // This should have been a unique key all along.
      'label' => array(
        'label',
      ),
    ),
    'primary key' => array(
      'fba_id',
    ),
  ));
  return $ret;
}
function fb_app_update_6204() {
  $ret = array();
  db_add_field($ret, 'fb_app', 'status', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 1,
  ));
  $result = db_query("SELECT n.nid, n.status FROM {node} n WHERE type = 'fb_app'");
  while ($data = db_fetch_object($result)) {
    $ret[] = update_sql("UPDATE {fb_app} SET status = %d WHERE nid = %d", $data->status, $data->nid);
  }
  return $ret;
}
function fb_app_update_6205() {
  $ret = array();
  db_add_field($ret, 'fb_app', 'title', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  ));
  return $ret;
}
function fb_app_update_6206() {
  $ret = array();

  // Add default value to nid col.
  db_change_field($ret, 'fb_app', 'nid', 'nid', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}
function fb_app_update_6300() {
  $ret = array();
  fb_install_property_message($ret, st('Event callbacks have changed.'));
  return $ret;
}

/**
 * Change app labels to all lower case.
 *
 * This include some code specific to fb_connect.module (because easier to do here than fb_connect.install).
 */
function fb_app_update_6302() {
  $ret = array();
  $query = db_query("SELECT fba_id, label FROM {fb_app} ORDER BY fba_id");
  while ($app = db_fetch_object($query)) {

    //change label names to lowercase
    $label_old = $app->label;
    $label_new = strtolower($label_old);
    if ($label_old != $label_new) {

      // Change app name to lowercase.
      $ret[] = update_sql("UPDATE {fb_app} SET label = '{$label_new}' WHERE fba_id = {$app->fba_id}");
      drupal_set_message(t("Changed fb application name from %label_old to %label_new. Please adjust any custom code or settings which rely on app's label.", array(
        '%label_old' => $label_old,
        '%label_new' => $label_new,
      )), 'warning');

      // begin fb_connect.module settings which use label.
      if (variable_get('fb_connect_primary_label', NULL) == $label_old) {

        // Primary label has changed.
        variable_set('fb_connect_primary_label', $label_new);
      }

      // fb_connect.module blocks.
      $variable_name_old = 'fb_connect_block_login_' . $label_old;
      $variable_name_new = 'fb_connect_block_login_' . $label_new;
      $variable_content = variable_get($variable_name_old, NULL);
      variable_del($variable_name_old);
      if ($variable_content) {
        variable_set($variable_name_new, $variable_content);
      }

      // change deltas of blocks
      $old_delta = 'login_' . $label_old;
      $new_delta = 'login_' . $label_new;
      $ret[] = update_sql("UPDATE {blocks} SET delta = '{$new_delta}' WHERE (module = 'fb_connect' AND delta = '{$old_delta}')");

      // end fb_connect.module settings.
    }
  }
  return $ret;
}