Projet

Général

Profil

Paste
Télécharger (8,45 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / commerce / modules / customer / commerce_customer.install @ b858700c

1
<?php
2

    
3
/**
4
 * Implements hook_schema().
5
 */
6
function commerce_customer_schema() {
7
  $schema = array();
8

    
9
  $schema['commerce_customer_profile'] = array(
10
    'description' => 'The base table for customer profiles.',
11
    'fields' => array(
12
      'profile_id' => array(
13
        'description' => 'The primary identifier for a customer profile.',
14
        'type' => 'serial',
15
        'unsigned' => TRUE,
16
        'not null' => TRUE,
17
      ),
18
      'revision_id' => array(
19
        'description' => 'The current {commerce_customer_profile_revision}.revision_id version identifier.',
20
        'type' => 'int',
21
        'unsigned' => TRUE,
22
        'not null' => FALSE,
23
      ),
24
      'type' => array(
25
        'description' => 'The {commerce_customer_profile_type}.type of this profile.',
26
        'type' => 'varchar',
27
        'length' => 255,
28
        'not null' => TRUE,
29
        'default' => '',
30
      ),
31
      'uid' => array(
32
        'description' => 'The {users}.uid that this profile belongs to.',
33
        'type' => 'int',
34
        'not null' => TRUE,
35
        'default' => 0,
36
      ),
37
      'status' => array(
38
        'description' => 'Boolean indicating whether the profile is active or not.',
39
        'type' => 'int',
40
        'not null' => TRUE,
41
        'default' => 0,
42
      ),
43
      'created' => array(
44
        'description' => 'The Unix timestamp when the profile was created.',
45
        'type' => 'int',
46
        'not null' => TRUE,
47
        'default' => 0,
48
      ),
49
      'changed' => array(
50
        'description' => 'The Unix timestamp when the profile was most recently saved.',
51
        'type' => 'int',
52
        'not null' => TRUE,
53
        'default' => 0,
54
      ),
55
      'data' => array(
56
        'type' => 'blob',
57
        'not null' => FALSE,
58
        'size' => 'big',
59
        'serialize' => TRUE,
60
        'description' => 'A serialized array of additional data.',
61
      ),
62
    ),
63
    'primary key' => array('profile_id'),
64
    'unique keys' => array(
65
      'revision_id' => array('revision_id'),
66
    ),
67
    'indexes' => array(
68
      'uid' => array('uid'),
69
      'customer_profile_type' => array('type'),
70
      'uid_by_type' => array('uid', 'type'),
71
    ),
72
    'foreign keys' => array(
73
      'customer_profile_revision' => array(
74
        'table' => 'commerce_customer_profile_revision',
75
        'columns'=> array('revision_id' => 'revision_id'),
76
      ),
77
      'owner' => array(
78
        'table' => 'users',
79
        'columns' => array('uid' => 'uid'),
80
      ),
81
    ),
82
  );
83

    
84
  $schema['commerce_customer_profile_revision'] = array(
85
    'description' => 'Saves information about each saved revision of a {commerce_customer_profile}.',
86
    'fields' => array(
87
      'profile_id' => array(
88
        'description' => 'The {commerce_customer_profile}.customer_id of the profile this revision belongs to.',
89
        'type' => 'int',
90
        'unsigned' => TRUE,
91
        'not null' => TRUE,
92
        'default' => 0,
93
      ),
94
      'revision_id' => array(
95
        'description' => 'The primary identifier for this revision.',
96
        'type' => 'serial',
97
        'unsigned' => TRUE,
98
        'not null' => TRUE,
99
      ),
100
      'revision_uid' => array(
101
        'description' => 'The {users}.uid that created this profile at this revision.',
102
        'type' => 'int',
103
        'not null' => TRUE,
104
        'default' => 0,
105
      ),
106
      'status' => array(
107
        'description' => 'Boolean indicating whether the profile is active or not.',
108
        'type' => 'int',
109
        'not null' => TRUE,
110
        'default' => 0,
111
      ),
112
      'log' => array(
113
        'description' => 'The log entry explaining the changes in this version.',
114
        'type' => 'text',
115
        'not null' => TRUE,
116
        'size' => 'big',
117
      ),
118
      'revision_timestamp' => array(
119
        'description' => 'The Unix timestamp when this revision was created.',
120
        'type' => 'int',
121
        'not null' => TRUE,
122
        'default' => 0,
123
      ),
124
      'data' => array(
125
        'type' => 'blob',
126
        'not null' => FALSE,
127
        'size' => 'big',
128
        'serialize' => TRUE,
129
        'description' => 'A serialized array of additional data.',
130
      ),
131
    ),
132
    'primary key' => array('revision_id'),
133
    'indexes' => array(
134
      'profile_id' => array('profile_id'),
135
    ),
136
    'foreign keys' => array(
137
      'customer_profile' => array(
138
        'table' => 'commerce_customer_profile',
139
        'columns'=> array('profile_id' => 'profile_id'),
140
      ),
141
      'creator' => array(
142
        'table' => 'users',
143
        'columns' => array('uid' => 'uid'),
144
      ),
145
    ),
146
  );
147

    
148
  return $schema;
149
}
150

    
151
/**
152
 * Implements hook_field_schema().
153
 */
154
function commerce_customer_field_schema($field) {
155
  if ($field['type'] == 'commerce_customer_profile_reference') {
156
    return array(
157
      'columns' => array(
158
        'profile_id' => array(
159
          'type' => 'int',
160
          'unsigned' => TRUE,
161
          'not null' => FALSE,
162
        ),
163
      ),
164
      'indexes' => array(
165
        'profile_id' => array('profile_id'),
166
      ),
167
      'foreign keys' => array(
168
        'profile_id' => array(
169
          'table' => 'commerce_customer_profile',
170
          'columns' => array('profile_id' => 'profile_id'),
171
        ),
172
      ),
173
    );
174
  }
175
}
176

    
177
/**
178
 * Implements hook_uninstall().
179
 */
180
function commerce_customer_uninstall() {
181
  module_load_include('module', 'commerce');
182

    
183
  // Delete any field instance attached to a customer profile type.
184
  commerce_delete_instances('commerce_customer_profile');
185

    
186
  // Delete any customer profile reference fields.
187
  commerce_delete_fields('commerce_customer_profile_reference');
188
}
189

    
190
/**
191
 * Update permission names for customer profile entity management.
192
 */
193
function commerce_customer_update_7000() {
194
  // Load utility functions.
195
  module_load_install('commerce');
196

    
197
  $map = array(
198
    'administer customer profiles' => 'administer commerce_customer_profile entities',
199
    'access customer profiles' => 'view any commerce_customer_profile entity',
200
  );
201
  $entity_info = entity_get_info('commerce_product');
202
  foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
203
    $map['create ' . $bundle_name . ' customer profiles'] = 'create commerce_customer_profile entities of bundle ' . $bundle_name;
204
    $map['edit any ' . $bundle_name . ' customer profile'] = 'edit any commerce_customer_profile entity of bundle ' . $bundle_name;
205
    $map['edit own ' . $bundle_name . ' customer profiles'] = 'edit own commerce_customer_profile entities of bundle ' . $bundle_name;
206
  }
207

    
208
  commerce_update_rename_permissions($map);
209

    
210
  return t('Role and custom View permissions updated for order entity management. Access checks in modules and permissions on default Views must be updated manually.');
211
}
212

    
213
/**
214
 * Add an index to the commerce_customer_profile_revision table on profile_id.
215
 */
