Projet

Général

Profil

Paste
Télécharger (7,99 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / ctools.install @ 7e72b748

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains install and update functions for ctools.
6
 */
7

    
8
/**
9
 * Use requirements to ensure that the CTools CSS cache directory can be
10
 * created and that the PHP version requirement is met.
11
 */
12
function ctools_requirements($phase) {
13
  $requirements = array();
14
  if ($phase == 'runtime') {
15
    $requirements['ctools_css_cache'] = array(
16
      'title' => t('CTools CSS Cache'),
17
      'severity' => REQUIREMENT_OK,
18
      'value' => t('Exists'),
19
    );
20

    
21
    $path = 'public://ctools/css';
22
    if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
23
      $requirements['ctools_css_cache']['description'] = t('The CTools CSS cache directory, %path could not be created due to a misconfigured files directory. Please ensure that the files directory is correctly configured and that the webserver has permission to create directories.', array('%path' => file_uri_target($path)));
24
      $requirements['ctools_css_cache']['severity'] = REQUIREMENT_ERROR;
25
      $requirements['ctools_css_cache']['value'] = t('Unable to create');
26
    }
27

    
28
    if (!function_exists('error_get_last')) {
29
      $requirements['ctools_php_52']['title'] = t('CTools PHP requirements');
30
      $requirements['ctools_php_52']['description'] = t('CTools requires certain features only available in PHP 5.2.0 or higher.');
31
      $requirements['ctools_php_52']['severity'] = REQUIREMENT_WARNING;
32
      $requirements['ctools_php_52']['value'] = t('PHP !version', array('!version' => phpversion()));
33
    }
34
  }
35

    
36
  return $requirements;
37
}
38

    
39
/**
40
 * Implements hook_schema().
41
 */
42
function ctools_schema() {
43
  return ctools_schema_4();
44
}
45

    
46
/**
47
 * Version 4 of the CTools schema.
48
 */
49
function ctools_schema_4() {
50
  $schema = ctools_schema_3();
51

    
52
  // Update the 'name' field to be 255 bytes long:
53
  $schema['ctools_object_cache']['fields']['name']['length'] = 255;
54

    
55
  return $schema;
56
}
57

    
58
/**
59
 * Version 3 of the CTools schema.
60
 */
61
function ctools_schema_3() {
62
  $schema = ctools_schema_2();
63

    
64
  // Update the 'obj' field to be 128 bytes long:
65
  $schema['ctools_object_cache']['fields']['obj']['length'] = 128;
66

    
67
  return $schema;
68
}
69

    
70
/**
71
 * Version 2 of the CTools schema.
72
 */
73
function ctools_schema_2() {
74
  $schema = ctools_schema_1();
75

    
76
  // Update the 'name' field to be 128 bytes long:
77
  $schema['ctools_object_cache']['fields']['name']['length'] = 128;
78

    
79
  // Update the 'data' field to be type 'blob'.
80
  $schema['ctools_object_cache']['fields']['data'] = array(
81
    'type' => 'blob',
82
    'size' => 'big',
83
    'description' => 'Serialized data being stored.',
84
    'serialize' => TRUE,
85
  );
86

    
87
  // DO NOT MODIFY THIS TABLE -- this definition is used to create the table.
88
  // Changes to this table must be made in schema_3 or higher.
89
  $schema['ctools_css_cache'] = array(
90
    'description' => 'A special cache used to store CSS that must be non-volatile.',
91
    'fields' => array(
92
      'cid' => array(
93
        'type' => 'varchar',
94
        'length' => '128',
95
        'description' => 'The CSS ID this cache object belongs to.',
96
        'not null' => TRUE,
97
      ),
98
      'filename' => array(
99
        'type' => 'varchar',
100
        'length' => '255',
101
        'description' => 'The filename this CSS is stored in.',
102
      ),
103
      'css' => array(
104
        'type' => 'text',
105
        'size' => 'big',
106
        'description' => 'CSS being stored.',
107
        'serialize' => TRUE,
108
      ),
109
      'filter' => array(
110
        'type' => 'int',
111
        'size' => 'tiny',
112
        'description' => 'Whether or not this CSS needs to be filtered.',
113
      ),
114
    ),
115
    'primary key' => array('cid'),
116
  );
117

    
118
  return $schema;
119
}
120

    
121
/**
122
 * CTools' initial schema; separated for the purposes of updates.
123
 *
124
 * DO NOT MAKE CHANGES HERE. This schema version is locked.
125
 */
