You are here

drupagram.install in Drupagram 7

Same filename and directory in other branches
  1. 6 drupagram.install

Install, update and uninstall functions for the drupagram module.

File

drupagram.install
View source
<?php

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

/**
 * Implements hook_schema().
 */
function drupagram_schema() {

  /**
   * Instagram media objects have the following attributes:
   *
   * public id;
   * public user;
   * public type;
   * public images;
   * public location;
   * public comments;
   * public caption;
   * public link;
   * public likes;
   * public filter;
   * public created_time;
   */
  $schema['drupagram'] = array(
    'description' => "Stores individual Instagrams (media).",
    'fields' => array(
      'drupagram_id' => array(
        'description' => "Unique identifier for each {drupagram} post.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'username' => array(
        'description' => "Username of the {drupagram_account} user.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'type' => array(
        'description' => "The type of {drupagram} post.",
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => 'image',
      ),
      'images' => array(
        'description' => "The images available for the {drupagram} post. Serialied array.",
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
      'location' => array(
        'description' => "The location of the {drupagram} post.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
      'comments' => array(
        'description' => "The comments made on the {drupagram} post.",
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
      'caption' => array(
        'description' => "The caption of the {drupagram} post.",
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
      'link' => array(
        'description' => "The link to the {drupagram} post.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ),
      'likes' => array(
        'description' => "The link to the {drupagram} post.",
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
      'filter' => array(
        'description' => "The filter used on this {drupagram} post.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'created_at' => array(
        'description' => "Date and time the {drupagram} post was created.",
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'created_time' => array(
        'description' => "A duplicate of {drupagram}.created_at in UNIX timestamp format.",
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'username' => array(
        'username',
      ),
    ),
    'primary key' => array(
      'drupagram_id',
    ),
  );
  $schema['drupagram_local_image'] = array(
    'description' => "Stores references to the local image",
    'fields' => array(
      'path' => array(
        'description' => "The remote location of the locally cached image.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'file_object' => array(
        'description' => "The serialized array of the locally stored file",
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
    ),
    'indexes' => array(
      'path' => array(
        'path',
      ),
    ),
  );

  /**
   * Instagram user objects have the following attributes:
   *
   * public id;
   * public username;
   * public first_name;
   * public last_name;
   * public full_name;
   * public profile_picture;
   * public bio;
   * public website;
   * public media_count;
   * public follows_count;
   * public followed_by_count;
   * public follows;
   * public followed_by;
   * public url;
   */
  $schema['drupagram_account'] = array(
    'description' => "Stores information on specific Instagram user accounts.",
    'fields' => array(
      'drupagram_id' => array(
        'description' => "The unique identifier of the {drupagram_account}.",
        'type' => 'numeric',
        'unsigned' => TRUE,
        'precision' => 20,
        'scale' => 0,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => "The {users}.uid of the owner of this account",
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'big',
        'not null' => TRUE,
      ),
      'username' => array(
        'description' => "The unique login name of the {drupagram_account} user.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'password' => array(
        'description' => "The password for the Instagram account.",
        'type' => 'varchar',
        'length' => 64,
      ),
      '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,
      ),
      'full_name' => array(
        'description' => "The full name of the {drupagram_account} user.",
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'first_name' => array(
        'description' => "The first name of the {drupagram_account} user.",
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
        'default' => '',
      ),
      'last_name' => array(
        'description' => "The last name of the {drupagram_account} user.",
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
        'default' => '',
      ),
      'profile_picture' => array(
        'description' => "The url of the {drupagram_account}'s profile image.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'bio' => array(
        'description' => "The description/biography associated with the {drupagram_account}.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'website' => array(
        'description' => "The url of the {drupagram_account}'s home page.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'media_count' => array(
        'description' => "The total number of status updates performed by a user, excluding direct messages sent.",
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'follows_count' => array(
        'description' => "The number of users this {drupagram_account} is following.",
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'followed_by_count' => array(
        'description' => "The number of users following this {drupagram_account}.",
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'follows' => array(
        'description' => "The users this {drupagram_account} is following.",
        'type' => 'text',
        'not null' => FALSE,
      ),
      'followed_by' => array(
        'description' => "The users following this {drupagram_account}.",
        'type' => 'text',
        'not null' => FALSE,
      ),
      'url' => array(
        'description' => "The url of the {drupagram_account}'s Instagram page.",
        'type' => 'varchar',
        'length' => 255,
      ),
      'import' => array(
        'description' => "Boolean flag indicating whether the {drupagram_user}'s posts should be pulled in by the site.",
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'last_refresh' => array(
        'description' => "A UNIX timestamp marking the date Instagram 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,
      ),
    ),
    'indexes' => array(
      'username' => array(
        'username',
      ),
    ),
    'primary key' => array(
      'drupagram_id',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function drupagram_install() {

  // Set the weight to 3, making it heavier than Pathauto.
  db_update('system')
    ->fields(array(
    'weight' => 3,
  ))
    ->condition('type', 'module')
    ->condition('name', 'drupagram')
    ->execute();
  $drupagram_settings_link = l(st('here'), 'admin/config/services/drupagram');
  drupal_set_message(st('The drupagram module has been enabled. You must enter your API information !drupagram_settings_link', array(
    '!drupagram_settings_link' => $drupagram_settings_link,
  )));
}

/**
 * Implements hook_uninstall().
 */
function drupagram_uninstall() {

  // Remove variables
  variable_del('drupagram_import');
  variable_del('drupagram_expire');
  variable_del('drupagram_client_id');
  variable_del('drupagram_client_secret');
  variable_del('drupagram_post_types');
  variable_del('drupagram_host');
  variable_del('drupagram_post_default_format');
  variable_del('drupagram_signin_button');
  variable_del('drupagram_signin_register');
}

/**
 * Adds the drupagram_local_image table.
 */
function drupagram_update_7100() {
  $schema['drupagram_local_image'] = array(
    'description' => "Stores references to the local image",
    'fields' => array(
      'path' => array(
        'description' => "The remote location of the locally cached image.",
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'file_object' => array(
        'description' => "The serialized array of the locally stored file",
        'type' => 'text',
        'not null' => FALSE,
        'serialize' => TRUE,
      ),
    ),
    'indexes' => array(
      'path' => array(
        'path',
      ),
    ),
  );
  if (!db_table_exists('drupagram_local_image')) {
    db_create_table('drupagram_local_image', $schema['drupagram_local_image']);
    return st('Drupagram Local Image table was created successfully');
  }
  return st('There was an error creating the Drupagram Local Image table');
}

/**
 * Reload the schema changes.
 */
function drupagram_update_7101() {
  cache_clear_all('schema:runtime:', 'cache', TRUE);
  cache_clear_all('schema', 'cache');
}

Functions

Namesort descending Description
drupagram_install Implements hook_install().
drupagram_schema Implements hook_schema().
drupagram_uninstall Implements hook_uninstall().
drupagram_update_7100 Adds the drupagram_local_image table.
drupagram_update_7101 Reload the schema changes.