Projet

Général

Profil

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

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

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

    
53
function panels_schema_9() {
54
  $schema = panels_schema_8();
55
  $schema['panels_allowed_types'] = array(
56
    'fields' => array(
57
      'module' => array(
58
        'description' => 'The name of the module requiring allowed type settings.',
59
        'type' => 'varchar',
60
        'length' => 255,
61
        'not null' => TRUE,
62
        'default' => '',
63
      ),
64
      'type' => array(
65
        'description' => 'Ctools content type to allow.',
66
        'type' => 'varchar',
67
        'length' => 255,
68
        'not null' => TRUE,
69
        'default' => '',
70
      ),
71
      'allowed' => array(
72
        'description' => 'A boolean for if the type is allowed or not.',
73
        'type' => 'int',
74
        'size' => 'tiny',
75
        'default' => 1,
76
      ),
77
    ),
78
    'indexes' => array(
79
      'type_idx' => array('type'),
80
    ),
81
  );
82

    
83
  return $schema;
84
 }
85

    
86
function panels_schema_8() {
87
  $schema = panels_schema_7();
88

    
89
  // Add the storage type and id columns.
90
  $schema['panels_display']['fields']['storage_type'] = array(
91
    'type' => 'varchar',
92
    'length' => 255,
93
    'default' => '',
94
  );
95
  $schema['panels_display']['fields']['storage_id'] = array(
96
    'type' => 'varchar',
97
    'length' => 255,
98
    'default' => '',
99
  );
100

    
101
  return $schema;
102
}
103

    
104
function panels_schema_7() {
105
  $schema = panels_schema_6();
106

    
107
  // Update field lengths to 255 chars.
108
  $schema['panels_pane']['fields']['subtype']['length'] = '255';
109
  $schema['panels_pane']['fields']['panel']['length'] = '255';
110
  $schema['panels_pane']['fields']['type']['length'] = '255';
111

    
112
  return $schema;
113
}
114

    
115
function panels_schema_6() {
116
  $schema = panels_schema_5();
117

    
118
  $schema['cache_panels'] = drupal_get_schema_unprocessed('system', 'cache');
119

    
120
  return $schema;
121
}
122

    
123
function panels_schema_5() {
124
  $schema = panels_schema_4();
125

    
126
  $schema['panels_display']['fields']['uuid'] = array(
127
    'type' => 'char',
128
    'length' => '36',
129
  );
130
  $schema['panels_display']['export']['key'] = 'uuid';
131
  $schema['panels_display']['export']['key name'] = 'UUID';
132

    
133
  $schema['panels_pane']['fields']['uuid'] = array(
134
    'type' => 'char',
135
    'length' => '36',
136
  );
137
  $schema['panels_pane']['export']['key'] = 'uuid';
138
  $schema['panels_pane']['export']['key name'] = 'UUID';
139

    
140
  return $schema;
141
}
142

    
143
function panels_schema_4() {
144
  $schema = panels_schema_3();
145

    
146
  $schema['panels_pane']['fields']['locks'] = array(
147
    'type' => 'text',
148
    'size' => 'big',
149
    'serialize' => TRUE,
150
    'object default' => array(),
151
    'initial' => array(),
152
  );
153

    
154
  return $schema;
155
}
156

    
157
/**
158
 * Schema from the D6 version.
159
 */
