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

Drupal example source code file (uc_stock.install)

This example Drupal source code file (uc_stock.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, default, description, function, int, nid, not, null, php, ret, stock, true, type

The uc_stock.install Drupal example source code

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

/**
 * @file
 * The installation file
 */

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

  $schema['uc_product_stock'] = array(
    'description' => 'Stock levels for Ubercart products.',
    'fields' => array(
      'sku' => array(
        'description' => 'SKU (Stock Keeping Unit) of a product.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'nid' => array(
        'description' => 'Node ID of a product.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'active' => array(
        'description' => 'Boolean flag indicating whether stock is being tracked for this product. 1 => Yes. 0 => No.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'stock' => array(
        'description' => 'Quantity in stock.',
        'type' => 'int',
        'size' => 'medium',
        'not null' => TRUE,
        'default' => 0,
      ),
      'threshold' => array(
        'description' => 'Minimum quantity threshold level.',
        'type' => 'int',
        'size' => 'medium',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'nid' => array('nid'),
    ),
    'primary key' => array('sku'),
  );

  return $schema;
}

/**
 * Implementation of hook_install().
 */
function uc_stock_install() {
  drupal_install_schema('uc_stock');
}

/**
 * Implementation of hook_uninstall().
 */
function uc_stock_uninstall() {
  drupal_uninstall_schema('uc_stock');
  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_stock_%%'");
  variable_del('uc_stock_threshold_notification');
  variable_del('uc_stock_threshold_notification_recipients');
  variable_del('uc_stock_threshold_notification_subject');
  variable_del('uc_stock_threshold_notification_message');
  variable_del('uc_stock_threshold_notification_format');
}

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

  db_drop_index($ret, 'uc_product_stock', 'nid');
  db_change_field($ret, 'uc_product_stock', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), array('indexes' => array('nid' => array('nid'))));
  db_change_field($ret, 'uc_product_stock', 'active', 'active', array('type' => 'int', 'unsigned' => TRUE, '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_stock.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.