Projet

Général

Profil

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

root / drupal7 / sites / all / modules / panels / panels.install @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * Test requirements for installation and running.
5
 */
6
function panels_requirements($phase) {
7
  $function = "panels_requirements_$phase";
8
  return function_exists($function) ? $function() : array();
9
}
10

    
11
/**
12
 * Check install-time requirements.
13
 */
14
function panels_requirements_install() {
15
  $requirements = array();
16
  $t = get_t();
17
  // Assume that if the user is running an installation profile that both
18
  // Panels and CTools are the same release.
19
  if (!(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install')) {
20
    // apparently the install process doesn't include .module files,
21
    // so we need to force the issue in order for our versioning
22
    // check to work.
23
    if (!defined('PANELS_REQUIRED_CTOOLS_API')) {
24
      include_once drupal_get_path('module', 'panels') . '/panels.module';
25
    }
26

    
27
    // In theory we should check module_exists, but Drupal's gating should
28
    // actually prevent us from getting here otherwise.
29
    if (!defined('CTOOLS_API_VERSION')) {
30
      include_once drupal_get_path('module', 'ctools') . '/ctools.module';
31
    }
32
    if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
33
       $requirements['panels_ctools'] = array(
34
         'title' => $t('CTools API Version'),
35
         'value' => CTOOLS_API_VERSION,
36
         'severity' => REQUIREMENT_ERROR,
37
         'description' => t('The CTools API version is too old for Panels. Panels needs at least %version.', array('%version' => PANELS_REQUIRED_CTOOLS_API))
38
       );
39
    }
40
  }
41
  return $requirements;
42
}
43

    
44
/**
45
 * Implementation of hook_schema().
46
 */
47
function panels_schema() {
48
  // This should always point to our 'current' schema. This makes it relatively easy
49
  // to keep a record of schema as we make changes to it.
50
  return panels_schema_5();
51
}
52

    
53
function panels_schema_5() {
54
  $schema = panels_schema_4();
55

    
56
  $schema['panels_display']['fields']['uuid'] = array(
57
    'type' => 'char',
58
    'length' => '36',
59
  );
60
  $schema['panels_display']['export']['key'] = 'uuid';
61
  $schema['panels_display']['export']['key name'] = 'UUID';
62

    
63
  $schema['panels_pane']['fields']['uuid'] = array(
64
    'type' => 'char',
65
    'length' => '36',
66
  );
67
  $schema['panels_pane']['export']['key'] = 'uuid';
68
  $schema['panels_pane']['export']['key name'] = 'UUID';
69

    
70
  return $schema;
71
}
72

    
73
function panels_schema_4() {
74
  $schema = panels_schema_3();
75

    
76
  $schema['panels_pane']['fields']['locks'] = array(
77
    'type' => 'text',
78
    'size' => 'big',
79
    'serialize' => TRUE,
80
    'object default' => array(),
81
    'initial' => array(),
82
  );
83

    
84
  return $schema;
85
}
86

    
87
/**
88
 * Schema from the D6 version.
89
 */
