comparison ad.install @ 0:d8a3998dac8e ad

ajout module ad
author pierre
date Fri, 20 Feb 2009 14:04:09 +0000
parents
children 948362c2a207
comparison
equal deleted inserted replaced
-1:000000000000 0:d8a3998dac8e
1 <?php
2 // $Id: ad.install,v 1.2.2.4.2.27.2.7 2009/02/17 18:56:25 jeremy Exp $
3
4 /**
5 * @file
6 * Advertisement module database schema.
7 *
8 * Copyright (c) 2005-2009.
9 * Jeremy Andrews <jeremy@tag1consulting.com>.
10 */
11
12 /**
13 * Ad module database schema.
14 */
15 function ad_schema() {
16 /**
17 * The ad table stores administrative information about each ad. The
18 * actual ad itself can be found in the appropriate ad type table.
19 */
20 $schema['ads'] = array(
21 'description' => 'The ad table stores administrative information about each ad. The actual ad itself can be found in the appropriate ad type table.',
22 'fields' => array(
23 'aid' => array(
24 'type' => 'int',
25 'not null' => TRUE,
26 'unsigned' => TRUE,
27 'default' => 0,
28 'description' => 'Unique ad ID. Equals to ad nid.',
29 ),
30 'uid' => array(
31 'type' => 'int',
32 'not null' => TRUE,
33 'unsigned' => TRUE,
34 'default' => 0,
35 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
36 ),
37 'adstatus' => array(
38 'type' => 'varchar',
39 'length' => 255,
40 'not null' => TRUE,
41 'default' => '',
42 'description' => 'Ad status',
43 ),
44 'adtype' => array(
45 'type' => 'varchar',
46 'length' => 255,
47 'not null' => TRUE,
48 'default' => '',
49 'description' => 'Ad type',
50 ),
51 'redirect' => array(
52 'type' => 'varchar',
53 'length' => 255,
54 'not null' => TRUE,
55 'default' => '',
56 'description' => 'Ad redirect URL',
57 ),
58 'autoactivate' => array(
59 'type' => 'int',
60 'not null' => TRUE,
61 'unsigned' => TRUE,
62 'default' => 0,
63 'description' => 'Is ad autoactivating?',
64 ),
65 'autoactivated' => array(
66 'type' => 'int',
67 'not null' => TRUE,
68 'unsigned' => TRUE,
69 'default' => 0,
70 'description' => 'Is ad autoactivated?',
71 ),
72 'autoexpire' => array(
73 'type' => 'int',
74 'not null' => TRUE,
75 'unsigned' => TRUE,
76 'default' => 0,
77 'description' => 'Is ad autoexpiring?',
78 ),
79 'autoexpired' => array(
80 'type' => 'int',
81 'not null' => TRUE,
82 'unsigned' => TRUE,
83 'default' => 0,
84 'description' => 'Is ad autoexpired?',
85 ),
86 'activated' => array(
87 'type' => 'int',
88 'not null' => TRUE,
89 'unsigned' => TRUE,
90 'default' => 0,
91 'description' => 'Is ad activated?',
92 ),
93 'maxviews' => array(
94 'type' => 'int',
95 'not null' => TRUE,
96 'unsigned' => TRUE,
97 'default' => 0,
98 'description' => 'Maximum ad impressions',
99 ),
100 'maxclicks' => array(
101 'type' => 'int',
102 'not null' => TRUE,
103 'unsigned' => TRUE,
104 'default' => 0,
105 'description' => 'Maximum ad clicks',
106 ),
107 'expired' => array(
108 'type' => 'int',
109 'not null' => TRUE,
110 'unsigned' => TRUE,
111 'default' => 0,
112 'description' => 'Is ad expired?',
113 ),
114 ),
115 'primary key' => array('aid'),
116 'indexes' => array(
117 'uid' => array('uid'),
118 'autoactivate' => array('autoactivate'),
119 'autoactivate' => array('autoactivate'),
120 ),
121 );
122
123 /**
124 * This table counts each time a given action occurs on an ad. Actions
125 * include when the ad is viewed, clicked, enabled and disabled.
126 * Statistics are collected at an hourly granularity.
127 *
128 * The source column is used for tracking statistics for externally
129 * hosted ads.
130 *
131 * Actions:
132 * 'view', 'click', 'enable', 'disable'
133 */
134 $schema['ad_statistics'] = array(
135 'description' => 'Stores ad statistics.',
136 'fields' => array(
137 'sid' => array(
138 'type' => 'serial',
139 'not null' => TRUE,
140 'unsigned' => TRUE,
141 'description' => 'Statistics entry ID.',
142 ),
143 'aid' => array(
144 'type' => 'int',
145 'not null' => TRUE,
146 'unsigned' => TRUE,
147 'default' => 0,
148 'description' => 'Ad id.',
149 ),
150 'date' => array(
151 'type' => 'int',
152 'not null' => TRUE,
153 'unsigned' => TRUE,
154 'default' => 0,
155 'description' => 'Date when action was made.',
156 ),
157 'action' => array(
158 'type' => 'varchar',
159 'length' => 255,
160 'not null' => TRUE,
161 'default' => '',
162 'description' => 'Actions: "view", "click", "enable", "disable".',
163 ),
164 'adgroup' => array(
165 'type' => 'varchar',
166 'length' => 255,
167 'not null' => FALSE,
168 'default' => '',
169 'description' => 'Ad group.',
170 ),
171 'hostid' => array(
172 'type' => 'varchar',
173 'length' => 32,
174 'not null' => TRUE,
175 'default' => '',
176 'description' => 'Host from which acion was made.',
177 ),
178 'count' => array(
179 'type' => 'int',
180 'not null' => TRUE,
181 'unsigned' => TRUE,
182 'default' => 0,
183 'description' => 'Count of actions triggered.',
184 ),
185 ),
186 'primary key' => array('sid'),
187 'indexes' => array(
188 'aid' => array('aid'),
189 'date' => array('date'),
190 'action' => array('action'),
191 'adgroup' => array('adgroup'),
192 'hostid' => array('hostid'),
193 ),
194 );
195
196 /**
197 * The ad_clicks table tracks when a given advertisement was clicked,
198 * who clicked it (uid if any and IP address), and what page they were
199 * on when they clicked it.
200 */
201 $schema['ad_clicks'] = array(
202 'description' => 'The ad_clicks table tracks when a given advertisement was clicked, who clicked it (uid if any and IP address), and what page they were on when they clicked it.',
203 'fields' => array(
204 'cid' => array(
205 'type' => 'serial',
206 'not null' => TRUE,
207 'unsigned' => TRUE,
208 'description' => 'Statistics entry ID.',
209 ),
210 'aid' => array(
211 'type' => 'int',
212 'not null' => TRUE,
213 'unsigned' => TRUE,
214 'default' => 0,
215 'description' => 'Ad id.',
216 ),
217 'uid' => array(
218 'type' => 'int',
219 'not null' => TRUE,
220 'unsigned' => TRUE,
221 'default' => 0,
222 'description' => '',
223 ),
224 'status' => array(
225 'type' => 'int',
226 'size' => 'tiny',
227 'not null' => TRUE,
228 'unsigned' => TRUE,
229 'default' => 0,
230 'description' => '',
231 ),
232 'hostname' => array(
233 'type' => 'varchar',
234 'length' => 128,
235 'not null' => TRUE,
236 'default' => '',
237 'description' => 'Host from which acion was made.',
238 ),
239 'user_agent' => array(
240 'type' => 'varchar',
241 'length' => 255,
242 'not null' => TRUE,
243 'default' => '',
244 'description' => 'Clicker\'s browser agent.',
245 ),
246 'adgroup' => array(
247 'type' => 'varchar',
248 'length' => 255,
249 'not null' => TRUE,
250 'default' => '',
251 'description' => 'Ad group.',
252 ),
253 'hostid' => array(
254 'type' => 'varchar',
255 'length' => 32,
256 'not null' => TRUE,
257 'default' => '',
258 'description' => 'Host from which acion was made.',
259 ),
260 'url' => array(
261 'type' => 'varchar',
262 'length' => 255,
263 'not null' => FALSE,
264 'default' => '',
265 'description' => 'Clicked URL.',
266 ),
267 'timestamp' => array(
268 'type' => 'int',
269 'not null' => TRUE,
270 'unsigned' => TRUE,
271 'default' => 0,
272 'description' => 'Date when action was made.',
273 ),
274 ),
275 'primary key' => array('cid'),
276 'indexes' => array(
277 'aid' => array('aid'),
278 'status' => array('status'),
279 'hostname' => array('hostname'),
280 'user_agent' => array('user_agent'),
281 'adgroup' => array('adgroup'),
282 'hostid' => array('hostid'),
283 'url' => array('url'),
284 ),
285 );
286
287 /**
288 * The ad_hosts table is used to configure users that can display ads
289 * remotely.
290 */
291 $schema['ad_hosts'] = array(
292 'description' => 'The ad_hosts table is used to configure users that can display ads remotely. ',
293 'fields' => array(
294 'uid' => array(
295 'type' => 'int',
296 'not null' => TRUE,
297 'unsigned' => TRUE,
298 'default' => 0,
299 'description' => '',
300 ),
301 'hostid' => array(
302 'type' => 'varchar',
303 'length' => 32,
304 'not null' => TRUE,
305 'default' => '',
306 'description' => 'Host from which acion was made.',
307 ),
308 'status' => array(
309 'type' => 'int',
310 'size' => 'tiny',
311 'not null' => TRUE,
312 'unsigned' => TRUE,
313 'default' => 0,
314 'description' => '',
315 ),
316 'description' => array(
317 'type' => 'text',
318 'not null' => FALSE,
319 'description' => 'Host from which acion was made.',
320 ),
321 ),
322 'primary key' => array('uid'),
323 'indexes' => array(
324 'status' => array('status'),
325 'hostid' => array('hostid'),
326 ),
327 );
328
329 return $schema;
330 }
331
332 /**
333 * Ad module installation.
334 */
335 function ad_install() {
336 // Create tables.
337 drupal_install_schema('ad');
338 }
339
340 /**
341 * Allow complete uninstallation of the ad module.
342 */
343 function ad_uninstall() {
344 // Remove tables.
345 drupal_uninstall_schema('ad');
346
347 // Delete all ad content.
348 $result = db_query("SELECT nid FROM {node} WHERE type = 'ad'");
349 while ($node = db_fetch_object($result)) {
350 node_delete($node->nid);
351 variable_del("ad_autoactivate_warning_$node->nid");
352 }
353
354 // Delete all remaining ad module variables.
355 $variables = array('ad_cron_timestamp', 'ad_link_target', 'ad_cache', 'ad_cache_file', 'adserve', 'ad_group_vid', 'ad_groups', 'ad_validate_url', 'ad_display');
356 foreach ($variables as $variable) {
357 variable_del($variable);
358 }
359 db_query("DELETE FROM {variable} WHERE name LIKE 'ad_block_quantity_%'");
360 }
361
362 /**
363 * Convert some things from absolete dev. schema to new schema API
364 */
365 function ad_update_6001() {
366 $ret = array();
367 // When we touching index columns, we should first remove it from schema
368 db_drop_index($ret, 'ad_clicks', 'status');
369 db_change_field($ret, 'ad_clicks', 'status', 'status',
370 array(
371 'type' => 'int',
372 'size' => 'tiny',
373 'not null' => TRUE,
374 'unsigned' => TRUE,
375 'default' => 0,
376 'description' => '',
377 ),
378 array('indexes' => array(
379 'status' => array('status'),
380 ),
381 )
382 );
383 db_drop_index($ret, 'ad_hosts', 'status');
384 db_change_field($ret, 'ad_hosts', 'status', 'status',
385 array(
386 'type' => 'int',
387 'size' => 'tiny',
388 'not null' => TRUE,
389 'unsigned' => TRUE,
390 'default' => 0,
391 'description' => '',
392 ),
393 array('indexes' => array(
394 'status' => array('status'),
395 ),
396 )
397 );
398
399 db_drop_index($ret, 'ad_statistics', 'hostid');
400 db_change_field($ret, 'ad_statistics', 'hostid', 'hostid',
401 array(
402 'type' => 'varchar',
403 'length' => 32,
404 'not null' => TRUE,
405 'default' => '',
406 'description' => 'Host from which acion was made.',
407 ),
408 array('indexes' => array(
409 'hostid' => array('hostid'),
410 ),
411 )
412 );
413
414 db_drop_index($ret, 'ad_hosts', 'hostid');
415 db_change_field($ret, 'ad_hosts', 'hostid', 'hostid',
416 array(
417 'type' => 'varchar',
418 'length' => 32,
419 'not null' => TRUE,
420 'default' => '',
421 'description' => 'Host from which acion was made.',
422 ),
423 array('indexes' => array(
424 'hostid' => array('hostid'),
425 ),
426 )
427 );
428 return $ret;
429 }
430
431 /**
432 * Rebuild menu for anyone using the ad_embed module.
433 */
434 function ad_update_6002() {
435 menu_rebuild();
436 return array();
437 }
438
439 /**
440 * Flush all caches for new themeable ad display functions.
441 */
442 function ad_update_6003() {
443 drupal_flush_all_caches();
444 return array();
445 }