Projet

Général

Profil

Paste
Télécharger (16 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / panels.install @ 136a805a

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_8();
51
}
52

    
53
function panels_schema_8() {
54
  $schema = panels_schema_7();
55

    
56
  // Add the storage type and id columns.
57
  $schema['panels_display']['fields']['storage_type'] = array(
58
    'type' => 'varchar',
59
    'length' => 255,
60
    'default' => '',
61
  );
62
  $schema['panels_display']['fields']['storage_id'] = array(
63
    'type' => 'varchar',
64
    'length' => 255,
65
    'default' => '',
66
  );
67

    
68
  return $schema;
69
}
70

    
71
function panels_schema_7() {
72
  $schema = panels_schema_6();
73

    
74
  // Update field lengths to 255 chars.
75
  $schema['panels_pane']['fields']['subtype']['length'] = '255';
76
  $schema['panels_pane']['fields']['panel']['length'] = '255';
77
  $schema['panels_pane']['fields']['type']['length'] = '255';
78

    
79
  return $schema;
80
}
81

    
82
function panels_schema_6() {
83
  $schema = panels_schema_5();
84

    
85
  $schema['cache_panels'] = drupal_get_schema_unprocessed('system', 'cache');
86

    
87
  return $schema;
88
}
89

    
90
function panels_schema_5() {
91
  $schema = panels_schema_4();
92

    
93
  $schema['panels_display']['fields']['uuid'] = array(
94
    'type' => 'char',
95
    'length' => '36',
96
  );
97
  $schema['panels_display']['export']['key'] = 'uuid';
98
  $schema['panels_display']['export']['key name'] = 'UUID';
99

    
100
  $schema['panels_pane']['fields']['uuid'] = array(
101
    'type' => 'char',
102
    'length' => '36',
103
  );
104
  $schema['panels_pane']['export']['key'] = 'uuid';
105
  $schema['panels_pane']['export']['key name'] = 'UUID';
106

    
107
  return $schema;
108
}
109

    
110
function panels_schema_4() {
111
  $schema = panels_schema_3();
112

    
113
  $schema['panels_pane']['fields']['locks'] = array(
114
    'type' => 'text',
115
    'size' => 'big',
116
    'serialize' => TRUE,
117
    'object default' => array(),
118
    'initial' => array(),
119
  );
120

    
121
  return $schema;
122
}
123

    
124
/**
125
 * Schema from the D6 version.
126
 */
