You are here

uc_quote.install in Ubercart 6.2

Install, update and uninstall functions for the uc_quote module.

File

shipping/uc_quote/uc_quote.install
View source
<?php

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

/**
 * Implements hook_schema().
 */
function uc_quote_schema() {
  $schema = array();
  $schema['uc_quote_shipping_types'] = array(
    'description' => 'Stores shipping information of products.',
    'fields' => array(
      'id_type' => array(
        'description' => 'Determines the table that id references. "product" => {uc_products}.nid.',
        'type' => 'varchar',
        'length' => 127,
        'not null' => TRUE,
        'default' => '',
      ),
      'id' => array(
        'description' => 'The entity ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'shipping_type' => array(
        'description' => 'The basic type of shipment, e.g.: small package, freight.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'id_type',
      'id',
    ),
  );
  $schema['uc_quote_product_locations'] = array(
    'description' => 'Stores default product origin addresses.',
    'fields' => array(
      'nid' => array(
        'description' => 'The {uc_products}.nid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'first_name' => array(
        'description' => 'The address first name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'last_name' => array(
        'description' => 'The address last name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'company' => array(
        'description' => 'The address company.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'street1' => array(
        'description' => 'The address street line 1.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'street2' => array(
        'description' => 'The address street line 2.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'city' => array(
        'description' => 'The address city.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'zone' => array(
        'description' => 'The address state/province, from {uc_zones}.zone_id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'postal_code' => array(
        'description' => 'The address postal code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'country' => array(
        'description' => 'The address country, from {uc_countries}.country_id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'phone' => array(
        'description' => 'The address phone number.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  $schema['uc_order_quotes'] = array(
    'description' => 'Stores shipping quotes.',
    'fields' => array(
      'order_id' => array(
        'description' => 'The {uc_orders}.order_id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'method' => array(
        'description' => 'The quoted shipping method.',
        'type' => 'varchar',
        'length' => 25,
        'not null' => TRUE,
        'default' => '',
      ),
      'accessorials' => array(
        'description' => 'Additional services or special instructions.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'rate' => array(
        'description' => 'The quoted shipping rate.',
        'type' => 'numeric',
        'precision' => 16,
        'scale' => 5,
        'not null' => TRUE,
        'default' => 0,
      ),
      'quote_form' => array(
        'description' => 'HTML form used to choose the shipping quote.',
        'type' => 'text',
      ),
    ),
    'unique keys' => array(
      'order_id_quote_method' => array(
        'order_id',
        'method',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function uc_quote_install() {
  drupal_install_schema('uc_quote');
}

/**
 * Implements hook_uninstall().
 */
function uc_quote_uninstall() {
  drupal_uninstall_schema('uc_quote');
  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_quote_%%'");
  variable_del('uc_store_shipping_type');
}

/**
 * Implements hook_update_last_removed().
 */
function uc_quote_update_last_removed() {
  return 8;
}

/**
 * Implements hook_update_N().
 */
function uc_quote_update_6000() {
  $ret = array();
  db_drop_primary_key($ret, 'uc_quote_shipping_types');
  db_change_field($ret, 'uc_quote_shipping_types', 'id', 'id', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'primary key' => array(
      'id_type',
      'id',
    ),
  ));
  db_drop_primary_key($ret, 'uc_quote_manufacturer_locations');
  db_change_field($ret, 'uc_quote_manufacturer_locations', 'tid', 'tid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'primary key' => array(
      'tid',
    ),
  ));
  db_drop_primary_key($ret, 'uc_quote_product_locations');
  db_change_field($ret, 'uc_quote_product_locations', 'nid', 'nid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'primary key' => array(
      'nid',
    ),
  ));
  db_drop_unique_key($ret, 'uc_order_quotes', 'oid_quote_method');
  db_change_field($ret, 'uc_order_quotes', 'oid', 'order_id', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'unique keys' => array(
      'order_id_quote_method' => array(
        'order_id',
        'method',
      ),
    ),
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 */
function uc_quote_update_6001() {
  $ret = array();
  db_change_field($ret, 'uc_order_quotes', 'rate', 'rate', array(
    'type' => 'numeric',
    'precision' => 15,
    'scale' => 3,
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 */
function uc_quote_update_6002() {
  $ret = array();
  if (db_table_exists('uc_quote_manufacturer_locations')) {
    db_drop_table($ret, 'uc_quote_manufacturer_locations');
  }
  return $ret;
}

/**
 * Implements hook_update_N().
 */
function uc_quote_update_6003() {

  // This is the same update as #8, but it was added after 6002 was published.
  $ret = array();
  $ret[] = update_sql("DELETE FROM {uc_quote_shipping_types} WHERE id = 0");
  return $ret;
}

/**
 * Implements hook_update_N().
 *
 * Changes currency fields to numeric(16,5).
 */
function uc_quote_update_6004() {
  $ret = array();
  db_change_field($ret, 'uc_order_quotes', 'rate', 'rate', array(
    'type' => 'numeric',
    'precision' => 16,
    'scale' => 5,
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}