90
function panels_schema_3() {
91
  // Schema 3 is now locked. If you need to make changes, please create
92
  // schema 4 and add them.
93
  $schema = array();
94

    
95
  $schema['panels_display'] = array(
96
    'export' => array(
97
      'object' => 'panels_display',
98
      'bulk export' => FALSE,
99
      'export callback' => 'panels_export_display',
100
      'can disable' => FALSE,
101
      'identifier' => 'display',
102
    ),
103
    'fields' => array(
104
      'did' => array(
105
        'type' => 'serial',
106
        'not null' => TRUE,
107
        'no export' => TRUE,
108
      ),
109
      'layout' => array(
110
        'type' => 'varchar',
111
        'length' => '255',
112
        'default' => '',
113
      ),
114
      'layout_settings' => array(
115
        'type' => 'text',
116
        'size' => 'big',
117
        'serialize' => TRUE,
118
        'object default' => array(),
119
        'initial' => array(),
120
      ),
121
      'panel_settings' => array(
122
        'type' => 'text',
123
        'size' => 'big',
124
        'serialize' => TRUE,
125
        'object default' => array(),
126
        'initial' => array(),
127
      ),
128
      'cache' => array(
129
        'type' => 'text',
130
        'serialize' => TRUE,
131
        'object default' => array(),
132
        'initial' => array(),
133
      ),
134
      'title' => array(
135
        'type' => 'varchar',
136
        'length' => '255',
137
        'default' => '',
138
      ),
139
      'hide_title' => array(
140
        'type' => 'int',
141
        'size' => 'tiny',
142
        'default' => 0,
143
        'no export' => TRUE,
144
      ),
145
      'title_pane' => array(
146
        'type' => 'int',
147
        'default' => 0,
148
        'no export' => TRUE,
149
      ),
150
    ),
151
    'primary key' => array('did'),
152
  );
153

    
154
  $schema['panels_pane'] = array(
155
    'export' => array(
156
      'can disable' => FALSE,
157
      'identifier' => 'pane',
158
      'bulk export' => FALSE,
159
    ),
160
    'fields' => array(
161
      'pid' => array(
162
        'type' => 'serial',
163
        'not null' => TRUE,
164
      ),
165
      'did' => array(
166
        'type' => 'int',
167
        'not null' => TRUE,
168
        'default' => 0,
169
        'no export' => TRUE,
170
      ),
171
      'panel' => array(
172
        'type' => 'varchar',
173
        'length' => '32',
174
        'default' => '',
175
      ),
176
      'type' => array(
177
        'type' => 'varchar',
178
        'length' => '32',
179
        'default' => '',
180
      ),
181
      'subtype' => array(
182
        'type' => 'varchar',
183
        'length' => '64',
184
        'default' => '',
185
      ),
186
      'shown' => array(
187
        'type' => 'int',
188
        'size' => 'tiny',
189
        'default' => 1,
190
      ),
191
      'access' => array(
192
        'type' => 'text',
193
        'size' => 'big',
194
        'serialize' => TRUE,
195
        'object default' => array(),
196
        'initial' => array(),
197
      ),
198
      'configuration' => array(
199
        'type' => 'text',
200
        'size' => 'big',
201
        'serialize' => TRUE,
202
        'object default' => array(),
203
        'initial' => array(),
204
      ),
205
      'cache' => array(
206
        'type' => 'text',
207
        'size' => 'big',
208
        'serialize' => TRUE,
209
        'object default' => array(),
210
        'initial' => array(),
211
      ),
212
      'style' => array(
213
        'type' => 'text',
214
        'size' => 'big',
215
        'serialize' => TRUE,
216
        'object default' => array(),
217
        'initial' => array(),
218
      ),
219
      'css' => array(
220
        'type' => 'text',
221
        'size' => 'big',
222
        'serialize' => TRUE,
223
        'object default' => array(),
224
        'initial' => array(),
225
      ),
226
      'extras' => array(
227
        'type' => 'text',
228
        'size' => 'big',
229
        'serialize' => TRUE,
230
        'object default' => array(),
231
        'initial' => array(),
232
      ),
233
      'position' => array(
234
        'type' => 'int',
235
        'size' => 'small',
236
        'default' => 0,
237
      ),
238
    ),
239
    'primary key' => array('pid'),
240
    'indexes' => array(
241
      'did_idx' => array('did')
242
    ),
243
  );
244

    
245
  $schema['panels_renderer_pipeline'] = array(
246
    'description' => 'Contains renderer pipelines for Panels. Each pipeline contains one or more renderers and access rules to select which renderer gets used.',
247
    'export' => array(
248
      'identifier' => 'pipeline',
249
      'bulk export' => TRUE,
250
      'primary key' => 'rpid',
251
      'api' => array(
252
        'owner' => 'panels',
253
        'api' => 'pipelines',
254
        'minimum_version' => 1,
255
        'current_version' => 1,
256
      ),
257
    ),
258
    'fields' => array(
259
      'rpid' => array(
260
        'type' => 'serial',
261
        'description' => 'A database primary key to ensure uniqueness.',
262
        'not null' => TRUE,
263
        'no export' => TRUE,
264
      ),
265
      'name' => array(
266
        'type' => 'varchar',
267
        'length' => '255',
268
        'description' => 'Unique ID for this content. Used to identify it programmatically.',
269
      ),
270
      'admin_title' => array(
271
        'type' => 'varchar',
272
        'length' => '255',
273
        'description' => 'Administrative title for this pipeline.',
274
      ),
275
      'admin_description' => array(
276
        'type' => 'text',
277
        'size' => 'big',
278
        'description' => 'Administrative description for this pipeline.',
279
        'object default' => '',
280
      ),
281
      'weight' => array(
282
        'type' => 'int',
283
        'size' => 'small',
284
        'default' => 0,
285
      ),
286
      'settings' => array(
287
        'type' => 'text',
288
        'size' => 'big',
289
        'description' => 'Serialized settings for the actual pipeline. The contents of this field are up to the plugin that uses it.',
290
        'serialize' => TRUE,
291
        'object default' => array(),
292
      ),
293
    ),
294
    'primary key' => array('rpid'),
295
  );
296

    
297
  $schema['panels_layout'] = array(
298
    'description' => 'Contains exportable customized layouts for this site.',
299
    'export' => array(
300
      'identifier' => 'layout',
301
      'bulk export' => TRUE,
302
      'primary key' => 'lid',
303
      'api' => array(
304
        'owner' => 'panels',
305
        'api' => 'layouts',
306
        'minimum_version' => 1,
307
        'current_version' => 1,
308
      ),
309
    ),
310
    'fields' => array(
311
      'lid' => array(
312
        'type' => 'serial',
313
        'description' => 'A database primary key to ensure uniqueness.',
314
        'not null' => TRUE,
315
        'no export' => TRUE,
316
      ),
317
      'name' => array(
318
        'type' => 'varchar',
319
        'length' => '255',
320
        'description' => 'Unique ID for this content. Used to identify it programmatically.',
321
      ),
322
      'admin_title' => array(
323
        'type' => 'varchar',
324
        'length' => '255',
325
        'description' => 'Administrative title for this layout.',
326
      ),
327
      'admin_description' => array(
328
        'type' => 'text',
329
        'size' => 'big',
330
        'description' => 'Administrative description for this layout.',
331
        'object default' => '',
332
      ),
333
      'category' => array(
334
        'type' => 'varchar',
335
        'length' => '255',
336
        'description' => 'Administrative category for this layout.',
337
      ),
338
      'plugin' => array(
339
        'type' => 'varchar',
340
        'length' => '255',
341
        'description' => 'The layout plugin that owns this layout.',
342
      ),
343
      'settings' => array(
344
        'type' => 'text',
345
        'size' => 'big',
346
        'description' => 'Serialized settings for the actual layout. The contents of this field are up to the plugin that uses it.',
347
        'serialize' => TRUE,
348
        'object default' => array(),
349
      ),
350
    ),
351
    'primary key' => array('lid'),
352
  );
353

    
354
  $schema['cache_panels'] = drupal_get_schema_unprocessed('system', 'cache');
355

    
356
  return $schema;
357
}
358

    
359
/**
360
 * Change panels_display.layout to match the size of panels_layout.name.
361
 */
