pierre@1: . pierre@1: */ pierre@1: pierre@1: /** pierre@1: * Create the ad_channel schema. pierre@1: */ pierre@1: function ad_channel_install() { pierre@1: switch ($GLOBALS['db_type']) { pierre@1: case 'mysql': pierre@1: case 'mysqli': pierre@1: default: pierre@1: // TODO: PostgreSQL support. Patches welcome. pierre@1: /* The ad_channel table stores channel definitions and rules. pierre@1: */ pierre@1: db_query("CREATE TABLE {ad_channel} ( pierre@1: chid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, pierre@1: name VARCHAR(64) NOT NULL DEFAULT '', pierre@1: description LONGTEXT NULL, pierre@1: conid INT(11) UNSIGNED NOT NULL DEFAULT '0', pierre@1: weight TINYINT(4) SIGNED NOT NULL DEFAULT '0', pierre@1: display TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', piotre@7: no_channel_percent INT(3) NOT NULL DEFAULT '0', pierre@1: urls TEXT NULL, pierre@1: groups TEXT NULL, pierre@1: PRIMARY KEY (chid), pierre@1: KEY (name) pierre@1: );"); pierre@1: /* The ad_channel_container table stores channel container definitions. pierre@1: */ pierre@1: db_query("CREATE TABLE {ad_channel_container} ( pierre@1: conid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, pierre@1: name VARCHAR(64) NOT NULL DEFAULT '', pierre@1: description LONGTEXT NULL, pierre@1: weight TINYINT(4) SIGNED NOT NULL DEFAULT '0', pierre@1: PRIMARY KEY (conid) pierre@1: );"); pierre@1: /* The ad_channel_node table stores per node channel information. pierre@1: */ pierre@1: db_query("CREATE TABLE {ad_channel_node} ( pierre@1: chid INT(11) UNSIGNED NOT NULL DEFAULT '0', pierre@1: nid INT(11) UNSIGNED NOT NULL DEFAULT '0', pierre@1: PRIMARY KEY (chid, nid), pierre@1: KEY (nid, chid) pierre@1: );"); pierre@1: /* The ad_channel_node table stores per node channel information. pierre@1: */ pierre@1: db_query("CREATE TABLE {ad_priority} ( pierre@1: aid INT(11) UNSIGNED NOT NULL DEFAULT '0', pierre@1: priority TINYINT UNSIGNED NOT NULL DEFAULT '0', pierre@1: PRIMARY KEY (aid, priority) pierre@1: );"); pierre@1: } pierre@1: } pierre@1: pierre@1: /** pierre@1: * Completely uninstall the ad channel module. pierre@1: */ pierre@1: function ad_channel_uninstall() { pierre@1: switch ($GLOBALS['db_type']) { pierre@1: case 'mysql': pierre@1: case 'mysqli': pierre@1: default: pierre@1: // TODO: PostgreSQL support. Patches welcome. pierre@1: db_query('DROP TABLE {ad_channel}'); pierre@1: db_query('DROP TABLE {ad_channel_container}'); pierre@1: db_query('DROP TABLE {ad_channel_node}'); pierre@1: } 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: }