127
function panels_schema_3() {
128
  // Schema 3 is now locked. If you need to make changes, please create
129
  // schema 4 and add them.
130
  $schema = array();
131

    
132
  $schema['panels_display'] = array(
133
    'export' => array(
134
      'object' => 'panels_display',
135
      'bulk export' => FALSE,
136
      'export callback' => 'panels_export_display',
137
      'can disable' => FALSE,
138
      'identifier' => 'display',
139
    ),
140
    'fields' => array(
141
      'did' => array(
142
        'type' => 'serial',
143
        'not null' => TRUE,
144
        'no export' => TRUE,
145
      ),
146
      'layout' => array(
147
        'type' => 'varchar',
148
        'length' => '255',
149
        'default' => '',
150
      ),
151
      'layout_settings' => array(
152
        'type' => 'text',
153
        'size' => 'big',
154
        'serialize' => TRUE,
155
        'object default' => array(),
156
        'initial' => array(),
157
      ),
158
      'panel_settings' => array(
159
        'type' => 'text',
160
        'size' => 'big',
161
        'serialize' => TRUE,
162
        'object default' => array(),
163
        'initial' => array(),
164
      ),
165
      'cache' => array(
166
        'type' => 'text',
167
        'serialize' => TRUE,
168
        'object default' => array(),
169
        'initial' => array(),
170
      ),
171
      'title' => array(
172
        'type' => 'varchar',
173
        'length' => '255',
174
        'default' => '',
175
      ),
176
      'hide_title' => array(
177
        'type' => 'int',
178
        'size' => 'tiny',
179
        'default' => 0,
180
        'no export' => TRUE,
181
      ),
182
      'title_pane' => array(
183
        'type' => 'int',
184
        'default' => 0,
185
        'no export' => TRUE,
186
      ),
187
    ),
188
    'primary key' => array('did'),
189
  );
190

    
191
  $schema['panels_pane'] = array(
192
    'export' => array(
193
      'can disable' => FALSE,
194
      'identifier' => 'pane',
195
      'bulk export' => FALSE,
196
    ),
197
    'fields' => array(
198
      'pid' => array(
199
        'type' => 'serial',
200
        'not null' => TRUE,
201
      ),
202
      'did' => array(
203
        'type' => 'int',
204
        'not null' => TRUE,
205
        'default' => 0,
206
        'no export' => TRUE,
207
      ),
208
      'panel' => array(
209
        'type' => 'varchar',
210
        'length' => '32',
211
        'default' => '',
212
      ),
213
      'type' => array(
214
        'type' => 'varchar',
215
        'length' => '32',
216
        'default' => '',
217
      ),
218
      'subtype' => array(
219
        'type' => 'varchar',
220
        'length' => '64',
221
        'default' => '',
222
      ),
223
      'shown' => array(
224
        'type' => 'int',
225
        'size' => 'tiny',
226
        'default' => 1,
227
      ),
228
      'access' => array(
229
        'type' => 'text',
230
        'size' => 'big',
231
        'serialize' => TRUE,
232
        'object default' => array(),
233
        'initial' => array(),
234
      ),
235
      'configuration' => array(
236
        'type' => 'text',
237
        'size' => 'big',
238
        'serialize' => TRUE,
239
        'object default' => array(),
240
        'initial' => array(),
241
      ),
242
      'cache' => array(
243
        'type' => 'text',
244
        'size' => 'big',
245
        'serialize' => TRUE,
246
        'object default' => array(),
247
        'initial' => array(),
248
      ),
249
      'style' => array(
250
        'type' => 'text',
251
        'size' => 'big',
252
        'serialize' => TRUE,
253
        'object default' => array(),
254
        'initial' => array(),
255
      ),
256
      'css' => array(
257
        'type' => 'text',
258
        'size' => 'big',
259
        'serialize' => TRUE,
260
        'object default' => array(),
261
        'initial' => array(),
262
      ),
263
      'extras' => array(
264
        'type' => 'text',
265
        'size' => 'big',
266
        'serialize' => TRUE,
267
        'object default' => array(),
268
        'initial' => array(),
269
      ),
270
      'position' => array(
271
        'type' => 'int',
272
        'size' => 'small',
273
        'default' => 0,
274
      ),
275
    ),
276
    'primary key' => array('pid'),
277
    'indexes' => array(
278
      'did_idx' => array('did')
279
    ),
280
  );
281

    
282
  $schema['panels_renderer_pipeline'] = array(
283
    'description' => 'Contains renderer pipelines for Panels. Each pipeline contains one or more renderers and access rules to select which renderer gets used.',
284
    'export' => array(
285
      'identifier' => 'pipeline',
286
      'bulk export' => TRUE,
287
      'primary key' => 'rpid',
288
      'api' => array(
289
        'owner' => 'panels',
290
        'api' => 'pipelines',
291
        'minimum_version' => 1,
292
        'current_version' => 1,
293
      ),
294
    ),
295
    'fields' => array(
296
      'rpid' => array(
297
        'type' => 'serial',
298
        'description' => 'A database primary key to ensure uniqueness.',
299
        'not null' => TRUE,
300
        'no export' => TRUE,
301
      ),
302
      'name' => array(
303
        'type' => 'varchar',
304
        'length' => '255',
305
        'description' => 'Unique ID for this content. Used to identify it programmatically.',
306
      ),
307
      'admin_title' => array(
308
        'type' => 'varchar',
309
        'length' => '255',
310
        'description' => 'Administrative title for this pipeline.',
311
      ),
312
      'admin_description' => array(
313
        'type' => 'text',
314
        'size' => 'big',
315
        'description' => 'Administrative description for this pipeline.',
316
        'object default' => '',
317
      ),
318
      'weight' => array(
319
        'type' => 'int',
320
        'size' => 'small',
321
        'default' => 0,
322
      ),
323
      'settings' => array(
324
        'type' => 'text',
325
        'size' => 'big',
326
        'description' => 'Serialized settings for the actual pipeline. The contents of this field are up to the plugin that uses it.',
327
        'serialize' => TRUE,
328
        'object default' => array(),
329
      ),
330
    ),
331
    'primary key' => array('rpid'),
332
  );
333

    
334
  $schema['panels_layout'] = array(
335
    'description' => 'Contains exportable customized layouts for this site.',
336
    'export' => array(
337
      'identifier' => 'layout',
338
      'bulk export' => TRUE,
339
      'primary key' => 'lid',
340
      'api' => array(
341
        'owner' => 'panels',
342
        'api' => 'layouts',
343
        'minimum_version' => 1,
344
        'current_version' => 1,
345
      ),
346
    ),
347
    'fields' => array(
348
      'lid' => array(
349
        'type' => 'serial',
350
        'description' => 'A database primary key to ensure uniqueness.',
351
        'not null' => TRUE,
352
        'no export' => TRUE,
353
      ),
354
      'name' => array(
355
        'type' => 'varchar',
356
        'length' => '255',
357
        'description' => 'Unique ID for this content. Used to identify it programmatically.',
358
      ),
359
      'admin_title' => array(
360
        'type' => 'varchar',
361
        'length' => '255',
362
        'description' => 'Administrative title for this layout.',
363
      ),
364
      'admin_description' => array(
365
        'type' => 'text',
366
        'size' => 'big',
367
        'description' => 'Administrative description for this layout.',
368
        'object default' => '',
369
      ),
370
      'category' => array(
371
        'type' => 'varchar',
372
        'length' => '255',
373
        'description' => 'Administrative category for this layout.',
374
      ),
375
      'plugin' => array(
376
        'type' => 'varchar',
377
        'length' => '255',
378
        'description' => 'The layout plugin that owns this layout.',
379
      ),
380
      'settings' => array(
381
        'type' => 'text',
382
        'size' => 'big',
383
        'description' => 'Serialized settings for the actual layout. The contents of this field are up to the plugin that uses it.',
384
        'serialize' => TRUE,
385
        'object default' => array(),
386
      ),
387
    ),
388
    'primary key' => array('lid'),
389
  );
390

    
391
  return $schema;
392
}
393

    
394
/**
395
 * Change panels_display.layout to match the size of panels_layout.name.
396
 */
