diff channel/ad_channel.install @ 8:32c1a7d9e1fa ad tip

maj module ad en 2.1
author sly
date Fri, 11 Sep 2009 11:10:20 +0000
parents 6aeff3329e01
children
line wrap: on
line diff
--- a/channel/ad_channel.install	Mon Jul 20 13:54:40 2009 +0000
+++ b/channel/ad_channel.install	Fri Sep 11 11:10:20 2009 +0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: ad_channel.install,v 1.1.4.8 2009/07/11 16:39:21 jeremy Exp $
+// $Id: ad_channel.install,v 1.1.4.9 2009/07/28 17:39:35 jeremy Exp $
 
 /**
  *
@@ -10,67 +10,180 @@
 /**
  * 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' => TRUE,
+        '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' => TRUE,
+        '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() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-    default:
-      // TODO: PostgreSQL support.  Patches welcome.
-      /* The ad_channel table stores channel definitions and rules.
-       */
-      db_query("CREATE TABLE {ad_channel} (
-        chid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
-        name VARCHAR(64) NOT NULL DEFAULT '',
-        description LONGTEXT NULL,
-        conid INT(11) UNSIGNED NOT NULL DEFAULT '0',
-        weight TINYINT(4) SIGNED NOT NULL DEFAULT '0',
-        display TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
-        no_channel_percent INT(3) NOT NULL DEFAULT '0',
-        urls TEXT NULL,
-        groups TEXT NULL,
-        PRIMARY KEY  (chid),
-        KEY  (name)
-      );");
-      /* The ad_channel_container table stores channel container definitions.
-       */
-      db_query("CREATE TABLE {ad_channel_container} (
-        conid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
-        name VARCHAR(64) NOT NULL DEFAULT '',
-        description LONGTEXT NULL,
-        weight TINYINT(4) SIGNED NOT NULL DEFAULT '0',
-        PRIMARY KEY  (conid)
-      );");
-      /* The ad_channel_node table stores per node channel information.
-       */
-      db_query("CREATE TABLE {ad_channel_node} (
-        chid INT(11) UNSIGNED NOT NULL DEFAULT '0',
-        nid INT(11) UNSIGNED NOT NULL DEFAULT '0',
-        PRIMARY KEY  (chid, nid),
-        KEY (nid, chid)
-      );");
-      /* The ad_channel_node table stores per node channel information.
-       */
-      db_query("CREATE TABLE {ad_priority} (
-        aid INT(11) UNSIGNED NOT NULL DEFAULT '0',
-        priority TINYINT UNSIGNED NOT NULL DEFAULT '0',
-        PRIMARY KEY  (aid, priority)
-      );");
-  }
+  // Create tables
+  drupal_install_schema('ad_channel');
 }
 
 /**
  * Completely uninstall the ad channel module.
  */
 function ad_channel_uninstall() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-    default:
-      // TODO: PostgreSQL support.  Patches welcome.
-      db_query('DROP TABLE {ad_channel}');
-      db_query('DROP TABLE {ad_channel_container}');
-      db_query('DROP TABLE {ad_channel_node}');
-  }
+  // Drop tables
+  drupal_uninstall_schema('ad_channel');
 }
 
 /**