You are here

commerce_uuid.install in Commerce UUID 7

File

commerce_uuid.install
View source
<?php

/**
 * Include some helper functions for the Entity API.
 */
module_load_include('inc', 'uuid', 'uuid.entity');

/**
 * Implements hook_schema_alter().
 */
function commerce_uuid_schema_alter(&$schema = array()) {
  $field = uuid_schema_field_definition();

  // Alter the schema definition for the commerce_bundle_item entity type.
  if (module_exists('commerce_bundle_item')) {
    if (isset($schema['commerce_bundle_item'])) {
      $schema['commerce_bundle_item']['fields']['uuid'] = $field;
    }
  }

  // Alter the schema definition for the commerce_customer_profile entity type.
  if (isset($schema['commerce_customer_profile'])) {
    $schema['commerce_customer_profile']['fields']['uuid'] = $field;
    $schema['commerce_customer_profile_revision']['fields']['vuuid'] = $field;
  }

  // Alter the schema definition for the commerce_line_item entity type.
  if (isset($schema['commerce_line_item'])) {
    $schema['commerce_line_item']['fields']['uuid'] = $field;
  }

  // Alter the schema definition for the commerce_order entity type.
  if (isset($schema['commerce_order'])) {
    $schema['commerce_order']['fields']['uuid'] = $field;
    $schema['commerce_order_revision']['fields']['vuuid'] = $field;
  }

  // Alter the schema definition for the commerce_payment_transaction entity type.
  if (isset($schema['commerce_payment_transaction'])) {
    $schema['commerce_payment_transaction']['fields']['uuid'] = $field;
    $schema['commerce_payment_transaction_revision']['fields']['vuuid'] = $field;
  }

  // Alter the schema definition for the commerce_product entity type.
  if (isset($schema['commerce_product'])) {
    $schema['commerce_product']['fields']['uuid'] = $field;
    $schema['commerce_product_revision']['fields']['vuuid'] = $field;
  }
}

/**
 * Implements hook_install().
 */
