home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (uc_product.install)

This example Drupal source code file (uc_product.install) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, database, default, description, function, not, null, ret, sql, table, the, true, uc_products, update_sql

The uc_product.install Drupal example source code

<?php
// $Id: uc_product.install,v 1.12.2.12 2010/03/19 21:27:18 tr Exp $

/**
 * @file
 * Database installation, uninstallation, and updates for the product module.
 */

/**
 * Implementation of hook_schema().
 */
function uc_product_schema() {
  $schema = array();

  $schema['uc_product_classes'] = array(
    'description' => 'The list of product node types.',
    'fields' => array(
      'pcid' => array(
        'description' => 'The node type identifier.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The human-readable name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'The description of the node type.',
        'type' => 'text',
      ),
    ),
    'primary key' => array('pcid'),
  );

  $schema['uc_product_features'] = array(
    'description' => 'Stores information of features added to products.',
    'fields' => array(
      'pfid' => array(
        'description' => 'Primary key: the product feature id.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'The {node}.nid of the product that has this feature.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'fid' => array(
        'description' => 'The type of feature.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'The description of the feature.',
        'type' => 'text',
      ),
    ),
    'indexes' => array(
      'nid' => array('nid'),
    ),
    'primary key' => array('pfid'),
  );

  $schema['uc_products'] = array(
    'description' => 'Product information for nodes.',
    'fields' => array(
      'vid' => array(
        'description' => 'The {node}.vid of the product.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'description' => 'The {node}.nid of the product.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'model' => array(
        'description' => 'SKU or model number.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'list_price' => array(
        'description' => 'Suggested retail price.',
        'type' => 'numeric',
        'precision' => 16,
        'scale' => 5,
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'cost' => array(
        'description' => 'The amount the store pays to sell the product.',
        'type' => 'numeric',
        'precision' => 16,
        'scale' => 5,
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'sell_price' => array(
        'description' => 'The amount the customer pays for the product.',
        'type' => 'numeric',
        'precision' => 16,
        'scale' => 5,
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'weight' => array(
        'description' => 'Physical weight.',
        'type' => 'float',
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'weight_units' => array(
        'description' => 'Unit of measure for the weight field.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'lb',
      ),
      'length' => array(
        'description' => 'Physical length of the product or its packaging.',
        'type' => 'float',
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'width' => array(
        'description' => 'Physical width of the product or its packaging.',
        'type' => 'float',
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'height' => array(
        'description' => 'Physical height of the product or its packaging.',
        'type' => 'float',
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'length_units' => array(
        'description' => 'Unit of measure for the length, width, and height.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'in',
      ),
      'pkg_qty' => array(
        'description' => 'The number of this product that fit in one package.',
        'type' => 'int',
        'size' => 'small',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'default_qty' => array(
        'description' => 'The default value for the quantity field in the "Add to Cart" form.',
        'type' => 'int',
        'size' => 'small',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'unique_hash' => array(
        'description' => 'A multi-site unique identifier for a product.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => md5(''),
      ),
      'ordering' => array(
        'description' => 'The sort criteria for products.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'shippable' => array(
        'description' => 'Boolean flag signifying that the product can be shipped.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'indexes' => array(
      'nid' => array('nid'),
    ),
    'primary key' => array('vid'),
  );

  return $schema;
}

/**
 * Implementation of hook_install().
 */
function uc_product_install() {
  drupal_install_schema('uc_product');
}

/**
 * Implementation of hook_uninstall().
 */
function uc_product_uninstall() {
  drupal_uninstall_schema('uc_product');

  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_product_shippable_%%'");

  variable_del('uc_product_nodes_per_page');
  variable_del('uc_product_add_to_cart_qty');
  variable_del('uc_product_add_to_cart_teaser');
  variable_del('uc_teaser_add_to_cart_text');
  variable_del('uc_product_add_to_cart_text');
  variable_del('uc_product_field_enabled');
  variable_del('uc_product_field_weight');
}

function uc_product_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_class_choices} CHANGE name name varchar(255) NOT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_class_fields} CHANGE name name varchar(255) NOT NULL, DROP COLUMN title");
      $ret[] = update_sql("ALTER TABLE {uc_product_classes} CHANGE name name varchar(255) NOT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} CHANGE value value varchar(255) NOT NULL, ADD PRIMARY KEY (nid, cfid, value)");
      $ret[] = update_sql("ALTER TABLE {uc_products} CHANGE model model varchar(255) NOT NULL");
    break;
    case 'pgsql':
      db_change_column($ret, 'uc_class_choices', 'name', 'name', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
      db_change_column($ret, 'uc_class_fields', 'name', 'name', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
      $ret[] = update_sql("ALTER TABLE {uc_class_fields} DROP title");
      db_change_column($ret, 'uc_product_classes', 'name', 'name', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
      db_change_column($ret, 'uc_product_class_choices', 'value', 'value', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
      $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} ADD PRIMARY KEY (nid, cfid, value)");
      db_change_column($ret, 'uc_products', 'model', 'model', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
    break;
  }

  if ($max_id = db_result(db_query_range("SELECT cfid FROM {uc_class_fields} ORDER BY cfid DESC", 0, 1))) {
    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{uc_class_fields}_cfid', %d)", $max_id);
  }

  return $ret;
}

function uc_product_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} DROP PRIMARY KEY");
      $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} CHANGE value value text NOT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} ADD PRIMARY KEY (nid, cfid, value (3))");
    break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} DROP CONSTRAINT {uc_product_class_choices}_pkey");
      db_change_column($ret, 'uc_product_class_choices', 'value', 'value', 'text', array('not null' => TRUE, 'default' => "''"));
      $ret[] = update_sql("ALTER TABLE {uc_product_class_choices} ADD PRIMARY KEY (nid, cfid, value (3))");
    break;
  }
  return $ret;
}

function uc_product_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD COLUMN units varchar(255) NOT NULL default 'lbs' AFTER weight");
    break;
    case 'pgsql':
      db_add_column($ret, 'uc_products', 'units', 'varchar(255)', array('not null' => TRUE, 'default' => 'lbs'));
    break;
  }
  return $ret;
}

function uc_product_update_4() {
  $ret = array();

  $ret[] = update_sql("UPDATE {node} AS n, {uc_products} AS p, {uc_product_classes} AS pc SET n.type = REPLACE(LOWER(pc.name), ' ', '_') WHERE n.nid = p.nid AND p.pcid = pc.pcid");
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("DROP TABLE {uc_class_choices}");
      $ret[] = update_sql("DROP TABLE {uc_class_fields}");
      $ret[] = update_sql("DROP TABLE {uc_product_class_choices}");
      $ret[] = update_sql("ALTER TABLE {uc_product_classes} CHANGE pcid pcid varchar(32) NOT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_product_classes} ADD COLUMN description text");
      $ret[] = update_sql("ALTER TABLE {uc_products} DROP COLUMN pcid");
    break;
    case 'pgsql':
      $ret[] = update_sql("DROP TABLE {uc_class_choices}");
      $ret[] = update_sql("DROP TABLE {uc_class_fields}");
      $ret[] = update_sql("DROP TABLE {uc_product_class_choices}");
      $ret[] = update_sql("DROP INDEX {uc_product_classes}_pcid_idx");
      db_change_column($ret, 'uc_product_classes', 'pcid', 'pcid', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
      db_add_column($ret, 'uc_product_classes', 'description', 'text');
      $ret[] = update_sql("ALTER TABLE {uc_products} DROP COLUMN pcid");
    break;
  }
  $ret[] = update_sql("UPDATE {uc_product_classes} SET pcid = REPLACE(LOWER(name), ' ', '_')");
  if ($vid = variable_get('uc_catalog_vid', 0)) {
    $types = module_invoke_all('product_types');
    unset($types['product']);
    foreach ($types as $type) {
      $placeholders[] = "(%d, '%s')";
      $values[] = $vid;
      $values[] = $type;
    }
    $result = db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES ". implode(',', $placeholders), $values);
    $ret[] = array('success' => $result, 'query' => t('Added the following node types to the Catalog vocabulary: %list', array('%list' => implode(', ', $values))));
  }

  node_types_rebuild();

  return $ret;
}

function uc_product_update_5() {
  $ret = array();

  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD COLUMN default_qty smallint(5) unsigned NOT NULL default '1' AFTER units");
    break;
    case 'pgsql':
      db_add_column($ret, 'uc_products', 'default_qty', 'smallint unsigned', array('not null' => TRUE, 'default' => 1));
    break;
  }

  return $ret;
}

function uc_product_update_6() {
  $ret = array();

  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD COLUMN ordering smallint(2) NOT NULL default 0");
    break;
    case 'pgsql':
      db_add_column($ret, 'uc_products', 'default_qty', 'smallint(2)', array('not null' => TRUE, 'default' => 0));
    break;
  }

  return $ret;
}

function uc_product_update_7() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_products} CHANGE units weight_units varchar(255) NOT NULL default 'lb'");
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD length float unsigned NOT NULL default 0 AFTER weight_units");
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD width float unsigned NOT NULL default 0 AFTER length");
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD height float unsigned NOT NULL default 0 AFTER width");
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD length_units varchar(255) NOT NULL default 'in' AFTER height");
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD pkg_qty smallint unsigned NOT NULL default 1 AFTER length_units");
    break;
    case 'pgsql':
      db_change_column($ret, 'uc_products', 'units', 'weight_units', 'varchar(255)', array('not null' => TRUE, 'default' => 'lb'));
      db_add_column($ret, 'uc_products', 'pkg_qty', 'smallint unsigned', array('not null' => TRUE, 'default' => 1));
      db_add_column($ret, 'uc_products', 'length', 'float unsigned', array('not null' => TRUE, 'default' => 0));
      db_add_column($ret, 'uc_products', 'width', 'float unsigned', array('not null' => TRUE, 'default' => 0));
      db_add_column($ret, 'uc_products', 'height', 'float unsigned', array('not null' => TRUE, 'default' => 0));
      db_add_column($ret, 'uc_products', 'length_units', 'varchar(255)', array('not null' => TRUE, 'default' => 'in'));
    break;
  }
  return $ret;
}

