You are here

ad_channel.install in Advertisement 6.2

File

channel/ad_channel.install
View source
<?php

/**
 *
 * Ad channel database schema.
 * Copyright (c) 2008-2009 Jeremy Andrews <jeremy@tag1consulting.com>.
 */

/**
 * Create the ad_channel schema.
 */
function ad_channel_schema() {
  $schema['ad_channel'] = array(
    'description' => 'The ad_channel table allows advertisements to be organized into channels against which rules can be applied.',
    'fields' => array(
      'chid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'description' => 'Unique channel ID.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The name of the channel.',
      ),
      'description' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'A description of the channel.',
      ),
      'conid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'ID of the container the channel is in.',
      ),
      'weight' => array(
        'type' => 'int',
        'size' => 'medium',
        'not null' => TRUE,
        'unsigned' => FALSE,
        'default' => 0,
        'description' => 'Used when displaying channels to admins, heavier weights sink to the bottom.',
      ),
      'display' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'no_channel_percent' => array(
        'type' => 'int',
        'size' => 'medium',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'inventory' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'urls' => array(
        'type' => 'text',
      ),
      'groups' => array(
        'type' => 'text',
      ),
    ),
    'primary key' => array(
      'chid',
    ),
    'indexes' => array(
      'name' => array(
        'name',
      ),
    ),
  );
  $schema['ad_channel_remnant'] = array(
    'fields' => array(
      'aid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'remnant' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'aid',
      'remnant',
    ),
  );
  $schema['ad_channel_container'] = array(
    'description' => 'The ad_channel_container table stores channel container definitions.',
    'fields' => array(
      'conid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'description' => 'Unique container ID.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The name of the container.',
      ),
      'description' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'A description of the container.',
      ),
      'weight' => array(
        'type' => 'int',
        'size' => 'medium',
        'not null' => TRUE,
        'unsigned' => FALSE,
        'default' => 0,
        'description' => 'Used when displaying channels to admins, heavier weights sink to the bottom.',
      ),
    ),
    'primary key' => array(
      'conid',
    ),
  );
  $schema['ad_channel_node'] = array(
    'description' => 'The ad_channel_node table stores per node channel information.',
    'fields' => array(
      'chid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'chid',
      'nid',
    ),
    'indexes' => array(
      'nid_chid' => array(
        'nid',
        'chid',
      ),
    ),
  );
  $schema['ad_priority'] = array(
    'fields' => array(
      'aid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'priority' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'aid',
      'priority',
    ),
  );
  return $schema;
}
function ad_channel_install() {

  // Create tables
  drupal_install_schema('ad_channel');
}

/**
 * Completely uninstall the ad channel module.
 */
function ad_channel_uninstall() {

  // Drop tables
  drupal_uninstall_schema('ad_channel');
}

/**
 * Populate the ad_priority table.
 */
function ad_channel_update_6001() {
  $ret = array();
  $result = db_query('SELECT a.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid');
  while ($ad = db_fetch_object($result)) {
    if (!isset($ad->priority)) {
      $ret[] = update_sql("INSERT INTO {ad_priority} (aid, priority) VALUES ({$ad->aid}, 0)");
    }
  }
  return $ret;
}

/**
 * Rebuild the menu so that channels and containers can be deleted.
 */
function ad_channel_update_6002() {
  cache_clear_all();
  menu_rebuild();
  return array();
}

/**
 * Introduce no_channel_weight.
 */
function ad_channel_update_6003() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {ad_channel} ADD no_channel_weight INT(3) NOT NULL DEFAULT '0'");
  return $ret;
}

/**
 * Introduce no_channel_percent.
 */
function ad_channel_update_6004() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {ad_channel} CHANGE COLUMN no_channel_weight no_channel_percent INT(3) NOT NULL DEFAULT '0'");

  // migration of no_channel_weights to no_channel_percent is an approximation
  // to evenly distribute legacy values to new inorder to maintain weighting
  $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=20 WHERE no_channel_percent=25");
  $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=25 WHERE no_channel_percent=33");
  $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=35 WHERE no_channel_percent=50");
  $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=50 WHERE no_channel_percent=100");
  $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=65 WHERE no_channel_percent=200");
  $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=75 WHERE no_channel_percent=300");
  $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=80 WHERE no_channel_percent=400");
  return $ret;
}

/*
 * Introduce channel inventory and remnant ads
 */
function ad_channel_update_6005() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {ad_channel} ADD inventory INT(11)");
  $ret[] = update_sql("CREATE TABLE {ad_channel_remnant} (aid INT(11) UNSIGNED NOT NULL DEFAULT '0', remnant TINYINT UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (aid, remnant))");
  return $ret;
}

/*
 * Make weight a signed int to allow negative weights.
 * Issue http://drupal.org/node/612302
 */
function ad_channel_update_6006() {
  $ret = array();
  db_change_field($ret, 'ad_channel', 'weight', 'weight', array(
    'type' => 'int',
    'size' => 'medium',
    'not null' => TRUE,
    'unsigned' => FALSE,
    'default' => 0,
    'description' => 'Used when displaying channels to admins, heavier weights sink to the bottom.',
  ));
  db_change_field($ret, 'ad_channel_container', 'weight', 'weight', array(
    'type' => 'int',
    'size' => 'medium',
    'not null' => TRUE,
    'unsigned' => FALSE,
    'default' => 0,
    'description' => 'Used when displaying channels to admins, heavier weights sink to the bottom.',
  ));
  return $ret;
}

Functions

Namesort descending Description
ad_channel_install
ad_channel_schema Create the ad_channel schema.
ad_channel_uninstall Completely uninstall the ad channel module.
ad_channel_update_6001 Populate the ad_priority table.
ad_channel_update_6002 Rebuild the menu so that channels and containers can be deleted.
ad_channel_update_6003 Introduce no_channel_weight.
ad_channel_update_6004 Introduce no_channel_percent.
ad_channel_update_6005
ad_channel_update_6006