You are here

amazon.install in Amazon Product Advertisement API 7

Same filename and directory in other branches
  1. 6 amazon.install
  2. 7.2 amazon.install

Install, update and uninstall functions for the amazon module.

File

amazon.install
View source
<?php

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

/**
 * Implements hook_install.
 */
function amazon_install() {
}

/**
 * Implements hook_uninstall().
 */
function amazon_uninstall() {
  $vars = array(
    'amazon_media_data',
    'amazon_locale',
    'amazon_associate_setting',
    'amazon_custom_associate_id',
    'amazon_aws_access_key',
    'amazon_aws_secret_access_key',
    'amazon_refresh_schedule',
    'amazon_core_data',
  );
  foreach ($vars as $var) {
    variable_del($var);
  }
}

/**
 * implementation of hook_requirements to make sure we let them know about
 * the requirement for amazon_aws_secret_access_key
 * @param $phase
 * @return A $requirement[] array, or NULL if there are no issues.
 */
function amazon_requirements($phase) {
  if ($phase != 'runtime') {
    return;
  }
  $secret_access_key = variable_get('amazon_aws_secret_access_key', "");
  $api_key = variable_get('amazon_aws_access_key', "");
  $associate_tag = amazon_get_associate_id();
  if (empty($secret_access_key) || empty($api_key) || empty($associate_tag)) {
    drupal_set_message(t("The Amazon API must be configured with an Associate Tag, an Access Key ID and an Amazon AWS Secret Access Key to function. Go to !settings.", array(
      "!settings" => l(t("Amazon API Setttings"), 'admin/config/services/amazon'),
    )));
    $requirement['title'] = t("Amazon AWS Settings");
    $requirement['severity'] = REQUIREMENT_WARNING;
    $requirement['value'] = t("Not Set");
    $requirement['description'] = t("The Amazon API must be configured with an Associate Tag, an Access Key ID and an Amazon AWS Secret Access Key to function. Go to !settings.", array(
      "!settings" => l(t("Amazon API Setttings"), 'admin/config/services/amazon'),
    ));
    return array(
      'amazon_aws_secret_access_key' => $requirement,
    );
  }
  return NULL;
}
function amazon_schema() {
  $schema['amazon_item'] = array(
    'fields' => array(
      'asin' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'detailpageurl' => array(
        'type' => 'text',
      ),
      'salesrank' => array(
        'type' => 'int',
        'unsigned' => TRUE,
      ),
      'brand' => array(
        'type' => 'varchar',
        'length' => 64,
      ),
      'publisher' => array(
        'type' => 'varchar',
        'length' => 64,
      ),
      'manufacturer' => array(
        'type' => 'varchar',
        'length' => 64,
      ),
      'mpn' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
      'studio' => array(
        'type' => 'varchar',
        'length' => 64,
      ),
      'label' => array(
        'type' => 'varchar',
        'length' => 64,
      ),
      'binding' => array(
        'type' => 'varchar',
        'length' => 64,
      ),
      'releasedate' => array(
        'type' => 'varchar',
        'length' => 64,
      ),
      'listpriceamount' => array(
        'type' => 'numeric',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '0',
      ),
      'listpricecurrencycode' => array(
        'type' => 'varchar',
        'length' => 32,
      ),
      'listpriceformattedprice' => array(
        'type' => 'varchar',
        'length' => 32,
      ),
      'lowestpriceamount' => array(
        'type' => 'numeric',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '0',
      ),
      'lowestpricecurrencycode' => array(
        'type' => 'varchar',
        'length' => 32,
      ),
      'lowestpriceformattedprice' => array(
        'type' => 'varchar',
        'length' => 32,
      ),
      'amazonpriceamount' => array(
        'type' => 'numeric',
        'not null' => FALSE,
        'precision' => '10',
        'scale' => '0',
      ),
      'amazonpricecurrencycode' => array(
        'type' => 'varchar',
        'length' => 32,
      ),
      'amazonpriceformattedprice' => array(
        'type' => 'varchar',
        'length' => 32,
      ),
      'productgroup' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
      'producttypename' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
      'customerreviews_iframe' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
      'invalid_asin' => array(
        'type' => 'int',
        'default' => 0,
      ),
      'timestamp' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'asin',
    ),
  );
  $schema['amazon_item_participant'] = array(
    'fields' => array(
      'asin' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'participant' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
    ),
    'indexes' => array(
      'asin' => array(
        'asin',
      ),
    ),
  );
  $schema['amazon_item_image'] = array(
    'fields' => array(
      'asin' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'size' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'url' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'height' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'width' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'asin',
      'size',
    ),
    'indexes' => array(
      'asin' => array(
        'asin',
      ),
    ),
  );
  $schema['amazon_item_editorial_review'] = array(
    'fields' => array(
      'asin' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'source' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'content' => array(
        'type' => 'text',
      ),
    ),
    'indexes' => array(
      'asin' => array(
        'asin',
      ),
    ),
  );
  return $schema;
}