function uc_product_update_8() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD vid mediumint(9) NOT NULL default 0 FIRST");
      $ret[] = update_sql("ALTER TABLE {uc_products} DROP PRIMARY KEY");
      $result = db_query("SELECT nid, vid FROM {node}");
      while ($product = db_fetch_object($result)) {
        db_query("UPDATE {uc_products} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
      }
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD PRIMARY KEY (vid)");
    break;
    case 'pgsql':
      db_add_column($ret, 'uc_products', 'vid', 'integer', array('not null' => TRUE, 'default' => 0));
      $ret[] = update_sql("ALTER TABLE {uc_products} DROP CONSTRAINT {uc_products}_pkey");
      $result = db_query("SELECT nid, vid FROM {node}");
      while ($product = db_fetch_object($result)) {
        db_query("UPDATE {uc_products} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
      }
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD PRIMARY KEY (vid)");
    break;
  }
  return $ret;
}

/**
 * Update to add in product feature support.
 */
function uc_product_update_9() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {uc_product_features} (
        `pfid` mediumint(9) NOT NULL default 0,
        `nid` mediumint(9) NOT NULL default 0,
        `fid` varchar(32) NOT NULL,
        `description` text,
        PRIMARY KEY (`pfid`),
        KEY nid (nid)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
      break;
  }

  return $ret;
}