397
function panels_update_7300() {
398
  // Load the schema.
399
  $schema = panels_schema_3();
400
  $table = 'panels_display';
401
  $field = 'layout';
402
  $spec = $schema[$table]['fields'][$field];
403

    
404
  // Re-define the column.
405
  db_change_field($table, $field, $field, $spec);
406

    
407
  return t('Changed the panels_display.layout field to the correct size.');
408
}
409

    
410
/**
411
 * Add lock field to panels_pane table.
412
 */
413
function panels_update_7301() {
414
  // Load the schema.
415

    
416
  // Due to a previous failure, the field may already exist:
417

    
418
  $schema = panels_schema_4();
419
  $table = 'panels_pane';
420
  $field = 'locks';
421

    
422
  if (!db_field_exists($table, $field)) {
423
    $spec = $schema[$table]['fields'][$field];
424

    
425
    // Core does not properly respect 'initial' and 'serialize'.
426
    unset($spec['initial']);
427

    
428
    // Re-define the column.
429
    db_add_field($table, $field, $spec);
430
    return t('Added panels_pane.lock field.');
431
  }
432

    
433
  return t('panels_pane.lock field already existed, update skipped.');
434
}
435

    
436
/**
437
 * Adding universally unique identifiers to panels.
438
 */
439
function panels_update_7302() {
440
  if (!module_load_include('inc', 'ctools', 'includes/uuid')) {
441
    throw new DrupalUpdateException(t('Ctools UUID support not detected. You must update to a more recent version of the ctools module.'));
442
  }
443
  // Load the schema.
444
  $schema = panels_schema_5();
445
  $msg = array();
446

    
447
  // Add the uuid column to the pane table.
448
  $table = 'panels_pane';
449
  $field = 'uuid';
450
  // Due to a previous failure, the column may already exist:
451
  if (!db_field_exists($table, $field)) {
452
    $spec = $schema[$table]['fields'][$field];
453
    db_add_field($table, $field, $spec);
454
    $msg[] = t('Added panels_pane.uuid column.');
455
  }
456

    
457
  // Add the uuid column to the display table.
458
  $table = 'panels_display';
459
  $field = 'uuid';
460
  // Due to a previous failure, the column may already exist:
461
  if (!db_field_exists($table, $field)) {
462
    $spec = $schema[$table]['fields'][$field];
463
    db_add_field($table, $field, $spec);
464
    $msg[] = t('Added panels_display.uuid column.');
465
  }
466

    
467
  if (empty($msg)) {
468
    $msg[] = t('UUID column already present in the panels_display & panels_pane tables.');
469
  }
470

    
471
  // Update all DB-based panes & displays to ensure that they all contain a UUID.
472
  $display_dids = db_select('panels_display')
473
    ->fields('panels_display', array('did'))
474
    ->condition(db_or()
475
      ->condition('uuid', '')
476
      ->isNull('uuid')
477
    )
478
    ->execute()
479
    ->fetchCol();
480

    
481
  // Check the panes as well, for paranoia.
482
  $pane_dids = db_select('panels_pane')
483
    ->distinct()
484
    ->fields('panels_pane', array('did'))
485
    ->condition(db_or()
486
      ->condition('uuid', '')
487
      ->isNull('uuid')
488
    )
489
    ->execute()
490
    ->fetchCol();
491

    
492
  $dids = array_unique(array_merge($display_dids, $pane_dids));
493

    
494
  // If the Panels module is disabled we don't have access to
495
  // panels_load_displays().
496
  if (!function_exists('panels_load_displays')) {
497
    module_load_include('module', 'panels');
498
  }
499
  if ($displays = panels_load_displays($dids)) {
500
    foreach ($displays as $display) {
501
      // A display save also triggers pane saves.
502
      panels_save_display($display);
503
    }
504
    $msg[] = t('Generated UUIDs for database-based panel displays and panes.');
505
  }
506
  else {
507
    $msg[] = t('No database-based panel displays or panes for which to generate UUIDs.');
508
  }
509

    
510
  return implode("\n", $msg);
511
}
512

    
513
/**
514
 * Add a custom cache table for Panels.
515
 */