160
function panels_schema_3() {
161
  // Schema 3 is now locked. If you need to make changes, please create
162
  // schema 4 and add them.
163
  $schema = array();
164

    
165
  $schema['panels_display'] = array(
166
    'export' => array(
167
      'object' => 'panels_display',
168
      'bulk export' => FALSE,
169
      'export callback' => 'panels_export_display',
170
      'can disable' => FALSE,
171
      'identifier' => 'display',
172
    ),
173
    'fields' => array(
174
      'did' => array(
175
        'type' => 'serial',
176
        'not null' => TRUE,
177
        'no export' => TRUE,
178
      ),
179
      'layout' => array(
180
        'type' => 'varchar',
181
        'length' => '255',
182
        'default' => '',
183
      ),
184
      'layout_settings' => array(
185
        'type' => 'text',
186
        'size' => 'big',
187
        'serialize' => TRUE,
188
        'object default' => array(),
189
        'initial' => array(),
190
      ),
191
      'panel_settings' => array(
192
        'type' => 'text',
193
        'size' => 'big',
194
        'serialize' => TRUE,
195
        'object default' => array(),
196
        'initial' => array(),
197
      ),
198
      'cache' => array(
199
        'type' => 'text',
200
        'serialize' => TRUE,
201
        'object default' => array(),
202
        'initial' => array(),
203
      ),
204
      'title' => array(
205
        'type' => 'varchar',
206
        'length' => '255',
207
        'default' => '',
208
      ),
209
      'hide_title' => array(
210
        'type' => 'int',
211
        'size' => 'tiny',
212
        'default' => 0,
213
        'no export' => TRUE,
214
      ),
215
      'title_pane' => array(
216
        'type' => 'int',
217
        'default' => 0,
218
        'no export' => TRUE,
219
      ),
220
    ),
221
    'primary key' => array('did'),
222
  );
223

    
224
  $schema['panels_pane'] = array(
225
    'export' => array(
226
      'can disable' => FALSE,
227
      'identifier' => 'pane',
228
      'bulk export' => FALSE,
229
    ),
230
    'fields' => array(
231
      'pid' => array(
232
        'type' => 'serial',
233
        'not null' => TRUE,
234
      ),
235
      'did' => array(
236
        'type' => 'int',
237
        'not null' => TRUE,
238
        'default' => 0,
239
        'no export' => TRUE,
240
      ),
241
      'panel' => array(
242
        'type' => 'varchar',
243
        'length' => '32',
244
        'default' => '',
245
      ),
246
      'type' => array(
247
        'type' => 'varchar',
248
        'length' => '32',
249
        'default' => '',
250
      ),
251
      'subtype' => array(
252
        'type' => 'varchar',
253
        'length' => '64',
254
        'default' => '',
255
      ),
256
      'shown' => array(
257
        'type' => 'int',
258
        'size' => 'tiny',
259
        'default' => 1,
260
      ),
261
      'access' => array(
262
        'type' => 'text',
263
        'size' => 'big',
264
        'serialize' => TRUE,
265
        'object default' => array(),
266
        'initial' => array(),
267
      ),
268
      'configuration' => array(
269
        'type' => 'text',
270
        'size' => 'big',
271
        'serialize' => TRUE,
272
        'object default' => array(),
273
        'initial' => array(),
274
      ),
275
      'cache' => array(
276
        'type' => 'text',
277
        'size' => 'big',
278
        'serialize' => TRUE,
279
        'object default' => array(),
280
        'initial' => array(),
281
      ),
282
      'style' => array(
283
        'type' => 'text',
284
        'size' => 'big',
285
        'serialize' => TRUE,
286
        'object default' => array(),
287
        'initial' => array(),
288
      ),
289
      'css' => array(
290
        'type' => 'text',
291
        'size' => 'big',
292
        'serialize' => TRUE,
293
        'object default' => array(),
294
        'initial' => array(),
295
      ),
296
      'extras' => array(
297
        'type' => 'text',
298
        'size' => 'big',
299
        'serialize' => TRUE,
300
        'object default' => array(),
301
        'initial' => array(),
302
      ),
303
      'position' => array(
304
        'type' => 'int',
305
        'size' => 'small',
306
        'default' => 0,
307
      ),
308
    ),
309
    'primary key' => array('pid'),
310
    'indexes' => array(
311
      'did_idx' => array('did')
312
    ),
313
  );
314

    
315
  $schema['panels_renderer_pipeline'] = array(
316
    'description' => 'Contains renderer pipelines for Panels. Each pipeline contains one or more renderers and access rules to select which renderer gets used.',
317
    'export' => array(
318
      'identifier' => 'pipeline',
319
      'bulk export' => TRUE,
320
      'primary key' => 'rpid',
321
      'api' => array(
322
        'owner' => 'panels',
323
        'api' => 'pipelines',
324
        'minimum_version' => 1,
325
        'current_version' => 1,
326
      ),
327
    ),
328
    'fields' => array(
329
      'rpid' => array(
330
        'type' => 'serial',
331
        'description' => 'A database primary key to ensure uniqueness.',
332
        'not null' => TRUE,
333
        'no export' => TRUE,
334
      ),
335
      'name' => array(
336
        'type' => 'varchar',
337
        'length' => '255',
338
        'description' => 'Unique ID for this content. Used to identify it programmatically.',
339
      ),
340
      'admin_title' => array(
341
        'type' => 'varchar',
342
        'length' => '255',
343
        'description' => 'Administrative title for this pipeline.',
344
      ),
345
      'admin_description' => array(
346
        'type' => 'text',
347
        'size' => 'big',
348
        'description' => 'Administrative description for this pipeline.',
349
        'object default' => '',
350
      ),
351
      'weight' => array(
352
        'type' => 'int',
353
        'size' => 'small',
354
        'default' => 0,
355
      ),
356
      'settings' => array(
357
        'type' => 'text',
358
        'size' => 'big',
359
        'description' => 'Serialized settings for the actual pipeline. The contents of this field are up to the plugin that uses it.',
360
        'serialize' => TRUE,
361
        'object default' => array(),
362
      ),
363
    ),
364
    'primary key' => array('rpid'),
365
  );
366

    
367
  $schema['panels_layout'] = array(
368
    'description' => 'Contains exportable customized layouts for this site.',
369
    'export' => array(
370
      'identifier' => 'layout',
371
      'bulk export' => TRUE,
372
      'primary key' => 'lid',
373
      'api' => array(
374
        'owner' => 'panels',
375
        'api' => 'layouts',
376
        'minimum_version' => 1,
377
        'current_version' => 1,
378
      ),
379
    ),
380
    'fields' => array(
381
      'lid' => array(
382
        'type' => 'serial',
383
        'description' => 'A database primary key to ensure uniqueness.',
384
        'not null' => TRUE,
385
        'no export' => TRUE,
386
      ),
387
      'name' => array(
388
        'type' => 'varchar',
389
        'length' => '255',
390
        'description' => 'Unique ID for this content. Used to identify it programmatically.',
391
      ),
392
      'admin_title' => array(
393
        'type' => 'varchar',
394
        'length' => '255',
395
        'description' => 'Administrative title for this layout.',
396
      ),
397
      'admin_description' => array(
398
        'type' => 'text',
399
        'size' => 'big',
400
        'description' => 'Administrative description for this layout.',
401
        'object default' => '',
402
      ),
403
      'category' => array(
404
        'type' => 'varchar',
405
        'length' => '255',
406
        'description' => 'Administrative category for this layout.',
407
      ),
408
      'plugin' => array(
409
        'type' => 'varchar',
410
        'length' => '255',
411
        'description' => 'The layout plugin that owns this layout.',
412
      ),
413
      'settings' => array(
414
        'type' => 'text',
415
        'size' => 'big',
416
        'description' => 'Serialized settings for the actual layout. The contents of this field are up to the plugin that uses it.',
417
        'serialize' => TRUE,
418
        'object default' => array(),
419
      ),
420
    ),
421
    'primary key' => array('lid'),
422
  );
423

    
424
  return $schema;
425
}
426

    
427
/**
428
 * Change panels_display.layout to match the size of panels_layout.name.
429
 */