/**
 * Update to add the shippable column to the product table.
 */
function uc_product_update_10() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_products} ADD shippable tinyint(2) NOT NULL default 1");
    break;
    case 'pgsql':
      db_add_column($ret, 'uc_products', 'shippable', 'tinyint', array('not null' => TRUE, 'default' => 1));
    break;
  }
  return $ret;
}

function uc_product_update_11() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      db_change_column($ret, 'uc_products', 'pkg_qty', 'pkg_qty', 'smallint_unsigned', array('not null' => TRUE, 'default' => 1));
      db_change_column($ret, 'uc_products', 'default_qty', 'defautl_qty', 'smallint_unsigned', array('not null' => TRUE, 'default' => 1));
    break;
  }
  return $ret;
}

function uc_product_update_12() {
  $ret = array();

  if (module_exists('imagecache')) {
    $preset_id = db_next_id('{imagecache_preset}_presetid');
    $action_id = db_next_id('{imagecache_action}_actionid');
    db_query("INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (%d, 'uc_thumbnail')", $preset_id);
    db_query("INSERT INTO {imagecache_action} (actionid, presetid, weight, data) VALUES (%d, %d, 0, '%s')", $action_id, $preset_id, 'a:4:{s:8:"function";s:5:"scale";s:3:"fit";s:6:"inside";s:5:"width";s:2:"35";s:6:"height";s:2:"35";}');
    cache_clear_all('imagecache:presets', 'cache');
    $ret[] = array('success' => TRUE, 'query' => "INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (". $preset_id .", 'uc_thumbnail')");
    $ret[] = array('success' => TRUE, 'query' => "INSERT INTO {imagecache_action} (actionid, presetid, weight, data) VALUES (". $action_id .", ". $preset_id .", 0, '". 'a:4:{s:8:"function";s:5:"scale";s:3:"fit";s:6:"inside";s:5:"width";s:2:"35";s:6:"height";s:2:"35";}' ."')");
  }

  return $ret;
}