/**
 * Fix messed up type for currency code in update 6012.
 */
function amazon_update_7100() {
  db_change_field('amazon_item', 'lowestpricecurrencycode', 'lowestpricecurrencycode', array(
    'type' => 'varchar',
    'length' => 32,
  ));
  db_change_field('amazon_item', 'amazonpricecurrencycode', 'amazonpricecurrencycode', array(
    'type' => 'varchar',
    'length' => 32,
  ));
  return t("Updated currency code column types");
}

/**
 * Amazon has stopped providing customer review data; now we only get an
 * iframe link where Amazon will provide the data, so we need to drop the table
 * that was used for customer reviews and add the new iframe link.
 */
function amazon_update_7102() {
  if (!db_field_exists('amazon_item', 'customerreviews_iframe')) {
    db_add_field('amazon_item', 'customerreviews_iframe', array(
      'type' => 'varchar',
      'length' => 255,
    ));
  }
  if (db_table_exists('amazon_item_customer_review')) {
    db_drop_table('amazon_item_customer_review');
  }

  // Expire all the existing amazon items so the next cron will update them.
  db_update('amazon_item')
    ->fields(array(
    'timestamp' => 0,
  ))
    ->execute();
  return t("Updated support for customer reviews");
}

/**
 * Increase the length of the mpn field.
 */
function amazon_update_7103() {
  db_change_field('amazon_item', 'mpn', 'mpn', array(
    'type' => 'varchar',
    'length' => 255,
  ));
}

/**
 * Move module config into Web Services section.
 */
function amazon_update_7104() {
  $paths = array(
    'admin/config/amazon_settings/amazon' => 'admin/config/services/amazon',
    'admin/config/amazon_settings/amazon/api' => 'admin/config/services/amazon/api',
    'admin/config/amazon_settings/amazon/storage' => 'admin/config/services/amazon/storage',
    'admin/config/amazon_settings/amazon/test' => 'admin/config/services/amazon/test',
  );
  foreach ($paths as $prev_path => $new_path) {
    db_query('UPDATE {menu_router} set path=:path WHERE path=:prev', array(
      ':path' => $new_path,
      ':prev' => $prev_path,
    ));
  }
  menu_rebuild();
}

/**
 * Rebuild the theme registry.
 */
function amazon_update_7105() {
  drupal_theme_rebuild();
}

/**
 * Drop table amazon_item_node.
 */
function amazon_update_7106() {
  db_drop_table('amazon_item_node');
}

/**
 * Migrate existing amazon variables to new variable format.
 */
function amazon_update_7107() {
  $amazon_locale = variable_get('amazon_locale', 'US');

  // Update the locale setting variable
  variable_set('amazon_default_locale', $amazon_locale);

  // Load locale data
  require_once drupal_get_path('module', 'amazon') . '/includes/amazon.locales.inc';
  $locales = _amazon_load_locales();

  // Set up default values for each locale to the Drupal Association ID for that locale (if available)
  foreach ($locales as $locale => $data) {
    variable_set('amazon_locale_' . $locale . '_associate_id', $data['da_associate_id']);
  }

  // Update the associate ID for the default locale to the value previously set
  $custom_assoc_id = variable_get('amazon_custom_associate_id', '');
  if ($custom_assoc_id) {
    variable_set('amazon_locale_' . $amazon_locale . '_associate_id', $custom_assoc_id);
  }

  // Remove depricated variables.
  variable_del('amazon_locale');
  variable_del('amazon_custom_associate_id');
  variable_del('amazon_associate_setting');
}

Functions

Namesort descending Description
amazon_install Implements hook_install.
amazon_requirements implementation of hook_requirements to make sure we let them know about the requirement for amazon_aws_secret_access_key
amazon_schema
amazon_uninstall Implements hook_uninstall().
amazon_update_7100 Fix messed up type for currency code in update 6012.
amazon_update_7102 Amazon has stopped providing customer review data; now we only get an iframe link where Amazon will provide the data, so we need to drop the table that was used for customer reviews and add the new iframe link.
amazon_update_7103 Increase the length of the mpn field.
amazon_update_7104 Move module config into Web Services section.
amazon_update_7105 Rebuild the theme registry.
amazon_update_7106 Drop table amazon_item_node.
amazon_update_7107 Migrate existing amazon variables to new variable format.