430
function panels_update_7300() {
431
  // Load the schema.
432
  $schema = panels_schema_3();
433
  $table = 'panels_display';
434
  $field = 'layout';
435
  $spec = $schema[$table]['fields'][$field];
436

    
437
  // Re-define the column.
438
  db_change_field($table, $field, $field, $spec);
439

    
440
  return t('Changed the panels_display.layout field to the correct size.');
441
}
442

    
443
/**
444
 * Add lock field to panels_pane table.
445
 */
446
function panels_update_7301() {
447
  // Load the schema.
448

    
449
  // Due to a previous failure, the field may already exist:
450

    
451
  $schema = panels_schema_4();
452
  $table = 'panels_pane';
453
  $field = 'locks';
454

    
455
  if (!db_field_exists($table, $field)) {
456
    $spec = $schema[$table]['fields'][$field];
457

    
458
    // Core does not properly respect 'initial' and 'serialize'.
459
    unset($spec['initial']);
460

    
461
    // Re-define the column.
462
    db_add_field($table, $field, $spec);
463
    return t('Added panels_pane.lock field.');
464
  }
465

    
466
  return t('panels_pane.lock field already existed, update skipped.');
467
}
468

    
469
/**
470
 * Adding universally unique identifiers to panels.
471
 *
472
 * Note: This update hook is not written well. It calls apis which uses the
473
 * most updated drupal database, causing missing columns or tables errors. To
474
 * mitigate the issue, we've added updates from 7303 and 7305. Future updates
475
 * should go below the 7305 update.
476
 *
477
 * See https://www.drupal.org/node/2787123 for more info.
478
 */