216
function commerce_customer_update_7100() {
217
  if (db_index_exists('commerce_customer_profile_revision', 'profile_id')) {
218
    db_drop_index('commerce_customer_profile_revision', 'profile_id');
219
  }
220

    
221
  db_add_index('commerce_customer_profile_revision', 'profile_id', array('profile_id'));
222
}
223

    
224
/**
225
 * Add indexes to the commerce_customer_profile table on uid, type, and both together.
226
 */
227
function commerce_customer_update_7101() {
228
  if (db_index_exists('commerce_customer_profile', 'uid')) {
229
    db_drop_index('commerce_customer_profile', 'uid');
230
  }
231

    
232
  if (db_index_exists('commerce_customer_profile', 'type')) {
233
    db_drop_index('commerce_customer_profile', 'type');
234
  }
235

    
236
  if (db_index_exists('commerce_customer_profile', 'customer_profile_type')) {
237
    db_drop_index('commerce_customer_profile', 'type');
238
  }
239

    
240
  if (db_index_exists('commerce_customer_profile', 'idx_type_uid')) {
241
    db_drop_index('commerce_customer_profile', 'idx_type_uid');
242
  }
243

    
244
  if (db_index_exists('commerce_customer_profile', 'uid_by_type')) {
245
    db_drop_index('commerce_customer_profile', 'uid_by_type');
246
  }
247

    
248
  db_add_index('commerce_customer_profile', 'uid', array('uid'));
249
  db_add_index('commerce_customer_profile', 'customer_profile_type', array('type'));
250
  db_add_index('commerce_customer_profile', 'uid_by_type', array('uid', 'type'));
251

    
252
  return t('Database indexes added to the uid and type columns of the commerce_customer_profile table.');
253
}
254

    
255
/**
256
 * Allow NULL values for revision_id on {commerce_customer} to avoid locking issues.
257
 */
258
function commerce_customer_update_7102() {
259
  db_change_field('commerce_customer_profile', 'revision_id', 'revision_id', array(
260
    'description' => 'The current {commerce_customer_profile_revision}.revision_id version identifier.',
261
    'type' => 'int',
262
    'unsigned' => TRUE,
263
    'not null' => FALSE,
264
  ));
265

    
266
  return t('Schema for the commerce_customer_profile table has been updated.');
267
}