Projet

Général

Profil

Paste
Télécharger (13,4 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / panels.install @ a45e4bc1

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
 * Implements of hook_schema().
46
 */
47
function panels_schema() {
48
  // This should always point to our 'current' schema. This makes it relatively
49
  // easy to keep a record of schema as we make changes to it.
50
  return panels_schema_6();
51
}
52

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

    
56
  $schema['cache_panels'] = drupal_get_schema_unprocessed('system', 'cache');
57

    
58
  return $schema;
59
}
60

    
61
function panels_schema_5() {
62
  $schema = panels_schema_4();
63

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

    
71
  $schema['panels_pane']['fields']['uuid'] = array(
72
    'type' => 'char',
73
    'length' => '36',
74
  );
75
  $schema['panels_pane']['export']['key'] = 'uuid';
76
  $schema['panels_pane']['export']['key name'] = 'UUID';
77

    
78
  return $schema;
79
}
80

    
81
function panels_schema_4() {
82
  $schema = panels_schema_3();
83

    
84
  $schema['panels_pane']['fields']['locks'] = array(
85
    'type' => 'text',
86
    'size' => 'big',
87
    'serialize' => TRUE,
88
    'object default' => array(),
89
    'initial' => array(),
90
  );
91

    
92
  return $schema;
93
}
94

    
95
/**
96
 * Schema from the D6 version.
97
 */
98
function panels_schema_3() {
99
  // Schema 3 is now locked. If you need to make changes, please create
100
  // schema 4 and add them.
101
  $schema = array();
102

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

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

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

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

    
362
  return $schema;
363
}
364

    
365
/**
366
 * Change panels_display.layout to match the size of panels_layout.name.
367
 */
368
function panels_update_7300() {
369
  // Load the schema.
370
  $schema = panels_schema_3();
371
  $table = 'panels_display';
372
  $field = 'layout';
373
  $spec = $schema[$table]['fields'][$field];
374

    
375
  // Re-define the column.
376
  db_change_field($table, $field, $field, $spec);
377

    
378
  return t('Changed the panels_display.layout field to the correct size.');
379
}
380

    
381
/**
382
 * Add lock field to panels_pane table.
383
 */
384
function panels_update_7301() {
385
  // Load the schema.
386

    
387
  // Due to a previous failure, the field may already exist:
388

    
389
  $schema = panels_schema_4();
390
  $table = 'panels_pane';
391
  $field = 'locks';
392

    
393
  if (!db_field_exists($table, $field)) {
394
    $spec = $schema[$table]['fields'][$field];
395

    
396
    // Core does not properly respect 'initial' and 'serialize'.
397
    unset($spec['initial']);
398

    
399
    // Re-define the column.
400
    db_add_field($table, $field, $spec);
401
    return t('Added panels_pane.lock field.');
402
  }
403

    
404
  return t('panels_pane.lock field already existed, update skipped.');
405
}
406

    
407
/**
408
 * Adding universally unique identifiers to panels.
409
 */
410
function panels_update_7302() {
411
  if (!module_load_include('inc', 'ctools', 'includes/uuid')) {
412
    throw new DrupalUpdateException(t('Ctools UUID support not detected. You must update to a more recent version of the ctools module.'));
413
  }
414
  // Load the schema.
415
  $schema = panels_schema_5();
416
  $msg = array();
417

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

    
428
  // Add the uuid column to the display table.
429
  $table = 'panels_display';
430
  $field = 'uuid';
431
  // Due to a previous failure, the column may already exist:
432
  if (!db_field_exists($table, $field)) {
433
    $spec = $schema[$table]['fields'][$field];
434
    db_add_field($table, $field, $spec);
435
    $msg[] = t('Added panels_display.uuid column.');
436
  }
437

    
438
  if (empty($msg)) {
439
    $msg[] = t('UUID column already present in the panels_display & panels_pane tables.');
440
  }
441

    
442
  // Update all DB-based panes & displays to ensure that they all contain a UUID.
443
  $display_dids = db_select('panels_display')
444
    ->fields('panels_display', array('did'))
445
    ->condition(db_or()
446
      ->condition('uuid', '')
447
      ->isNull('uuid')
448
    )
449
    ->execute()
450
    ->fetchCol();
451

    
452
  // Check the panes as well, for paranoia.
453
  $pane_dids = db_select('panels_pane')
454
    ->distinct()
455
    ->fields('panels_pane', array('did'))
456
    ->condition(db_or()
457
      ->condition('uuid', '')
458
      ->isNull('uuid')
459
    )
460
    ->execute()
461
    ->fetchCol();
462

    
463
  $dids = array_unique(array_merge($display_dids, $pane_dids));
464

    
465
  // If the Panels module is disabled we don't have access to
466
  // panels_load_displays().
467
  if (!function_exists('panels_load_displays')) {
468
    module_load_include('module', 'panels');
469
  }
470
  if ($displays = panels_load_displays($dids)) {
471
    foreach ($displays as $display) {
472
      // A display save also triggers pane saves.
473
      panels_save_display($display);
474
    }
475
    $msg[] = t('Generated UUIDs for database-based panel displays and panes.');
476
  }
477
  else {
478
    $msg[] = t('No database-based panel displays or panes for which to generate UUIDs.');
479
  }
480

    
481
  return implode("\n", $msg);
482
}
483

    
484
/**
485
 * Add a custom cache table for Panels.
486
 */
487
function panels_update_7303() {
488
  $schema = panels_schema_6();
489

    
490
  $table_name = 'cache_panels';
491
  if (!db_table_exists($table_name)) {
492
    db_create_table($table_name, $schema[$table_name]);
493
  }
494
}