479
function panels_update_7302() {
480
  if (!module_load_include('inc', 'ctools', 'includes/uuid')) {
481
    throw new DrupalUpdateException(t('Ctools UUID support not detected. You must update to a more recent version of the ctools module.'));
482
  }
483
  // Run the 7303 update first to avoid caching issues.
484
  // This *probably* should be placed right above update 7305, however it was
485
  // tested here and re-testing this update is difficult, so it stays here.
486
  panels_update_7303();
487

    
488
  // Load the schema.
489
  $schema = panels_schema_5();
490
  $msg = array();
491

    
492
  // Add the uuid column to the pane table.
493
  $table = 'panels_pane';
494
  $field = 'uuid';
495
  // Due to a previous failure, the column may already exist:
496
  if (!db_field_exists($table, $field)) {
497
    $spec = $schema[$table]['fields'][$field];
498
    db_add_field($table, $field, $spec);
499
    $msg[] = t('Added panels_pane.uuid column.');
500
  }
501

    
502
  // Add the uuid column to the display table.
503
  $table = 'panels_display';
504
  $field = 'uuid';
505
  // Due to a previous failure, the column may already exist:
506
  if (!db_field_exists($table, $field)) {
507
    $spec = $schema[$table]['fields'][$field];
508
    db_add_field($table, $field, $spec);
509
    $msg[] = t('Added panels_display.uuid column.');
510
  }
511

    
512
  if (empty($msg)) {
513
    $msg[] = t('UUID column already present in the panels_display & panels_pane tables.');
514
  }
515

    
516
  // Update all DB-based panes & displays to ensure that they all contain a UUID.
517
  $display_dids = db_select('panels_display')
518
    ->fields('panels_display', array('did'))
519
    ->condition(db_or()
520
      ->condition('uuid', '')
521
      ->isNull('uuid')
522
    )
523
    ->execute()
524
    ->fetchCol();
525

    
526
  // Check the panes as well, for paranoia.
527
  $pane_dids = db_select('panels_pane')
528
    ->distinct()
529
    ->fields('panels_pane', array('did'))
530
    ->condition(db_or()
531
      ->condition('uuid', '')
532
      ->isNull('uuid')
533
    )
534
    ->execute()
535
    ->fetchCol();
536

    
537
  $dids = array_unique(array_merge($display_dids, $pane_dids));
538

    
539
  // Before using panels_save_display(), we have to make sure any new fields
540
  // are added from future updates.
541
  panels_update_7305();
542

    
543
  // If the Panels module is disabled we don't have access to
544
  // panels_load_displays().
545
  if (!function_exists('panels_load_displays')) {
546
    module_load_include('module', 'panels');
547
  }
548
  if ($displays = panels_load_displays($dids)) {
549
    foreach ($displays as $display) {
550
      // A display save also triggers pane saves.
551
      panels_save_display($display);
552
    }
553
    $msg[] = t('Generated UUIDs for database-based panel displays and panes.');
554
  }
555
  else {
556
    $msg[] = t('No database-based panel displays or panes for which to generate UUIDs.');
557
  }
558

    
559
  return implode("\n", $msg);
560
}
561

    
562
/**
563
 * Add a custom cache table for Panels.
564
 */
