Newer
Older
<?php
// $Id$
Alexander Shvets
committed
/**
* @file
* Advertisement module database schema.
*
* Copyright (c) 2005-2009.
* Jeremy Andrews <jeremy@tag1consulting.com>.
Alexander Shvets
committed
*/
/**
* Ad module database schema.
*/
Alexander Shvets
committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function ad_schema() {
/**
* The ad table stores administrative information about each ad. The
* actual ad itself can be found in the appropriate ad type table.
*/
$schema['ads'] = array(
'description' => 'The ad table stores administrative information about each ad. The actual ad itself can be found in the appropriate ad type table.',
'fields' => array(
'aid' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Unique ad ID. Equals to ad nid.',
),
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
),
'adstatus' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Ad status',
),
'adtype' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Ad type',
),
'redirect' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Ad redirect URL',
),
'autoactivate' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Is ad autoactivating?',
),
'autoactivated' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Is ad autoactivated?',
),
'autoexpire' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Is ad autoexpiring?',
),
'autoexpired' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Is ad autoexpired?',
),
'activated' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Is ad activated?',
),
'maxviews' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
Alexander Shvets
committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
),
'maxclicks' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Maximum ad clicks',
),
'expired' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Is ad expired?',
),
),
'primary key' => array('aid'),
'indexes' => array(
'uid' => array('uid'),
'autoactivate' => array('autoactivate'),
'autoactivate' => array('autoactivate'),
),
);
/**
* This table counts each time a given action occurs on an ad. Actions
* include when the ad is viewed, clicked, enabled and disabled.
* Statistics are collected at an hourly granularity.
*
* The source column is used for tracking statistics for externally
* hosted ads.
*
* Actions:
* 'view', 'click', 'enable', 'disable'
*/
$schema['ad_statistics'] = array(
'description' => 'Stores ad statistics.',
'fields' => array(
'sid' => array(
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
'description' => 'Statistics entry ID.',
),
'aid' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Ad id.',
),
'date' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Date when action was made.',
),
'action' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Actions: "view", "click", "enable", "disable".',
),
'adgroup' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
'description' => 'Ad group.',
),
'hostid' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'Host from which acion was made.',
),
'count' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Count of actions triggered.',
),
'extra' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Alow add-on modules to provide additional statistics granularity.',
),
Alexander Shvets
committed
),
'primary key' => array('sid'),
'indexes' => array(
Alexander Shvets
committed
'date' => array('date'),
'action' => array('action'),
'adgroup' => array('adgroup'),
'hostid' => array('hostid'),
Alexander Shvets
committed
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
),
);
/**
* 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.
*/
$schema['ad_clicks'] = array(
'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.',
'fields' => array(
'cid' => array(
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
'description' => 'Statistics entry ID.',
),
'aid' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Ad id.',
),
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => '',
),
'status' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => '',
),
'hostname' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Host from which acion was made.',
),
'user_agent' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Clicker\'s browser agent.',
),
'adgroup' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Ad group.',
),
'hostid' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'Host from which acion was made.',
),
'url' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
'description' => 'Clicked URL.',
),
'timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => 'Date when action was made.',
),
'extra' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Alow add-on modules to provide additional statistics granularity.',
),
Alexander Shvets
committed
),
'primary key' => array('cid'),
'indexes' => array(
'aid' => array('aid'),
'status' => array('status'),
'hostname' => array('hostname'),
'user_agent' => array('user_agent'),
'adgroup' => array('adgroup'),
'hostid' => array('hostid'),
'url' => array('url'),
Alexander Shvets
committed
),
);
return $schema;
}
Alexander Shvets
committed
/**
* Ad module installation.
*/
function ad_install() {
Alexander Shvets
committed
// Create tables.
drupal_install_schema('ad');
/**
* Allow complete uninstallation of the ad module.
*/
function ad_uninstall() {
// Delete all ad content.
$result = db_query("SELECT nid FROM {node} WHERE type = 'ad'");
while ($node = db_fetch_object($result)) {
node_delete($node->nid);
variable_del("ad_autoactivate_warning_$node->nid");
$variables = array('ad_cron_timestamp', 'ad_link_target', 'ad_cache', 'ad_cache_file', 'adserve', 'ad_group_vid', 'ad_groups', 'ad_validate_url', 'ad_display');
Alexander Shvets
committed
db_query("DELETE FROM {variable} WHERE name LIKE 'ad_block_quantity_%'");
// Remove tables.
drupal_uninstall_schema('ad');
Alexander Shvets
committed
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/**
* Convert some things from absolete dev. schema to new schema API
*/
function ad_update_6001() {
$ret = array();
// When we touching index columns, we should first remove it from schema
db_drop_index($ret, 'ad_clicks', 'status');
db_change_field($ret, 'ad_clicks', 'status', 'status',
array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => '',
),
array('indexes' => array(
'status' => array('status'),
),
)
);
db_drop_index($ret, 'ad_hosts', 'status');
db_change_field($ret, 'ad_hosts', 'status', 'status',
array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => '',
),
array('indexes' => array(
'status' => array('status'),
),
)
);
db_drop_index($ret, 'ad_statistics', 'hostid');
db_change_field($ret, 'ad_statistics', 'hostid', 'hostid',
array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'Host from which acion was made.',
),
array('indexes' => array(
'hostid' => array('hostid'),
),
)
);
db_drop_index($ret, 'ad_hosts', 'hostid');
db_change_field($ret, 'ad_hosts', 'hostid', 'hostid',
array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'Host from which acion was made.',
),
array('indexes' => array(
'hostid' => array('hostid'),
),
)
);
return $ret;
}
/**
* Rebuild menu for anyone using the ad_embed module.
*/
function ad_update_6002() {
menu_rebuild();
return array();
}
/**
* Flush all caches for new themeable ad display functions.
*/
function ad_update_6003() {
drupal_flush_all_caches();
return array();
}
/**
* Introduce "extra" field for ad statistics and clicks, optionally allowing
* add-on modules to provide additional granularity.
*/
function ad_update_6004() {
$ret = array();
array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Alow add-on modules to provide additional statistics granularity.',
),
array('indexes' => array(
'extra' => array('extra'))
));
array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Alow add-on modules to provide additional statistics granularity.',
),
array('indexes' => array(
'extra' => array('extra'))
));
return $ret;
}
/**
* Flush all caches for AHAH ad type switcher to work.
*/
function ad_update_6005() {
drupal_flush_all_caches();
return array();
}
/**
* Flush all caches
*/
function ad_update_6006() {
drupal_flush_all_caches();
return array();
}
/**
* Add new index to ad_statistics table for running reports.
*/
function ad_update_6007() {
$ret = array();
db_add_index($ret, 'ad_statistics', 'aid_date_action', array('aid', 'date', 'action'));
db_drop_index($ret, 'ad_statistics', 'aid');
/**
* If block caching is enabled, make it a per-page cache. This is necessary
* to fix bug #604350.
*/
function ad_update_6008() {
$ret = array();
$ret[] = update_sql("UPDATE {blocks} SET cache = ". BLOCK_CACHE_PER_PAGE ." WHERE module = 'ad'");
return $ret;
}