Project

General

Profile

Paste
Download (8.38 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / ctools / ctools.install @ 6e3ce7c2

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
    $t = get_t();
16
    $requirements['ctools_css_cache'] = array(
17
      'title' => $t('CTools CSS Cache'),
18
      'severity' => REQUIREMENT_OK,
19
      'value' => $t('Exists'),
20
    );
21

    
22
    $path = 'public://ctools/css';
23
    if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
24
      $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)));
25
      $requirements['ctools_css_cache']['severity'] = REQUIREMENT_ERROR;
26
      $requirements['ctools_css_cache']['value'] = $t('Unable to create');
27
    }
28

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

    
37
  return $requirements;
38
}
39

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

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

    
53
  // Removed due to alternative database configuration issues.
54
  // @see https://www.drupal.org/project/ctools/issues/2941920
55

    
56
  return $schema;
57
}
58

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

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

    
68
  return $schema;
69
}
70

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

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

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

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

    
119
  return $schema;
120
}
121

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

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

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

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

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

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

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

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

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

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

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

    
242
  return $ret;
243
}
244

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

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

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

    
268
/**
269
 * Increase the length of the ctools_object_cache.obj column.
270
 */
271
function ctools_update_7001() {
272
  db_change_field('ctools_object_cache', 'obj', 'obj', array(
273
    'type' => 'varchar',
274
    'length' => '128',
275
    'not null' => TRUE,
276
    '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.',
277
  ));
278
}
279

    
280
/**
281
 * Increase the length of the ctools_object_cache.name column to 255.
282
 */
283
function ctools_update_7002() {
284
  // Removed due to alternative database configuration issues.
285
  // @see https://www.drupal.org/project/ctools/issues/2941920
286
}
287

    
288
/**
289
 * Revert the length of the ctools_object_cache.name column back to 128.
290
 */
291
function ctools_update_7003() {
292
  db_delete('ctools_object_cache')->execute();
293
  db_change_field('ctools_object_cache', 'name', 'name', array(
294
    'type' => 'varchar',
295
    'length' => '128',
296
    'not null' => TRUE,
297
    'description' => 'The name of the object this cache is attached to.',
298
  ));
299
}