annotate channel/ad_channel.install @ 7:6aeff3329e01 ad

maj module ad 2.1rc1
author piotre
date Mon, 20 Jul 2009 13:54:40 +0000
parents 416ea999ed76
children 32c1a7d9e1fa
rev   line source
pierre@1 1 <?php
piotre@7 2 // $Id: ad_channel.install,v 1.1.4.8 2009/07/11 16:39:21 jeremy Exp $
pierre@1 3
pierre@1 4 /**
pierre@1 5 *
pierre@1 6 * Ad channel database schema.
pierre@1 7 * Copyright (c) 2008-2009 Jeremy Andrews <jeremy@tag1consulting.com>.
pierre@1 8 */
pierre@1 9
pierre@1 10 /**
pierre@1 11 * Create the ad_channel schema.
pierre@1 12 */
pierre@1 13 function ad_channel_install() {
pierre@1 14 switch ($GLOBALS['db_type']) {
pierre@1 15 case 'mysql':
pierre@1 16 case 'mysqli':
pierre@1 17 default:
pierre@1 18 // TODO: PostgreSQL support. Patches welcome.
pierre@1 19 /* The ad_channel table stores channel definitions and rules.
pierre@1 20 */
pierre@1 21 db_query("CREATE TABLE {ad_channel} (
pierre@1 22 chid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
pierre@1 23 name VARCHAR(64) NOT NULL DEFAULT '',
pierre@1 24 description LONGTEXT NULL,
pierre@1 25 conid INT(11) UNSIGNED NOT NULL DEFAULT '0',
pierre@1 26 weight TINYINT(4) SIGNED NOT NULL DEFAULT '0',
pierre@1 27 display TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
piotre@7 28 no_channel_percent INT(3) NOT NULL DEFAULT '0',
pierre@1 29 urls TEXT NULL,
pierre@1 30 groups TEXT NULL,
pierre@1 31 PRIMARY KEY (chid),
pierre@1 32 KEY (name)
pierre@1 33 );");
pierre@1 34 /* The ad_channel_container table stores channel container definitions.
pierre@1 35 */
pierre@1 36 db_query("CREATE TABLE {ad_channel_container} (
pierre@1 37 conid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
pierre@1 38 name VARCHAR(64) NOT NULL DEFAULT '',
pierre@1 39 description LONGTEXT NULL,
pierre@1 40 weight TINYINT(4) SIGNED NOT NULL DEFAULT '0',
pierre@1 41 PRIMARY KEY (conid)
pierre@1 42 );");
pierre@1 43 /* The ad_channel_node table stores per node channel information.
pierre@1 44 */
pierre@1 45 db_query("CREATE TABLE {ad_channel_node} (
pierre@1 46 chid INT(11) UNSIGNED NOT NULL DEFAULT '0',
pierre@1 47 nid INT(11) UNSIGNED NOT NULL DEFAULT '0',
pierre@1 48 PRIMARY KEY (chid, nid),
pierre@1 49 KEY (nid, chid)
pierre@1 50 );");
pierre@1 51 /* The ad_channel_node table stores per node channel information.
pierre@1 52 */
pierre@1 53 db_query("CREATE TABLE {ad_priority} (
pierre@1 54 aid INT(11) UNSIGNED NOT NULL DEFAULT '0',
pierre@1 55 priority TINYINT UNSIGNED NOT NULL DEFAULT '0',
pierre@1 56 PRIMARY KEY (aid, priority)
pierre@1 57 );");
pierre@1 58 }
pierre@1 59 }
pierre@1 60
pierre@1 61 /**
pierre@1 62 * Completely uninstall the ad channel module.
pierre@1 63 */
pierre@1 64 function ad_channel_uninstall() {
pierre@1 65 switch ($GLOBALS['db_type']) {
pierre@1 66 case 'mysql':
pierre@1 67 case 'mysqli':
pierre@1 68 default:
pierre@1 69 // TODO: PostgreSQL support. Patches welcome.
pierre@1 70 db_query('DROP TABLE {ad_channel}');
pierre@1 71 db_query('DROP TABLE {ad_channel_container}');
pierre@1 72 db_query('DROP TABLE {ad_channel_node}');
pierre@1 73 }
pierre@1 74 }
pierre@1 75
pierre@1 76 /**
pierre@1 77 * Populate the ad_priority table.
pierre@1 78 */
pierre@1 79 function ad_channel_update_6001() {
pierre@1 80 $ret = array();
pierre@1 81
pierre@1 82 $result = db_query('SELECT a.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid');
pierre@1 83 while ($ad = db_fetch_object($result)) {
pierre@1 84 if (!isset($ad->priority)) {
pierre@1 85 $ret[] = update_sql("INSERT INTO {ad_priority} (aid, priority) VALUES ($ad->aid, 0)");
pierre@1 86 }
pierre@1 87 }
pierre@1 88
pierre@1 89 return $ret;
pierre@1 90 }
pierre@1 91
sly@2 92 /**
sly@2 93 * Rebuild the menu so that channels and containers can be deleted.
sly@2 94 */
sly@2 95 function ad_channel_update_6002() {
sly@2 96 cache_clear_all();
sly@2 97 menu_rebuild();
sly@2 98 return array();
sly@2 99 }
sly@2 100
sly@2 101 /**
sly@2 102 * Introduce no_channel_weight.
sly@2 103 */
sly@2 104 function ad_channel_update_6003() {
sly@2 105 $ret = array();
sly@2 106 $ret[] = update_sql("ALTER TABLE {ad_channel} ADD no_channel_weight INT(3) NOT NULL DEFAULT '0'");
sly@2 107 return $ret;
sly@2 108 }
sly@2 109
piotre@7 110 /**
piotre@7 111 * Introduce no_channel_percent.
piotre@7 112 */
piotre@7 113 function ad_channel_update_6004() {
piotre@7 114 $ret = array();
piotre@7 115 $ret[] = update_sql("ALTER TABLE {ad_channel} CHANGE COLUMN no_channel_weight no_channel_percent INT(3) NOT NULL DEFAULT '0'");
piotre@7 116 // migration of no_channel_weights to no_channel_percent is an approximation
piotre@7 117 // to evenly distribute legacy values to new inorder to maintain weighting
piotre@7 118 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=20 WHERE no_channel_percent=25");
piotre@7 119 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=25 WHERE no_channel_percent=33");
piotre@7 120 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=35 WHERE no_channel_percent=50");
piotre@7 121 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=50 WHERE no_channel_percent=100");
piotre@7 122 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=65 WHERE no_channel_percent=200");
piotre@7 123 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=75 WHERE no_channel_percent=300");
piotre@7 124 $ret[] = update_sql("UPDATE {ad_channel} SET no_channel_percent=80 WHERE no_channel_percent=400");
piotre@7 125 return $ret;
piotre@7 126 }
piotre@7 127
piotre@7 128 /*
piotre@7 129 * Introduce channel inventory and remnant ads
piotre@7 130 */
piotre@7 131 function ad_channel_update_6005() {
piotre@7 132 $ret = array();
piotre@7 133 $ret[] = update_sql("ALTER TABLE {ad_channel} ADD inventory INT(11)");
piotre@7 134 $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 135 return $ret;
piotre@7 136 }