126
function ctools_schema_1() {
127
  $schema['ctools_object_cache'] = array(
128
    'description' => t('A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.'),
129
    'fields' => array(
130
      'sid' => array(
131
        'type' => 'varchar',
132
        'length' => '64',
133
        'not null' => TRUE,
134
        'description' => 'The session ID this cache object belongs to.',
135
      ),
136
      'name' => array(
137
        'type' => 'varchar',
138
        'length' => '32',
139
        'not null' => TRUE,
140
        'description' => 'The name of the object this cache is attached to.',
141
      ),
142
      'obj' => array(
143
        'type' => 'varchar',
144
        'length' => '32',
145
        'not null' => TRUE,
146
        'description' => 'The type of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.',
147
      ),
148
      'updated' => array(
149
        'type' => 'int',
150
        'unsigned' => TRUE,
151
        'not null' => TRUE,
152
        'default' => 0,
153
        'description' => 'The time this cache was created or updated.',
154
      ),
155
      'data' => array(
156
        'type' => 'text',
157
        'size' => 'big',
158
        'description' => 'Serialized data being stored.',
159
        'serialize' => TRUE,
160
      ),
161
    ),
162
    'primary key' => array('sid', 'obj', 'name'),
163
    'indexes' => array('updated' => array('updated')),
164
  );
165
  return $schema;
166
}
167

    
168
/**
169
 * Implements hook_install().
170
 */
171
function ctools_install() {
172
  // Activate our custom cache handler for the CSS cache.
173
  variable_set('cache_class_cache_ctools_css', 'CToolsCssCache');
174
}
175

    
176
/**
177
 * Implements hook_uninstall().
178
 */
179
function ctools_uninstall() {
180
  variable_del('cache_class_cache_ctools_css');
181
}
182

    
183
/**
184
 * Enlarge the ctools_object_cache.name column to prevent truncation and weird
185
 * errors.
186
 */
187
function ctools_update_6001() {
188
  // Perform updates like this to reduce code duplication.
189
  $schema = ctools_schema_2();
190

    
191
  db_change_field('ctools_object_cache', 'name', 'name', $schema['ctools_object_cache']['fields']['name']);
192
}
193

    
194
/**
195
 * Add the new css cache table.
196
 */
197
function ctools_update_6002() {
198
  // Schema 2 is locked and should not be changed.
199
  $schema = ctools_schema_2();
200

    
201
  db_create_table('ctools_css_cache', $schema['ctools_css_cache']);
202
}
203

    
204
/**
205
 * Take over for the panels_views module if it was on.
206
 */
207
function ctools_update_6003() {
208
  $result = db_query('SELECT status FROM {system} WHERE name = :name', array(':name' => 'panels_views'))->fetchField();
209
  if ($result) {
210
    db_delete('system')->condition('name', 'panels_views')->execute();
211
    module_enable(array('views_content'), TRUE);
212
  }
213
}
214

    
215
/**
216
 * Add primary key to the ctools_object_cache table.
217
 */
218
function ctools_update_6004() {
219
  db_add_primary_key('ctools_object_cache', array('sid', 'obj', 'name'));
220
  db_drop_index('ctools_object_cache', 'sid_obj_name');
221
}
222

    
223
/**
224
 * Removed update.
225
 */
226
function ctools_update_6005() {
227
  return array();
228
}
229

    
230
/**
231
 * The ctools_custom_content table was originally here, but is now moved to
232
 * its own module.
233
 */
234
function ctools_update_6007() {
235
  $ret = array();
236
  if (db_table_exists('ctools_custom_content')) {
237
    // Enable the module to make everything as seamless as possible.
238
    module_enable(array('ctools_custom_content'), TRUE);
239
  }
240

    
241
  return $ret;
242
}
243

    
244
/**
245
 * The ctools_object_cache needs to be defined as a blob.
246
 */
247
function ctools_update_6008() {
248
  db_delete('ctools_object_cache')
249
    ->execute();
250

    
251
  db_change_field('ctools_object_cache', 'data', 'data', array(
252
    'type' => 'blob',
253
    'size' => 'big',
254
    'description' => 'Serialized data being stored.',
255
    'serialize' => TRUE,
256
  )
257
  );
258
}
259

    
260
/**
261
 * Enable the custom CSS cache handler.
262
 */
263
function ctools_update_7000() {
264
  variable_set('cache_class_cache_ctools_css', 'CToolsCssCache');
265
}
266

    
267
/**
268
 * Increase the length of the ctools_object_cache.obj column.
269
 */
270
function ctools_update_7001() {
271
  db_change_field('ctools_object_cache', 'obj', 'obj', array(
272
    'type' => 'varchar',
273
    'length' => '128',
274
    'not null' => TRUE,
275
    'description' => 'The type of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.',
276
  ));
277
}
278

    
279
/**
280
 * Increase the length of the ctools_object_cache.name column to 255.
281
 */
282
function ctools_update_7002() {
283
  db_change_field('ctools_object_cache', 'name', 'name', array(
284
    'type' => 'varchar',
285
    'length' => '255',
286
    'not null' => TRUE,
287
  ));
288
}