annotate channel/ad_channel.install @ 1:948362c2a207 ad

update advertisement
author pierre
date Thu, 02 Apr 2009 15:28:21 +0000
parents
children e5584a19768b
rev   line source
pierre@1 1 <?php
pierre@1 2 // $Id: ad_channel.install,v 1.1.4.3 2009/03/05 21:20:36 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',
pierre@1 28 urls TEXT NULL,
pierre@1 29 groups TEXT NULL,
pierre@1 30 PRIMARY KEY (chid),
pierre@1 31 KEY (name)
pierre@1 32 );");
pierre@1 33 /* The ad_channel_container table stores channel container definitions.
pierre@1 34 */
pierre@1 35 db_query("CREATE TABLE {ad_channel_container} (
pierre@1 36 conid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
pierre@1 37 name VARCHAR(64) NOT NULL DEFAULT '',
pierre@1 38 description LONGTEXT NULL,
pierre@1 39 weight TINYINT(4) SIGNED NOT NULL DEFAULT '0',
pierre@1 40 PRIMARY KEY (conid)
pierre@1 41 );");
pierre@1 42 /* The ad_channel_node table stores per node channel information.
pierre@1 43 */
pierre@1 44 db_query("CREATE TABLE {ad_channel_node} (
pierre@1 45 chid INT(11) UNSIGNED NOT NULL DEFAULT '0',
pierre@1 46 nid INT(11) UNSIGNED NOT NULL DEFAULT '0',
pierre@1 47 PRIMARY KEY (chid, nid),
pierre@1 48 KEY (nid, chid)
pierre@1 49 );");
pierre@1 50 /* The ad_channel_node table stores per node channel information.
pierre@1 51 */
pierre@1 52 db_query("CREATE TABLE {ad_priority} (
pierre@1 53 aid INT(11) UNSIGNED NOT NULL DEFAULT '0',
pierre@1 54 priority TINYINT UNSIGNED NOT NULL DEFAULT '0',
pierre@1 55 PRIMARY KEY (aid, priority)
pierre@1 56 );");
pierre@1 57 }
pierre@1 58 }
pierre@1 59
pierre@1 60 /**
pierre@1 61 * Completely uninstall the ad channel module.
pierre@1 62 */
pierre@1 63 function ad_channel_uninstall() {
pierre@1 64 switch ($GLOBALS['db_type']) {
pierre@1 65 case 'mysql':
pierre@1 66 case 'mysqli':
pierre@1 67 default:
pierre@1 68 // TODO: PostgreSQL support. Patches welcome.
pierre@1 69 db_query('DROP TABLE {ad_channel}');
pierre@1 70 db_query('DROP TABLE {ad_channel_container}');
pierre@1 71 db_query('DROP TABLE {ad_channel_node}');
pierre@1 72 }
pierre@1 73 }
pierre@1 74
pierre@1 75 /**
pierre@1 76 * Populate the ad_priority table.
pierre@1 77 */
pierre@1 78 function ad_channel_update_6001() {
pierre@1 79 $ret = array();
pierre@1 80
pierre@1 81 $result = db_query('SELECT a.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid');
pierre@1 82 while ($ad = db_fetch_object($result)) {
pierre@1 83 if (!isset($ad->priority)) {
pierre@1 84 $ret[] = update_sql("INSERT INTO {ad_priority} (aid, priority) VALUES ($ad->aid, 0)");
pierre@1 85 }
pierre@1 86 }
pierre@1 87
pierre@1 88 return $ret;
pierre@1 89 }
pierre@1 90