Projet

Général

Profil

Paste
Télécharger (9,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / commerce / modules / payment / commerce_payment.install @ 70a4c29b

1
<?php
2

    
3
/**
4
 * @file
5
 * Installation functions for Drupal Commerce Payment.
6
 */
7

    
8

    
9
/**
10
 * Implements hook_schema().
11
 */
12
function commerce_payment_schema() {
13
  $schema = array();
14

    
15
  $schema['commerce_payment_transaction'] = array(
16
    'description' => 'Transaction information for every attempted payment.',
17
    'fields' => array(
18
      'transaction_id' => array(
19
        'description' => 'The primary identifier for a transaction.',
20
        'type' => 'serial',
21
        'unsigned' => TRUE,
22
        'not null' => TRUE,
23
      ),
24
      'revision_id' => array(
25
        'description' => 'The current {commerce_payment_transaction_revision}.revision_id version identifier.',
26
        'type' => 'int',
27
        'unsigned' => TRUE,
28
        'not null' => FALSE,
29
      ),
30
      'uid' => array(
31
        'description' => 'The {users}.uid that created this transaction.',
32
        'type' => 'int',
33
        'not null' => TRUE,
34
        'default' => 0,
35
      ),
36
      'order_id' => array(
37
        'description' => 'The {commerce_order}.order_id of the order this payment is for.',
38
        'type' => 'int',
39
        'unsigned' => TRUE,
40
        'not null' => TRUE,
41
        'default' => 0,
42
      ),
43
      'payment_method' => array(
44
        'description' => 'The payment method method_id for this transaction.',
45
        'type' => 'varchar',
46
        'length' => 128,
47
        'not null' => TRUE,
48
      ),
49
      'instance_id' => array(
50
        'description' => 'The payment method instance ID for this transaction.',
51
        'type' => 'varchar',
52
        'length' => 255,
53
        'not null' => TRUE,
54
      ),
55
      'remote_id' => array(
56
        'description' => 'The remote identifier for this transaction.',
57
        'type' => 'varchar',
58
        'length' => 255,
59
        'not null' => TRUE,
60
      ),
61
      'message' => array(
62
        'description' => 'The human-readable message associated to this transaction.',
63
        'type' => 'text',
64
        'size' => 'big',
65
        'not null' => TRUE,
66
      ),
67
      'message_variables' => array(
68
        'description' => 'The variables associated with the human-readable message.',
69
        'type' => 'blob',
70
        'size' => 'big',
71
        'not null' => TRUE,
72
        'serialize' => TRUE,
73
      ),
74
      'amount' => array(
75
        'description' => 'The amount of this transaction.',
76
        'type' => 'int',
77
        'not null' => TRUE,
78
        'default' => 0,
79
      ),
80
      'currency_code' => array(
81
        'description' => 'The currency code for the price.',
82
        'type' => 'varchar',
83
        'length' => 32,
84
        'not null' => TRUE,
85
      ),
86
      'status' => array(
87
        'description' => 'The status of this transaction (pending, success, or failure).',
88
        'type' => 'varchar',
89
        'length' => 128,
90
        'not null' => TRUE,
91
      ),
92
      'remote_status' => array(
93
        'description' => 'The status of the transaction at the payment provider.',
94
        'type' => 'varchar',
95
        'length' => 128,
96
        'not null' => TRUE,
97
      ),
98
      'payload' => array(
99
        'description' => 'The payment-gateway specific payload associated with this transaction.',
100
        'type' => 'blob',
101
        'size' => 'big',
102
        'not null' => TRUE,
103
        'serialize' => TRUE,
104
      ),
105
      'created' => array(
106
        'description' => 'The Unix timestamp when this transaction was created.',
107
        'type' => 'int',
108
        'not null' => TRUE,
109
        'default' => 0,
110
      ),
111
      'changed' => array(
112
        'description' => 'The Unix timestamp when this transaction was last changed.',
113
        'type' => 'int',
114
        'not null' => TRUE,
115
        'default' => 0,
116
      ),
117
      'data' => array(
118
        'type' => 'blob',
119
        'not null' => FALSE,
120
        'size' => 'big',
121
        'serialize' => TRUE,
122
        'description' => 'A serialized array of additional data.',
123
      ),
124
    ),
125
    'primary key' => array('transaction_id'),
126
    'unique keys' => array(
127
      'revision_id' => array('revision_id'),
128
    ),
129
    'indexes' => array(
130
      'payment_method' => array('payment_method'),
131
      'uid' => array('uid'),
132
      'order_id' => array('order_id'),
133
    ),
134
    'foreign keys' => array(
135
      'payment_transaction_revision' => array(
136
        'table' => 'commerce_payment_transaction_revision',
137
        'columns'=> array('revision_id' => 'revision_id'),
138
      ),
139
      'creator' => array(
140
        'table' => 'users',
141
        'columns' => array('uid' => 'uid'),
142
      ),
143
      'order_id' => array(
144
        'table' => 'commerce_order',
145
        'columns'=> array('order_id' => 'order_id'),
146
      ),
147
    ),
148
  );
149

    
150
  $schema['commerce_payment_transaction_revision'] = array(
151
    'description' => 'Saves information about each saved revision of a {commerce_payment_transaction}.',
152
    'fields' => array(
153
      'transaction_id' => array(
154
        'description' => 'The primary identifier for a transaction.',
155
        'type' => 'int',
156
        'unsigned' => TRUE,
157
        'not null' => TRUE,
158
        'default' => 0,
159
      ),
160
      'revision_id' => array(
161
        'description' => 'The current {commerce_payment_transaction_revision}.revision_id version identifier.',
162
        'type' => 'serial',
163
        'unsigned' => TRUE,
164
        'not null' => TRUE,
165
      ),
166
      'revision_uid' => array(
167
        'description' => 'The {users}.uid that created this revision.',
168
        'type' => 'int',
169
        'not null' => TRUE,
170
        'default' => 0,
171
      ),
172
      'remote_id' => array(
173
        'description' => 'The remote identifier for this transaction.',
174
        'type' => 'varchar',
175
        'length' => 255,
176
        'not null' => TRUE,
177
      ),
178
      'message' => array(
179
        'description' => 'The human-readable message associated to this transaction.',
180
        'type' => 'text',
181
        'size' => 'big',
182
        'not null' => TRUE,
183
      ),
184
      'message_variables' => array(
185
        'description' => 'The variables associated with the human-readable message.',
186
        'type' => 'blob',
187
        'size' => 'big',
188
        'not null' => TRUE,
189
        'serialize' => TRUE,
190
      ),
191
      'amount' => array(
192
        'description' => 'The amount of this transaction.',
193
        'type' => 'int',
194
        'not null' => TRUE,
195
        'default' => 0,
196
      ),
197
      'currency_code' => array(
198
        'description' => 'The currency code for the price.',
199
        'type' => 'varchar',
200
        'length' => 32,
201
        'not null' => TRUE,
202
      ),
203
      'status' => array(
204
        'description' => 'The status of this transaction (pending, success, or failure).',
205
        'type' => 'varchar',
206
        'length' => 128,
207
        'not null' => TRUE,
208
      ),
209
      'remote_status' => array(
210
        'description' => 'The status of the transaction at the payment provider.',
211
        'type' => 'varchar',
212
        'length' => 128,
213
        'not null' => TRUE,
214
      ),
215
      'log' => array(
216
        'description' => 'The log entry explaining the changes in this version.',
217
        'type' => 'text',
218
        'not null' => TRUE,
219
        'size' => 'big',
220
      ),
221
      'revision_timestamp' => array(
222
        'description' => 'The Unix timestamp when this revision was created.',
223
        'type' => 'int',
224
        'not null' => TRUE,
225
        'default' => 0,
226
      ),
227
      'data' => array(
228
        'type' => 'blob',
229
        'not null' => FALSE,
230
        'size' => 'big',
231
        'serialize' => TRUE,
232
        'description' => 'A serialized array of additional data.',
233
      ),
234
    ),
235
    'indexes' => array(
236
      'transaction_id' => array('transaction_id'),
237
    ),
238
    'primary key' => array('revision_id'),
239
    'foreign keys' => array(
240
      'payment_transaction' => array(
241
        'table' => 'commerce_payment_transaction',
242
        'columns'=> array('transaction_id' => 'transaction_id'),
243
      ),
244
      'creator' => array(
245
        'table' => 'users',
246
        'columns' => array('revision_uid' => 'uid'),
247
      ),
248
    ),
249
  );
250

    
251
  return $schema;
252
}
253

    
254
/**
255
 * Add an index to the commerce_payment_transaction_revision table on transaction_id.
256
 */
257
function commerce_payment_update_7100() {
258
  if (db_index_exists('commerce_payment_transaction_revision', 'transaction_id')) {
259
    db_drop_index('commerce_payment_transaction_revision', 'transaction_id');
260
  }
261

    
262
  db_add_index('commerce_payment_transaction_revision', 'transaction_id', array('transaction_id'));
263
}
264

    
265
/**
266
 * Add indexes to the commerce_payment_transaction table on order_id and uid.
267
 */
268
function commerce_payment_update_7101() {
269
  if (db_index_exists('commerce_payment_transaction', 'uid')) {
270
    db_drop_index('commerce_payment_transaction', 'uid');
271
  }
272

    
273
  if (db_index_exists('commerce_payment_transaction', 'order_id')) {
274
    db_drop_index('commerce_payment_transaction', 'order_id');
275
  }
276

    
277
  db_add_index('commerce_payment_transaction', 'uid', array('uid'));
278
  db_add_index('commerce_payment_transaction', 'order_id', array('order_id'));
279

    
280
  return t('Database indexes added to the uid and order_id columns of the commerce_payment_transaction table.');
281
}
282

    
283
/**
284
 * Allow NULL values for revision_id on {commerce_payment_transaction} to avoid locking issues.
285
 */
286
function commerce_payment_update_7102() {
287
  db_change_field('commerce_payment_transaction', 'revision_id', 'revision_id', array(
288
    'description' => 'The current {commerce_payment_transaction_revision}.revision_id version identifier.',
289
    'type' => 'int',
290
    'unsigned' => TRUE,
291
    'not null' => FALSE,
292
  ));
293

    
294
  return t('Schema for the commerce_payment_transaction table has been updated.');
295
}