You are here

fb_app.install in Drupal for Facebook 6.2

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(FB_PATH_ADMIN),
  )));
}

/**
 * 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',
      ),
      '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;
}