You are here

commerce_addressbook.install in Commerce Addressbook 7.3

Same filename and directory in other branches
  1. 7 commerce_addressbook.install
  2. 7.2 commerce_addressbook.install

File

commerce_addressbook.install
View source
<?php

/**
 * Implements hook_schema().
 */
function commerce_addressbook_schema() {
  $schema = array();
  $schema['commerce_addressbook_defaults'] = array(
    'description' => 'Stores addressbook defaults by customer profile type.',
    'fields' => array(
      'profile_id' => array(
        'description' => 'Numeric ID of the customer profile in the local database.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'The customer profile type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'uid' => array(
        'description' => 'The {users}.uid that owns this profile-.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'foreign keys' => array(
      'profile_id' => array(
        'table' => 'commerce_customer_profile',
        'columns' => array(
          'profile_id' => 'profile_id',
        ),
      ),
      'uid' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
    ),
    'unique keys' => array(
      'uid_type' => array(
        'uid',
        'type',
      ),
    ),
    'indexes' => array(
      'profile_id' => array(
        'profile_id',
      ),
      'uid' => array(
        'uid',
      ),
    ),
  );
  return $schema;
}

/**
 * Creates the defaults table and removes any saved profile fields.
 */
function commerce_addressbook_update_7200() {

  // Only run this update if the defaults table does not exist.
  if (!db_table_exists('commerce_addressbook_defaults')) {
    db_create_table('commerce_addressbook_defaults', drupal_get_schema_unprocessed('commerce_addressbook', 'commerce_addressbook_defaults'));

    // Delete any saved profile fields.
    commerce_delete_fields('commerce_addressbook_saved_profiles');
    return t('Created the commerce_addressbook_defaults table and deleted all saved profile fields.');
  }
}

/**
 * Apply the schema updates from 7.x.2.x to 7.x.3.x.
 */
function commerce_addressbook_update_7300() {
  if (db_field_exists('commerce_addressbook_defaults', 'cad_id')) {

    // Deleting the field also drops the primary key.
    db_drop_field('commerce_addressbook_defaults', 'cad_id');
    db_add_unique_key('commerce_addressbook_defaults', 'uid_type', array(
      'uid',
      'type',
    ));
    db_change_field('commerce_addressbook_defaults', 'profile_id', 'profile_id', array(
      'description' => 'Numeric ID of the customer profile in the local database.',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
    ), array(
      'profile_id' => array(
        'profile_id',
      ),
    ));
  }
}

Functions

Namesort descending Description
commerce_addressbook_schema Implements hook_schema().
commerce_addressbook_update_7200 Creates the defaults table and removes any saved profile fields.
commerce_addressbook_update_7300 Apply the schema updates from 7.x.2.x to 7.x.3.x.