function commerce_uuid_install() {
  $field = uuid_schema_field_definition();

  // Add the uuid column for the commerce_bundle_item entity type.
  if (module_exists('commerce_bundle_item')) {
    if (db_table_exists('commerce_bundle_item')) {
      if (!db_field_exists('commerce_bundle_item', 'uuid')) {
        db_add_field('commerce_bundle_item', 'uuid', $field);
        db_add_index('commerce_bundle_item', 'uuid', array(
          'uuid',
        ));
      }
    }
  }

  // Add the uuid column for the commerce_customer_profile entity type.
  if (db_table_exists('commerce_customer_profile')) {
    if (!db_field_exists('commerce_customer_profile', 'uuid')) {
      db_add_field('commerce_customer_profile', 'uuid', $field);
      db_add_index('commerce_customer_profile', 'uuid', array(
        'uuid',
      ));
    }
    if (!db_field_exists('commerce_customer_profile_revision', 'vuuid')) {
      db_add_field('commerce_customer_profile_revision', 'vuuid', $field);
      db_add_index('commerce_customer_profile_revision', 'vuuid', array(
        'vuuid',
      ));
    }
  }

  // Add the uuid column for the commerce_line_item entity type.
  if (db_table_exists('commerce_line_item')) {
    if (!db_field_exists('commerce_line_item', 'uuid')) {
      db_add_field('commerce_line_item', 'uuid', $field);
      db_add_index('commerce_line_item', 'uuid', array(
        'uuid',
      ));
    }
  }

  // Add the uuid column for the commerce_order entity type.
  if (db_table_exists('commerce_order')) {
    if (!db_field_exists('commerce_order', 'uuid')) {
      db_add_field('commerce_order', 'uuid', $field);
      db_add_index('commerce_order', 'uuid', array(
        'uuid',
      ));
    }
    if (!db_field_exists('commerce_order_revision', 'vuuid')) {
      db_add_field('commerce_order_revision', 'vuuid', $field);
      db_add_index('commerce_order_revision', 'vuuid', array(
        'vuuid',
      ));
    }
  }

  // Add the uuid column for the commerce_payment_transaction entity type.
  if (db_table_exists('commerce_payment_transaction')) {
    if (!db_field_exists('commerce_payment_transaction', 'uuid')) {
      db_add_field('commerce_payment_transaction', 'uuid', $field);
      db_add_index('commerce_payment_transaction', 'uuid', array(
        'uuid',
      ));
    }
    if (!db_field_exists('commerce_payment_transaction_revision', 'vuuid')) {
      db_add_field('commerce_payment_transaction_revision', 'vuuid', $field);
      db_add_index('commerce_payment_transaction_revision', 'vuuid', array(
        'vuuid',
      ));
    }
  }

  // Add the uuid column for the commerce_product entity type.
  if (db_table_exists('commerce_product')) {
    if (!db_field_exists('commerce_product', 'uuid')) {
      db_add_field('commerce_product', 'uuid', $field);
      db_add_index('commerce_product', 'uuid', array(
        'uuid',
      ));
    }
    if (!db_field_exists('commerce_product_revision', 'vuuid')) {
      db_add_field('commerce_product_revision', 'vuuid', $field);
      db_add_index('commerce_product_revision', 'vuuid', array(
        'vuuid',
      ));
    }
  }
  uuid_sync_all();
}

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

  // Remove the uuid column for the commerce_bundle_item entity type.
  if (module_exists('commerce_bundle_item')) {
    if (db_table_exists('commerce_bundle_item')) {
      if (!db_field_exists('commerce_bundle_item', 'uuid')) {
        db_drop_field('commerce_bundle_item', 'uuid', $field);
        db_drop_index('commerce_bundle_item', 'uuid', array(
          'uuid',
        ));
      }
    }
  }

  // Remove the uuid column for the commerce_customer_profile entity type.
  if (db_table_exists('commerce_customer_profile')) {
    if (db_field_exists('commerce_customer_profile', 'uuid')) {
      db_drop_field('commerce_customer_profile', 'uuid');
      db_drop_index('commerce_customer_profile', 'uuid');
    }
    if (db_field_exists('commerce_customer_profile_revision', 'vuuid')) {
      db_drop_field('commerce_customer_profile_revision', 'vuuid');
      db_drop_index('commerce_customer_profile_revision', 'vuuid');
    }
  }

  // Remove the uuid column for the commerce_line_item entity type.
  if (db_table_exists('commerce_line_item')) {
    if (db_field_exists('commerce_line_item', 'uuid')) {
      db_drop_field('commerce_line_item', 'uuid');
      db_drop_index('commerce_line_item', 'uuid');
    }
  }

  // Remove the uuid column for the commerce_order entity type.
  if (db_table_exists('commerce_order')) {
    if (db_field_exists('commerce_order', 'uuid')) {
      db_drop_field('commerce_order', 'uuid');
      db_drop_index('commerce_order', 'uuid');
    }
    if (db_field_exists('commerce_order_revision', 'vuuid')) {
      db_drop_field('commerce_order_revision', 'vuuid');
      db_drop_index('commerce_order_revision', 'vuuid');
    }
  }

  // Remove the uuid column for the commerce_payment_transaction entity type.
  if (db_table_exists('commerce_payment_transaction')) {
    if (db_field_exists('commerce_payment_transaction', 'uuid')) {
      db_drop_field('commerce_payment_transaction', 'uuid');
      db_drop_index('commerce_payment_transaction', 'uuid');
    }
    if (db_field_exists('commerce_payment_transaction_revision', 'vuuid')) {
      db_drop_field('commerce_payment_transaction_revision', 'vuuid');
      db_drop_index('commerce_payment_transaction_revision', 'vuuid');
    }
  }

  // Remove the uuid column for the commerce_product entity type.
  if (db_table_exists('commerce_product')) {
    if (db_field_exists('commerce_product', 'uuid')) {
      db_drop_field('commerce_product', 'uuid');
      db_drop_index('commerce_product', 'uuid');
    }
    if (db_field_exists('commerce_product_revision', 'vuuid')) {
      db_drop_field('commerce_product_revision', 'vuuid');
      db_drop_index('commerce_product_revision', 'vuuid');
    }
  }
}

/**
 * Remove the commerce_uuid_* sub-modules from the system table.
 */
function commerce_uuid_update_7000() {
  $commerce_uuid_modules = array(
    'commerce_uuid_customer',
    'commerce_uuid_line_item',
    'commerce_uuid_order',
    'commerce_uuid_payment',
    'commerce_uuid_product',
  );
  db_delete('system')
    ->condition('type', 'module')
    ->condition('name', $commerce_uuid_modules, 'IN')
    ->execute();
}

Functions

Namesort descending Description
commerce_uuid_install Implements hook_install().
commerce_uuid_schema_alter Implements hook_schema_alter().
commerce_uuid_uninstall Implements hook_uninstall().
commerce_uuid_update_7000 Remove the commerce_uuid_* sub-modules from the system table.