Mercurial > defr > drupal > ad
comparison channel/ad_channel.install @ 1:948362c2a207 ad
update advertisement
author | pierre |
---|---|
date | Thu, 02 Apr 2009 15:28:21 +0000 |
parents | |
children | e5584a19768b |
comparison
equal
deleted
inserted
replaced
0:d8a3998dac8e | 1:948362c2a207 |
---|---|
1 <?php | |
2 // $Id: ad_channel.install,v 1.1.4.3 2009/03/05 21:20:36 jeremy Exp $ | |
3 | |
4 /** | |
5 * | |
6 * Ad channel database schema. | |
7 * Copyright (c) 2008-2009 Jeremy Andrews <jeremy@tag1consulting.com>. | |
8 */ | |
9 | |
10 /** | |
11 * Create the ad_channel schema. | |
12 */ | |
13 function ad_channel_install() { | |
14 switch ($GLOBALS['db_type']) { | |
15 case 'mysql': | |
16 case 'mysqli': | |
17 default: | |
18 // TODO: PostgreSQL support. Patches welcome. | |
19 /* The ad_channel table stores channel definitions and rules. | |
20 */ | |
21 db_query("CREATE TABLE {ad_channel} ( | |
22 chid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, | |
23 name VARCHAR(64) NOT NULL DEFAULT '', | |
24 description LONGTEXT NULL, | |
25 conid INT(11) UNSIGNED NOT NULL DEFAULT '0', | |
26 weight TINYINT(4) SIGNED NOT NULL DEFAULT '0', | |
27 display TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', | |
28 urls TEXT NULL, | |
29 groups TEXT NULL, | |
30 PRIMARY KEY (chid), | |
31 KEY (name) | |
32 );"); | |
33 /* The ad_channel_container table stores channel container definitions. | |
34 */ | |
35 db_query("CREATE TABLE {ad_channel_container} ( | |
36 conid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, | |
37 name VARCHAR(64) NOT NULL DEFAULT '', | |
38 description LONGTEXT NULL, | |
39 weight TINYINT(4) SIGNED NOT NULL DEFAULT '0', | |
40 PRIMARY KEY (conid) | |
41 );"); | |
42 /* The ad_channel_node table stores per node channel information. | |
43 */ | |
44 db_query("CREATE TABLE {ad_channel_node} ( | |
45 chid INT(11) UNSIGNED NOT NULL DEFAULT '0', | |
46 nid INT(11) UNSIGNED NOT NULL DEFAULT '0', | |
47 PRIMARY KEY (chid, nid), | |
48 KEY (nid, chid) | |
49 );"); | |
50 /* The ad_channel_node table stores per node channel information. | |
51 */ | |
52 db_query("CREATE TABLE {ad_priority} ( | |
53 aid INT(11) UNSIGNED NOT NULL DEFAULT '0', | |
54 priority TINYINT UNSIGNED NOT NULL DEFAULT '0', | |
55 PRIMARY KEY (aid, priority) | |
56 );"); | |
57 } | |
58 } | |
59 | |
60 /** | |
61 * Completely uninstall the ad channel module. | |
62 */ | |
63 function ad_channel_uninstall() { | |
64 switch ($GLOBALS['db_type']) { | |
65 case 'mysql': | |
66 case 'mysqli': | |
67 default: | |
68 // TODO: PostgreSQL support. Patches welcome. | |
69 db_query('DROP TABLE {ad_channel}'); | |
70 db_query('DROP TABLE {ad_channel_container}'); | |
71 db_query('DROP TABLE {ad_channel_node}'); | |
72 } | |
73 } | |
74 | |
75 /** | |
76 * Populate the ad_priority table. | |
77 */ | |
78 function ad_channel_update_6001() { | |
79 $ret = array(); | |
80 | |
81 $result = db_query('SELECT a.aid, p.priority FROM {ads} a LEFT JOIN {ad_priority} p ON a.aid = p.aid'); | |
82 while ($ad = db_fetch_object($result)) { | |
83 if (!isset($ad->priority)) { | |
84 $ret[] = update_sql("INSERT INTO {ad_priority} (aid, priority) VALUES ($ad->aid, 0)"); | |
85 } | |
86 } | |
87 | |
88 return $ret; | |
89 } | |
90 |