516
function panels_update_7303() {
517
  $schema = panels_schema_6();
518

    
519
  $table_name = 'cache_panels';
520
  if (!db_table_exists($table_name)) {
521
    db_create_table($table_name, $schema[$table_name]);
522
  }
523
}
524

    
525
/**
526
 * Update "panels_pane" table field lengths to 255 chars.
527
 */
528
function panels_update_7304() {
529
  $schema = panels_schema_7();
530

    
531
  $update_fields = array(
532
    'panels_pane' => array('subtype', 'panel', 'type'),
533
  );
534

    
535
  foreach($update_fields as $table => $fields) {
536
    foreach($fields as $field_name) {
537
      db_change_field($table, $field_name, $field_name, $schema[$table]['fields'][$field_name]);
538
    }
539
  }
540
}
541

    
542
/**
543
 * Add the "storage_type" and "storage_id" columns to "panels_display".
544
 */
545
function panels_update_7305() {
546
  $schema = panels_schema_8();
547

    
548
  $new_fields = array(
549
    'panels_display' => array('storage_type', 'storage_id'),
550
  );
551

    
552
  foreach ($new_fields as $table => $fields) {
553
    foreach ($fields as $field_name) {
554
      db_add_field($table, $field_name, $schema[$table]['fields'][$field_name]);
555
    }
556
  }
557
}
558

    
559
/**
560
 * Set the storage type and id on existing page manager panels displays.
561
 */
562
function panels_update_7306() {
563
  if (!db_table_exists('page_manager_handlers')) {
564
    return t('Skipping update - page_manager is not installed.');
565
  }
566

    
567
  // Get all page_manager_handlers that have a panels context.
568
  $result = db_query("SELECT pm.name, pm.conf FROM {page_manager_handlers} pm WHERE pm.handler = 'panel_context'");
569
  $page_manager_panels = array();
570
  foreach ($result as $row) {
571
    $conf = unserialize($row->conf);
572
    if (isset($conf['did'])) {
573
      $page_manager_panels[$conf['did']] = $row->name;
574
    }
575
  }
576

    
577
  if (!empty($page_manager_panels)) {
578
    // Check panels displays that only have empty storage types
579
    $result = db_query("SELECT pd.did FROM {panels_display} pd WHERE pd.did IN (:dids) AND storage_type = ''", array(':dids' => array_keys($page_manager_panels)));
580
    foreach ($result as $row) {
581
      db_update('panels_display')
582
        ->fields(array(
583
          'storage_type' => 'page_manager',
584
          'storage_id' => $page_manager_panels[$row->did],
585
        ))
586
        ->condition('did', $row->did)
587
        ->execute();
588
    }
589
  }
590
}