You are here

commerce_donate.install in Commerce Donate 7

Installation file for commerce_donate. Creates necessary entity fields on installation.

File

commerce_donate.install
View source
<?php

/**
 * @file
 * Installation file for commerce_donate. Creates necessary entity fields on
 * installation.
 */

/**
 * Implements hook_install().
 */
function commerce_donate_install() {
  module_load_include('inc', 'commerce_donate', 'includes/commerce_donate.field');
  if ($fields = commerce_donate_get_fields()) {
    field_info_cache_clear();
    foreach ($fields as $field) {

      // Create or update field.
      $field_config = $field['field_config'];
      $existing_field = field_info_field($field_config['field_name']);
      if (empty($existing_field)) {
        field_create_field($field_config);
      }

      // Create or update field instance.
      $field_instance = $field['field_instance'];
      $existing_instance = field_info_instance($field_instance['entity_type'], $field_instance['field_name'], $field_instance['bundle']);
      if ($existing_instance) {
        field_update_instance($field_instance);
      }
      else {
        field_create_instance($field_instance);
      }
      variable_set('menu_rebuild_needed', TRUE);
    }
  }
}

/**
 * Implements hook_uninstall().
 */
function commerce_donate_uninstall() {
  variable_del('commerce_donate_checkout_pane_title');
  variable_del('commerce_donate_checkout_pane_description');
  variable_del('commerce_donate_checkout_pane_product_id');
  variable_del('commerce_donate_checkout_pane_override_options');
  variable_del('commerce_donate_checkout_pane_donate_amounts');
}

/**
 * Change integer amount field to decimal.
 */
function commerce_donate_update_7001() {
  db_change_field('field_data_commerce_donate_amount', 'commerce_donate_amount_value', 'commerce_donate_amount_value', array(
    'type' => 'float',
    'size' => 'big',
  ));
  db_change_field('field_revision_commerce_donate_amount', 'commerce_donate_amount_value', 'commerce_donate_amount_value', array(
    'type' => 'float',
    'size' => 'big',
  ));
  $serialized = db_query("SELECT data FROM {field_config} WHERE field_name = 'commerce_donate_amount'")
    ->fetchField();
  $data = unserialize($serialized);
  $data['settings']['precision'] = 10;
  $data['settings']['scale'] = 2;
  $data['settings']['decimal_separator'] = '.';
  $serialized = serialize($data);
  db_query("UPDATE {field_config} SET type = 'number_decimal', data = :data WHERE field_name = 'commerce_donate_amount'", array(
    ':data' => $serialized,
  ));
}

Functions

Namesort descending Description
commerce_donate_install Implements hook_install().
commerce_donate_uninstall Implements hook_uninstall().
commerce_donate_update_7001 Change integer amount field to decimal.