362
function panels_update_7300() {
363
  // Load the schema.
364
  $schema = panels_schema_3();
365
  $table = 'panels_display';
366
  $field = 'layout';
367
  $spec = $schema[$table]['fields'][$field];
368

    
369
  // Re-define the column.
370
  db_change_field($table, $field, $field, $spec);
371

    
372
  return t('Changed the panels_display.layout field to the correct size.');
373
}
374

    
375
/**
376
 * Add lock field to panels_pane table.
377
 */
378
function panels_update_7301() {
379
  // Load the schema.
380

    
381
  // Due to a previous failure, the field may already exist:
382

    
383
  $schema = panels_schema_4();
384
  $table = 'panels_pane';
385
  $field = 'locks';
386

    
387
  if (!db_field_exists($table, $field)) {
388
    $spec = $schema[$table]['fields'][$field];
389

    
390
    // Core does not properly respect 'initial' and 'serialize'.
391
    unset($spec['initial']);
392

    
393
    // Re-define the column.
394
    db_add_field($table, $field, $spec);
395
    return t('Added panels_pane.lock field.');
396
  }
397

    
398
  return t('panels_pane.lock field already existed, update skipped.');
399
}
400

    
401
/**
402
 * Adding universally unique identifiers to panels.
403
 */
404
function panels_update_7302() {
405
  // Load the schema.
406
  $schema = panels_schema_5();
407
  $msg = array();
408

    
409
  // Add the uuid column to the pane table.
410
  $table = 'panels_pane';
411
  $field = 'uuid';
412
  // Due to a previous failure, the column may already exist:
413
  if (!db_field_exists($table, $field)) {
414
    $spec = $schema[$table]['fields'][$field];
415
    db_add_field($table, $field, $spec);
416
    $msg[] = t('Added panels_pane.uuid column.');
417
  }
418

    
419
  // Add the uuid column to the display table.
420
  $table = 'panels_display';
421
  $field = 'uuid';
422
  // Due to a previous failure, the column may already exist:
423
  if (!db_field_exists($table, $field)) {
424
    $spec = $schema[$table]['fields'][$field];
425
    db_add_field($table, $field, $spec);
426
    $msg[] = t('Added panels_display.uuid column.');
427
  }
428

    
429
  if (empty($msg)) {
430
    $msg[] = t('UUID column already present in the panels_display & panels_pane tables.');
431
  }
432

    
433
  // Update all DB-based panes & displays to ensure that they all contain a UUID.
434
  $display_dids = db_select('panels_display')
435
    ->fields('panels_display', array('did'))
436
    ->condition(db_or()
437
      ->condition('uuid', '')
438
      ->isNull('uuid')
439
    )
440
    ->execute()
441
    ->fetchCol();
442

    
443
  // Check the panes as well, for paranoia.
444
  $pane_dids = db_select('panels_pane')
445
    ->distinct()
446
    ->fields('panels_pane', array('did'))
447
    ->condition(db_or()
448
      ->condition('uuid', '')
449
      ->isNull('uuid')
450
    )
451
    ->execute()
452
    ->fetchCol();
453

    
454
  $dids = array_unique(array_merge($display_dids, $pane_dids));
455

    
456
  if ($displays = panels_load_displays($dids)) {
457
    foreach ($displays as $display) {
458
      // A display save also triggers pane saves.
459
      panels_save_display($display);
460
    }
461
    $msg[] = t('Generated UUIDs for database-based panel displays and panes.');
462
  }
463
  else {
464
    $msg[] = t('No database-based panel displays or panes for which to generate UUIDs.');
465
  }
466

    
467
  return implode("\n", $msg);
468
}
469

    
470
/**
471
 * Add a custom cache table for Panels.
472
 */
473
function panels_update_7303() {
474
  $table_name = 'cache_panels';
475
  if (!db_table_exists($table_name)) {
476
    $schema = drupal_get_schema_unprocessed('system', 'cache');
477
    db_create_table($table_name, $schema);
478
  }
479
}