function uc_product_update_6000() {
  $ret = array();

  db_drop_primary_key($ret, 'uc_product_features');
  db_drop_index($ret, 'uc_product_features', 'nid');
  db_change_field($ret, 'uc_product_features', 'pfid', 'pfid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('pfid')));
  db_change_field($ret, 'uc_product_features', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), array('indexes' => array('nid' => array('nid'))));

  db_drop_primary_key($ret, 'uc_products');
  db_change_field($ret, 'uc_products', 'vid', 'vid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), array('primary key' => array('vid')));
  db_change_field($ret, 'uc_products', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'list_price', 'list_price', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'cost', 'cost', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'sell_price', 'sell_price', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'weight', 'weight', array('type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'unique_hash', 'unique_hash', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => 'd41d8cd98f00b204e9800998ecf8427e'));
  db_change_field($ret, 'uc_products', 'shippable', 'shippable', array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE, 'default' => 1));

  return $ret;
}

/**
 * Make sure that those who had the faulty 6000 update have the right
 * precision and scale.
 */
function uc_product_update_6001() {
  $ret = array();

  db_change_field($ret, 'uc_products', 'list_price', 'list_price', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'cost', 'cost', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'sell_price', 'sell_price', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));

  return $ret;
}

/**
 * Make the numeric fields signed for Postgres compatibility.
 */
function uc_product_update_6002() {
  $ret = array();

  db_change_field($ret, 'uc_products', 'list_price', 'list_price', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'cost', 'cost', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'sell_price', 'sell_price', array('type' => 'numeric', 'precision' => 10, 'scale' => 2, 'not null' => TRUE, 'default' => 0));

  return $ret;
}

function uc_product_update_6003() {
  $ret = array();

  // Geez. Can't we get these columns right?
  db_change_field($ret, 'uc_products', 'list_price', 'list_price', array('type' => 'numeric', 'precision' => 15, 'scale' => 3, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'cost', 'cost', array('type' => 'numeric', 'precision' => 15, 'scale' => 3, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'sell_price', 'sell_price', array('type' => 'numeric', 'precision' => 15, 'scale' => 3, 'not null' => TRUE, 'default' => 0));

  return $ret;
}

/**
 * Handle the image widget upgrade.
 */
function uc_product_update_6004() {
  $ret = array();

  if (!variable_get('uc_product_image_widget', NULL)) {
    if (module_exists('thickbox')) {
      variable_set('uc_product_image_widget', 'thickbox');
    }
    elseif (module_exists('lightbox2')) {
      variable_set('uc_product_image_widget', 'lightbox2');
    }
    $ret[] = array('success' => TRUE, variable_get('uc_product_image_widget', 'No widget') .' was set as the current image widget');
  }

  return $ret;
}

/**
 * Set the uc_image setting to field_image_cache for all existing products.
 */
function uc_product_update_6005() {
  $ret = array();

  if (db_table_exists('content_node_field_instance')) {
    $result = db_query("SELECT type_name FROM {content_node_field_instance} WHERE field_name = 'field_image_cache'");
    while ($class = db_fetch_object($result)) {
      variable_set('uc_image_'. $class->type_name, 'field_image_cache');
    }

    $t = get_t();
    $ret[] = array('success' => TRUE, $t('field_image_cache set as the Ubercart image for products and product classes.'));
  }

  return $ret;
}

/**
 * Change to signed floats.
 */
function uc_product_update_6006() {
  $ret = array();

  $schema = array(
    'float_spec' => array(
      'type' => 'float',
      'not null' => TRUE,
      'default' => 0.0,
    ),
  );
  db_change_field($ret, 'uc_products', 'weight', 'weight', $schema['float_spec'] + array('description' => t("The product's physical weight")));
  db_change_field($ret, 'uc_products', 'length', 'length', $schema['float_spec'] + array('description' => t('Physical length of the product or its packaging.')));
  db_change_field($ret, 'uc_products', 'width', 'width', $schema['float_spec'] + array('description' => t('Physical width of the product or its packaging.')));
  db_change_field($ret, 'uc_products', 'height', 'height', $schema['float_spec'] + array('description' => t('Physical height of the product or its packaging.')));

  return $ret;
}

/**
 * Update old product images to the imagefield widget type.
 */
function uc_product_update_6007() {
  $ret = array();

  if (db_table_exists('content_node_field_instance')) {
    $ret[] = update_sql("UPDATE {content_node_field_instance} SET widget_type = 'imagefield_widget' WHERE field_name = 'field_image_cache'");
  }

  return $ret;
}

function uc_product_update_6008() {
  $ret = array();

  if (db_table_exists('imagecache_preset')) {
    $result = db_result(db_query("SELECT COUNT(presetid) FROM {imagecache_preset} WHERE presetname = 'product_full'"));
    if (!$result) {
      $ret[] = update_sql("INSERT INTO {imagecache_preset} (presetname) VALUES ('product_full')");
    }
  }

  return $ret;
}

/**
 * Change currency fields to numeric(16,5).
 */
function uc_product_update_6009() {
  $ret = array();

  db_change_field($ret, 'uc_products', 'list_price', 'list_price', array('type' => 'numeric', 'precision' => 16, 'scale' => 5, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'cost', 'cost', array('type' => 'numeric', 'precision' => 16, 'scale' => 5, 'not null' => TRUE, 'default' => 0));
  db_change_field($ret, 'uc_products', 'sell_price', 'sell_price', array('type' => 'numeric', 'precision' => 16, 'scale' => 5, 'not null' => TRUE, 'default' => 0));

  return $ret;
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal uc_product.install source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.