-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommerce_license_billing.install
256 lines (247 loc) · 7.41 KB
/
commerce_license_billing.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
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
<?php
/**
* Implements hook_schema().
*/
function commerce_license_billing_schema() {
$schema['cl_billing_cycle'] = array(
'description' => 'The base table for the commerce_license_billing_cycle entity type.',
'fields' => array(
'billing_cycle_id' => array(
'description' => 'The primary identifier for a billing cycle.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'The {cl_billing_cycle_type}.name of this billing cycle.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'uid' => array(
'description' => 'The {users}.uid that created this billing cycle belongs to.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'start' => array(
'description' => 'The Unix timestamp when the billing cycle starts.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'end' => array(
'description' => 'The Unix timestamp when the billing cycle ends.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'status' => array(
'description' => 'Whether the billing cycle is open or closed.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('billing_cycle_id'),
'indexes' => array(
'uid' => array('uid'),
),
);
$schema['cl_billing_cycle_type'] = array(
'description' => 'The base table for the cl_billing_cycle_type entity type.',
'fields' => array(
'billing_cycle_type_id' => array(
'description' => 'The primary identifier for a billing cycle type.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'engine' => array(
'description' => 'The engine for this billing cycle type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'name' => array(
'description' => 'The machine-readable name of this billing cycle type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'title' => array(
'description' => 'The human-readable name of the billing cycle type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'description' => 'The exportable status of the billing cycle type.',
'type' => 'int',
'not null' => TRUE,
// Set the default to ENTITY_CUSTOM without using the constant as it is
// not safe to use it at this point.
'default' => 0x01,
'size' => 'tiny',
),
'module' => array(
'description' => 'The name of the providing module if the type has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'unique keys' => array(
'name' => array('name'),
),
'primary key' => array('billing_cycle_type_id'),
);
$schema['cl_billing_usage'] = array(
'description' => 'Tracks license usage.',
'fields' => array(
'usage_id' => array(
'description' => 'The primary key.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'license_id' => array(
'description' => 'The id of the license.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'revision_id' => array(
'description' => 'The revision id of the license.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'usage_group' => array(
'description' => 'The usage group, as defined in $license->usageGroups().',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'quantity' => array(
'description' => 'The usage quantity.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'start' => array(
'description' => 'The Unix timestamp when usage began.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'end' => array(
'description' => 'The Unix timestamp when usage ended.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('usage_id'),
'indexes' => array(
'license_and_times' => array('license_id', 'start', 'end'),
),
);
$schema['cl_scheduled_change'] = array(
'description' => 'Tracks license changes scheduled for the end of the billing cycle.',
'fields' => array(
'change_id' => array(
'description' => 'The primary key.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'license_id' => array(
'description' => 'The id of the license.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'property' => array(
'description' => 'The property that will be changed, usually product_id or status.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'value' => array(
'description' => 'The new value of the property.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the change was scheduled.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('change_id'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function commerce_license_billing_install() {
variable_set('bundleswitcher__cl_billing_cycle_type', TRUE);
}
/**
* Implements hook_uninstall().
*/
function commerce_license_billing_uninstall() {
variable_del('bundleswitcher__cl_billing_cycle_type');
// Remove the product fields.
field_delete_field('cl_billing_cycle_type');
field_delete_field('cl_billing_type');
field_delete_field('cl_schedule_changes');
// Remove our bundles.
field_attach_delete_bundle('cl_billing_cycle_type', 'periodic');
field_attach_delete_bundle('commerce_line_item', 'recurring');
field_attach_delete_bundle('commerce_order', 'recurring');
}
/**
* Creates the 'cl_scheduled_change' table.
*/
function commerce_license_billing_update_7100() {
$schema = commerce_license_billing_schema();
db_create_table('cl_scheduled_change', $schema['cl_scheduled_change']);
}
/**
* Allow additional billing cycle periods.
*/
function commerce_license_billing_update_7101() {
$field = field_info_field('pce_period');
$field['settings'] = array(
'allowed_values' => array(
'hour' => 'Hour',
'day' => 'Day',
'week' => 'Week',
'month' => 'Month',
'quarter' => 'Quarter',
'half-year' => 'Half-year',
'year' => 'Year',
),
);
field_update_field($field);
}
/**
* Add an index to license_id, start and end for commerce_license_billing_usage_history_list().
*/
function commerce_license_billing_update_7102() {
if (!db_index_exists('cl_billing_usage', 'license_and_times')) {
db_add_index('cl_billing_usage', 'license_and_times', array('license_id', 'start', 'end'));
}
}