pierre@1: . pierre@1: */ pierre@1: pierre@1: /** pierre@1: * Create the ad_channel schema. pierre@1: */ sly@8: function ad_channel_schema() { sly@8: $schema['ad_channel'] = array( sly@8: 'description' => 'The ad_channel table allows advertisements to be organized into channels against which rules can be applied.', sly@8: 'fields' => array( sly@8: 'chid' => array( sly@8: 'type' => 'serial', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'description' => 'Unique channel ID.', sly@8: ), sly@8: 'name' => array( sly@8: 'type' => 'varchar', sly@8: 'length' => 64, sly@8: 'not null' => TRUE, sly@8: 'default' => '', sly@8: 'description' => 'The name of the channel.', sly@8: ), sly@8: 'description' => array( sly@8: 'type' => 'text', sly@8: 'size' => 'big', sly@8: 'not null' => FALSE, sly@8: 'description' => 'A description of the channel.', sly@8: ), sly@8: 'conid' => array( sly@8: 'type' => 'int', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: 'description' => 'ID of the container the channel is in.', sly@8: ), sly@8: 'weight' => array( sly@8: 'type' => 'int', sly@8: 'size' => 'medium', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: 'description' => 'Used when displaying channels to admins, heavier weights sink to the bottom.', sly@8: ), sly@8: 'display' => array( sly@8: 'type' => 'int', sly@8: 'size' => 'tiny', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: ), sly@8: 'no_channel_percent' => array( sly@8: 'type' => 'int', sly@8: 'size' => 'medium', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: ), sly@8: 'inventory' => array( sly@8: 'type' => 'int', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: ), sly@8: 'urls' => array( sly@8: 'type' => 'text', sly@8: ), sly@8: 'groups' => array( sly@8: 'type' => 'text', sly@8: ), sly@8: ), sly@8: 'primary key' => array('chid'), sly@8: 'indexes' => array( sly@8: 'name' => array('name'), sly@8: ), sly@8: ); sly@8: $schema['ad_channel_remnant'] = array( sly@8: 'fields' => array( sly@8: 'aid' => array( sly@8: 'type' => 'int', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: ), sly@8: 'remnant' => array( sly@8: 'type' => 'int', sly@8: 'size' => 'tiny', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: ), sly@8: ), sly@8: 'primary key' => array('aid', 'remnant'), sly@8: ); sly@8: $schema['ad_channel_container'] = array( sly@8: 'description' => 'The ad_channel_container table stores channel container definitions.', sly@8: 'fields' => array( sly@8: 'conid' => array( sly@8: 'type' => 'serial', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'description' => 'Unique container ID.', sly@8: ), sly@8: 'name' => array( sly@8: 'type' => 'varchar', sly@8: 'length' => 64, sly@8: 'not null' => TRUE, sly@8: 'default' => '', sly@8: 'description' => 'The name of the container.', sly@8: ), sly@8: 'description' => array( sly@8: 'type' => 'text', sly@8: 'size' => 'big', sly@8: 'not null' => FALSE, sly@8: 'description' => 'A description of the container.', sly@8: ), sly@8: 'weight' => array( sly@8: 'type' => 'int', sly@8: 'size' => 'medium', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: 'description' => 'Used when displaying channels to admins, heavier weights sink to the bottom.', sly@8: ), sly@8: ), sly@8: 'primary key' => array('conid'), sly@8: ); sly@8: $schema['ad_channel_node'] = array( sly@8: 'description' => 'The ad_channel_node table stores per node channel information.', sly@8: 'fields' => array( sly@8: 'chid' => array( sly@8: 'type' => 'int', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: ), sly@8: 'nid' => array( sly@8: 'type' => 'int', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: ), sly@8: ), sly@8: 'primary key' => array('chid', 'nid'), sly@8: 'indexes' => array( sly@8: 'nid_chid' => array('nid', 'chid'), sly@8: ), sly@8: ); sly@8: $schema['ad_priority'] = array( sly@8: 'fields' => array( sly@8: 'aid' => array( sly@8: 'type' => 'int', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: ), sly@8: 'priority' => array( sly@8: 'type' => 'int', sly@8: 'size' => 'tiny', sly@8: 'not null' => TRUE, sly@8: 'unsigned' => TRUE, sly@8: 'default' => 0, sly@8: ), sly@8: ), sly@8: 'primary key' => array('aid', 'priority'), sly@8: ); sly@8: return $schema; sly@8: } sly@8: pierre@1: function ad_channel_install() { sly@8: // Create tables sly@8: drupal_install_schema('ad_channel'); pierre@1: } pierre@1: pierre@1: /** pierre@1: * Completely uninstall the ad channel module. pierre@1: */ pierre@1: function ad_channel_uninstall() { sly@8: // Drop tables sly@8: drupal_uninstall_schema('ad_channel'); pierre@1: } pierre@1: pierre@1: /** pierre@1: * Populate the ad_priority table. pierre@1: */ pierre@1: function ad_channel_update_6001() { pierre@1: $ret = array(); pierre@1: pierre@1: $result = db_query('SELECT a.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid'); pierre@1: while ($ad = db_fetch_object($result)) { pierre@1: if (!isset($ad->priority)) { pierre@1: $ret[] = update_sql("INSERT INTO {ad_priority} (aid, priority) VALUES ($ad->aid, 0)"); pierre@1: } pierre@1: } pierre@1: pierre@1: return $ret; pierre@1: } pierre@1: sly@2: /** sly@2: * Rebuild the menu so that channels and containers can be deleted. sly@2: */ sly@2: function ad_channel_update_6002() { sly@2: cache_clear_all(); sly@2: menu_rebuild(); sly@2: return array(); sly@2: } sly@2: sly@2: /** sly@2: * Introduce no_channel_weight. sly@2: */ sly@2: function ad_channel_update_6003() { sly@2: $ret = array(); sly@2: $ret[] = update_sql("ALTER TABLE {ad_channel} ADD no_channel_weight INT(3) NOT NULL DEFAULT '0'"); sly@2: return $ret; sly@2: } sly@2: piotre@7: /** piotre@7: * Introduce no_channel_percent. piotre@7: */ piotre@7: function ad_channel_update_6004() { piotre@7: $ret = array(); piotre@7: $ret[] = update_sql("ALTER TABLE {ad_channel} CHANGE COLUMN no_channel_weight no_channel_percent INT(3) NOT NULL DEFAULT '0'"); piotre@7: // migration of no_channel_weights to no_channel_percent is an approximation piotre@7: // to evenly distribute legacy values to new inorder to maintain weighting piotre@7: $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=20 WHERE no_channel_percent=25"); piotre@7: $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=25 WHERE no_channel_percent=33"); piotre@7: $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=35 WHERE no_channel_percent=50"); piotre@7: $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=50 WHERE no_channel_percent=100"); piotre@7: $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=65 WHERE no_channel_percent=200"); piotre@7: $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=75 WHERE no_channel_percent=300"); piotre@7: $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=80 WHERE no_channel_percent=400"); piotre@7: return $ret; piotre@7: } piotre@7: piotre@7: /* piotre@7: * Introduce channel inventory and remnant ads piotre@7: */ piotre@7: function ad_channel_update_6005() { piotre@7: $ret = array(); piotre@7: $ret[] = update_sql("ALTER TABLE {ad_channel} ADD inventory INT(11)"); piotre@7: $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))"); piotre@7: return $ret; piotre@7: }