forked from mikl/ding_campaign
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ding_campaign.install
209 lines (185 loc) · 5.01 KB
/
ding_campaign.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
98
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* @file ding_campaign.install
* Installation and upgrade hooks for the ding_campaign module.
*/
/**
* Implementation of hook_install().
*/
function ding_campaign_install() {
drupal_install_schema('ding_campaign');
variable_set('admin_theme_ding_campaign_ding_campaign_rules', 1);
}
/**
* Implementation of hook_uninstall().
*/
function ding_campaign_uninstall() {
drupal_uninstall_schema('ding_campaign');
variable_del('admin_theme_ding_campaign_ding_campaign_rules');
}
/**
* Implementation of hook_schema().
*/
function ding_campaign_schema() {
$schema['ding_campaign'] = array(
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => '{node}.vid for node',
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => '{node}.nid for node',
),
'campaign_type' => array(
'type' => 'varchar',
'length' => 50,
'default' => 'normal',
'description' => 'The campaign type, image-only, text-only, etc.',
),
'campaign_theme' => array(
'type' => 'varchar',
'length' => 50,
'default' => 'normal',
'description' => 'The campaign colour scheme.',
),
'campaign_weight' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('vid', 'nid'),
'indexes' => array(
'nid' => array('nid'),
'campaign_weight' => array('campaign_weight'),
),
);
$schema['ding_campaign_rule'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => '{node}.nid for node',
),
'status' => array(
'description' => 'Denormalised mirror of {node}.status so we can filter out unpublished campaigns without requiring a JOIN',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'delta' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Rule number - unique per node.',
),
'type' => array(
'type' => 'varchar',
'length' => 50,
'description' => 'Rule type - one of library, page, taxonomy and search_term',
),
'value' => array(
'type' => 'varchar',
'length' => 255,
'description' => 'Rule value, text-version. Canonical for search term only',
),
'value_id' => array(
'type' => 'int',
'unsigned' => true,
'not null' => FALSE,
'description' => 'Rule value ID. For the applicable types it serves as a foreign key to nodes, terms, etc.',
),
),
'primary key' => array('nid', 'delta'),
'indexes' => array(
'nid_status' => array('nid', 'status'),
'type' => array('type'),
'value' => array('value'),
'value_id' => array('value_id'),
),
);
return $schema;
}
/**
* Implementation of hook_update_N().
*
* Rename system_path to path to reflect that they now work for both
* system paths and path aliases.
*/
function ding_campaign_update_6001(&$sandbox) {
$ret = array();
$ret[] = update_sql("UPDATE {ding_campaign_rule} SET `type` = 'path' WHERE `type` = 'system_path';");
return $ret;
}
/**
* Implementation of hook_update_N().
*
* Remove campaign rules on non-campaign nodes.
*/
function ding_campaign_update_6002(&$sandbox) {
$ret = array();
$ret[] = update_sql("
DELETE dcr FROM {ding_campaign_rule} AS dcr
LEFT JOIN {node} AS n USING(nid)
WHERE n.type != 'campaign';
");
return $ret;
}
/**
* Implementation of hook_update_N().
*
* Create cache table for Ding campaigns.
*/
function ding_campaign_update_6003(&$sandbox) {
$ret = array();
db_create_table($ret, 'cache_ding_campaign',
drupal_get_schema_unprocessed('system', 'cache'));
return $ret;
}
/**
* Implementation of hook_update_N().
*
* Delete cache table for Ding campaigns.
*/
function ding_campaign_update_6004(&$sandbox) {
$ret = array();
db_drop_table($ret, 'cache_ding_campaign');
return $ret;
}
/**
* Add status column to campaign rule table.
*/
function ding_campaign_update_6005(&$sandbox) {
$ret = array();
db_add_field($ret, 'ding_campaign_rule', 'status', array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
// Add status to the index, since we always filter on it.
db_drop_index($ret, 'ding_campaign_rule', 'nid');
db_add_index($ret, 'ding_campaign_rule', 'nid_status', array('nid', 'status'));
return $ret;
}
/**
* Set rule status from node table.
*/
function ding_campaign_update_6006(&$sandbox) {
$ret = array();
$ret[] = update_sql("
UPDATE {ding_campaign_rule} AS dcr
LEFT JOIN node AS n USING (nid)
SET dcr.status = n.status
WHERE n.status <> 0
");
return $ret;
}