You are here

function uc_product_enable in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_product/uc_product.module \uc_product_enable()
  2. 7.3 uc_product/uc_product.install \uc_product_enable()

Implements hook_enable().

Sets up default imagefield and imagecache settings.

File

uc_product/uc_product.module, line 252
The product module for Ubercart.

Code

function uc_product_enable() {

  // For some time in Drupal 5, CCK would delete its field data if a node
  // type was unavailable because its module was disabled. This function
  // worked around that by giving the product classes to node.module when
  // uc_product was disabled. This is no longer necessary as of CCK 5.x-1.9,
  // but the workaround was left in to prevent accidents. This block of
  // code is here to reclaim the product nodes after an upgrade to Drupal
  // 6, and then should not be used again as the corresponding code in
  // uc_product_disable() was removed.
  if (variable_get('uc_product_enable_nodes', TRUE)) {
    $node_types = node_get_types('types');
    $product_classes = array(
      'product',
    );
    $result = db_query("SELECT pcid, name, description FROM {uc_product_classes}");
    while ($product_class = db_fetch_object($result)) {
      $product_classes[] = $product_class->pcid;
    }
    foreach ($node_types as $type => $info) {
      if ($info->module == 'node' && in_array($type, $product_classes)) {
        $info->module = 'uc_product';
        $info->custom = 0;
        node_type_save($info);
      }
    }
    variable_set('uc_product_enable_nodes', FALSE);
  }
  if (module_exists('imagefield')) {
    uc_product_add_default_image_field();
  }
}