565
function panels_update_7303() {
566
  $schema = panels_schema_6();
567

    
568
  $table_name = 'cache_panels';
569
  if (!db_table_exists($table_name)) {
570
    db_create_table($table_name, $schema[$table_name]);
571
  }
572
}
573

    
574
/**
575
 * Update "panels_pane" table field lengths to 255 chars.
576
 */
577
function panels_update_7304() {
578
  $schema = panels_schema_7();
579

    
580
  $update_fields = array(
581
    'panels_pane' => array('subtype', 'panel', 'type'),
582
  );
583

    
584
  foreach ($update_fields as $table => $fields) {
585
    foreach ($fields as $field_name) {
586
      db_change_field($table, $field_name, $field_name, $schema[$table]['fields'][$field_name]);
587
    }
588
  }
589
}
590

    
591
/**
592
 * Add the "storage_type" and "storage_id" columns to "panels_display".
593
 */
594
function panels_update_7305() {
595
  $schema = panels_schema_8();
596

    
597
  $new_fields = array(
598
    'panels_display' => array('storage_type', 'storage_id'),
599
  );
600

    
601
  foreach ($new_fields as $table => $fields) {
602
    foreach ($fields as $field_name) {
603
      // Due to a previous failure, the column may already exist:
604
      if (!db_field_exists($table, $field_name)) {
605
        db_add_field($table, $field_name, $schema[$table]['fields'][$field_name]);
606
      }
607
    }
608
  }
609
}
610

    
611
/**
612
 * Set the storage type and id on existing page manager panels displays.
613
 */
614
function panels_update_7306() {
615
  if (!db_table_exists('page_manager_handlers')) {
616
    return t('Skipping update - page_manager is not installed.');
617
  }
618

    
619
  // Get all page_manager_handlers that have a panels context.
620
  $result = db_query("SELECT pm.name, pm.conf FROM {page_manager_handlers} pm WHERE pm.handler = 'panel_context'");
621
  $page_manager_panels = array();
622
  foreach ($result as $row) {
623
    $conf = unserialize($row->conf);
624
    if (isset($conf['did'])) {
625
      $page_manager_panels[$conf['did']] = $row->name;
626
    }
627
  }
628

    
629
  if (!empty($page_manager_panels)) {
630
    // Check panels displays that only have empty storage types
631
    $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)));
632
    foreach ($result as $row) {
633
      db_update('panels_display')
634
        ->fields(array(
635
          'storage_type' => 'page_manager',
636
          'storage_id' => $page_manager_panels[$row->did],
637
        ))
638
        ->condition('did', $row->did)
639
        ->execute();
640
    }
641
  }
642
}
643

    
644
/**
645
 * Add a custom table for allowed types.
646
 */
647
function panels_update_7307() {
648
  $schema = panels_schema_9();
649

    
650
  $table_name = 'panels_allowed_types';
651
  if (!db_table_exists($table_name)) {
652
    db_create_table($table_name, $schema[$table_name]);
653
  }
654

    
655
  // Read existing allowed settings and store them in a new table.
656
  $variables = db_select('variable', 'v')
657
    ->fields('v', array('name'))
658
    ->condition('name', '%' . db_like('_allowed_types'), 'LIKE')
659
    ->execute()
660
    ->fetchCol();
661
  foreach ($variables as $name) {
662
    $module = str_replace('_allowed_types', '', $name);
663
    $variable = variable_get($name);
664
    foreach ($variable as $type => $allowed) {
665
      $allowed = empty($allowed) ? 0 : 1;
666
      db_merge('panels_allowed_types')
667
        ->key(array('module' => $module, 'type' => $type))
668
        ->fields(array(
669
          'module' => $module,
670
          'type' => $type,
671
          'allowed' => $allowed,
672
        ))
673
        ->execute();
674
    }
675
    variable_del($name);
676
  }
677
}
678

    
679
/**
680
 * Rename style permissions.
681
 */
682
function panels_update_7308() {
683
  $permissions = array(
684
    'administer panels display styles',
685
    'administer panels pane styles',
686
    'administer panels region styles',
687
  );
688
  foreach (array_keys(user_roles(TRUE, 'administer panels styles')) as $rid) {
689
    user_role_grant_permissions($rid, $permissions);
690
  }
691
}