-
Notifications
You must be signed in to change notification settings - Fork 2
/
panelizer.install
1347 lines (1185 loc) · 43.7 KB
/
panelizer.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* Install, update and uninstall functions for the panelizer module.
*/
/**
* Implements hook_schema().
*/
function panelizer_schema() {
$schema = array();
// Fields that are shared between the two tables.
$common_fields = array(
'view_mode' => array(
'type' => 'varchar',
'length' => '128',
'description' => 'Contains the view mode this panelizer is for.',
'not null' => TRUE,
),
'did' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'The display ID of the panel.',
'no export' => TRUE,
),
'name' => array(
'type' => 'varchar',
'length' => '255',
'description' => 'The name of the default being used if there is one.',
),
'css_id' => array(
'type' => 'varchar',
'length' => '255',
'description' => 'The CSS ID this panel should use.',
'default' => '',
),
'css_class' => array(
'type' => 'varchar',
'length' => '255',
'description' => 'The CSS class this panel should use.',
'default' => '',
),
'css' => array(
'type' => 'text',
'size' => 'big',
'description' => 'Any CSS the author provided for the panel.',
'object default' => '',
),
'no_blocks' => array(
'type' => 'int',
'size' => 'tiny',
'description' => 'Whether or not the node disable sidebar blocks.',
'default' => 0,
),
'title_element' => array(
'type' => 'varchar',
'length' => '255',
'description' => 'The HTML element the title should use.',
'default' => 'H2',
),
'link_to_entity' => array(
'type' => 'int',
'size' => 'tiny',
'description' => 'Whether or not the title should link to the entity.',
'default' => 1,
),
'extra' => array(
'type' => 'text',
'size' => 'big',
'description' => 'Contains extra data that can be added by modules.',
'serialize' => TRUE,
'object default' => array(),
),
'pipeline' => array(
'type' => 'varchar',
'length' => '255',
'description' => 'The render pipeline this panel uses.',
'default' => 'standard',
),
'contexts' => array(
'type' => 'text',
'size' => 'big',
'description' => 'The contexts configured by the node author.',
'serialize' => TRUE,
'object default' => array(),
),
'relationships' => array(
'type' => 'text',
'size' => 'big',
'description' => 'The relationship contexts configured by the node author.',
'serialize' => TRUE,
'object default' => array(),
),
);
$schema['panelizer_entity'] = array(
'export' => array(
'bulk export' => FALSE,
'can disable' => FALSE,
'identifier' => 'panelizer_node',
),
'description' => 'Node panelizer references.',
'fields' => array(
'entity_type' => array(
'description' => 'The type of the entity this panel is attached to.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'entity_id' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The entity ID this panel is attached to.',
),
'revision_id' => array(
'description' => 'The revision id of the entity.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
) + $common_fields,
'primary key' => array('entity_type', 'entity_id', 'revision_id', 'view_mode'),
'indexes' => array(
'revision_id' => array('revision_id'),
),
);
$schema['panelizer_defaults'] = array(
'description' => 'Node type panelizer references.',
'export' => array(
'primary key' => 'pnid',
'key' => 'name',
'key name' => 'Name',
'admin_title' => 'title',
'identifier' => 'panelizer',
'default hook' => 'panelizer_defaults',
'api' => array(
'owner' => 'panelizer',
'api' => 'panelizer',
'minimum_version' => 1,
'current_version' => 1,
),
// 'create callback' => 'panelizer_export_create_callback',
'save callback' => 'panelizer_export_save_callback',
'export callback' => 'panelizer_export_export_callback',
'delete callback' => 'panelizer_export_delete_callback',
'subrecords callback' => 'panelizer_export_delete_callback_subrecords',
),
'fields' => array(
'pnid' => array(
'type' => 'serial',
'description' => 'The database primary key.',
'no export' => TRUE,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => '255',
'description' => 'The human readable title of this default.',
),
'panelizer_type' => array(
'type' => 'varchar',
'length' => '32',
'description' => 'The panelizer entity type, such as node or user.',
),
'panelizer_key' => array(
'type' => 'varchar',
'length' => '128',
'description' => 'The panelizer entity bundle.',
),
'access' => array(
'type' => 'text',
'size' => 'big',
'description' => 'Contains the access control for editing this default.',
'serialize' => TRUE,
'object default' => array(),
),
) + $common_fields,
'primary key' => array('pnid'),
'indexes' => array(
'name' => array('name'),
'type_key' => array('panelizer_type', 'panelizer_key'),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function panelizer_install() {
// Set the module weight so it can execute after Panels.
db_update('system')
->fields(array(
'weight' => 21,
))
->condition('name', 'panelizer')
->execute();
}
/**
* Implements hook_uninstall().
*/
function panelizer_uninstall() {
foreach (entity_get_info() as $entity_type => $entity_info) {
if (isset($entity_info['bundles'])) {
foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
// View mode variables.
if (!empty($entity_info['view modes'])) {
foreach ($entity_info['view modes'] as $view_mode => $view_info) {
variable_del('panelizer_' . $entity_type . ':' . $bundle_name . ':' . $view_mode . '_selection');
}
}
variable_del('panelizer_' . $entity_type . ':' . $bundle_name . ':default_selection');
variable_del('panelizer_' . $entity_type . ':' . $bundle_name . ':page_manager_selection');
// Other variables.
variable_del('panelizer_defaults_' . $entity_type . '_' . $bundle_name);
variable_del('panelizer_' . $entity_type . ':' . $bundle_name . '_allowed_layouts');
variable_del('panelizer_' . $entity_type . ':' . $bundle_name . '_allowed_layouts_default');
variable_del('panelizer_' . $entity_type . ':' . $bundle_name . '_allowed_types');
variable_del('panelizer_' . $entity_type . ':' . $bundle_name . '_default');
}
}
}
}
/**
* Implements hook_requirements().
*/
function panelizer_requirements($phase) {
$return = array();
if ($phase === 'runtime') {
// Check for fields displaying on view modes through core config.
$view_modes_to_report = array();
foreach (entity_get_info() as $entity_type => $entity_info) {
if (isset($entity_info['view modes'])) {
$view_modes = array_keys($entity_info['view modes']);
// Add default to the list of view modes because that might be panelized
// too.
$view_modes[] = 'default';
if (!empty($entity_info['bundles'])) {
$bundles = $entity_info['bundles'];
}
else {
$bundles = array($entity_type => $entity_type);
}
foreach ($bundles as $bundle => $bundle_info) {
foreach ($view_modes as $view_mode) {
if (panelizer_view_mode_extra_field_displays($entity_type, $bundle, $view_mode)) {
$view_modes_to_report[] = array(
'entity_type' => $entity_type,
'bundle' => $bundle,
'view_mode' => $view_mode,
);
// @todo Should the display be updated to hide the fields?
// panelizer_hide_fields_on_panelized_view_mode($entity_type, $bundle, $view_mode);
}
}
}
}
}
if (!empty($view_modes_to_report)) {
$count = count($view_modes_to_report);
$return['double_display'] = array(
'title' => t('Panelizer'),
'value' => t('@number view mode / bundle / entity combination(s) use Panelizer but still have field displays configured.', array('@number' => $count)),
'description' => t('Panelizer replaces the normal entity display. Any view mode that use Panelizer should have all fields hidden through the normal display settings in order to avoid the overhead of generating the output twice.'),
'severity' => REQUIREMENT_WARNING,
);
$description_links = array();
foreach ($view_modes_to_report as $view_mode_array) {
extract($view_mode_array);
$handler = panelizer_entity_plugin_get_handler($entity_type);
$path = $handler->admin_bundle_display_path($bundle, $view_mode);
$description_links[] = array(
'href' => $path,
'title' => implode(':', $view_mode_array),
);
}
$theme_variables = array(
'links' => $description_links,
'heading' => array(
'text' => 'Entity view modes that should have all fields hidden:',
'level' => 'h6',
),
);
$return['double_display']['description'] .= theme('links', $theme_variables);
}
}
return $return;
}
/**
* Check whether a view mode uses core display of fields and panelizer.
*
* @return bool
* Whether or not a bundle/view_mode is panelized and has fields displaying
* through core settings.
*/
function panelizer_view_mode_extra_field_displays($entity_type, $bundle, $view_mode) {
$handler = panelizer_entity_plugin_get_handler($entity_type);
if (panelizer_is_panelized($handler, $bundle, $view_mode)) {
$bundle = field_extract_bundle($entity_type, $bundle);
$instances = field_info_instances($entity_type, $bundle);
// @todo, handle extra fields.
// field_info_extra_fields($entity_type, $bundle, 'display');
// Look through all the fields and look for fields that aren't hidden.
// As soon as one is found, end this function. Finding any non-hidden
// fields is the point of this function.
foreach ($instances as $instance) {
if (!empty($instance['display'][$view_mode]['type']) && $instance['display'][$view_mode]['type'] !== 'hidden') {
return TRUE;
}
}
}
return FALSE;
}
/**
* Hide all fields on a view mode.
*
* @todo, connect this function to a form and/or ajax callback.
*/
function panelizer_hide_fields_on_panelized_view_mode($entity_type, $bundle, $view_mode) {
$bundle = field_extract_bundle($entity_type, $bundle);
$instances = field_info_instances($entity_type, $bundle);
foreach ($instances as $instance) {
if (!empty($instance['display'][$view_mode]['type'])) {
$instance['display'][$view_mode]['type'] = 'hidden';
field_update_instance($instance);
}
}
}
/**
* Implements hook_update_dependencies().
*/
function panelizer_update_dependencies() {
// Update 7115 requires UUID support in CTools and Panels.
$dependencies['panelizer'][7115] = array(
'panels' => 7302,
);
// These updates requires Panels storage support, which was added in
// panels_update_7305.
$dependencies['panelizer'][7302] = array(
'panels' => 7305,
);
$dependencies['panelizer'][7303] = array(
'panels' => 7305,
);
return $dependencies;
}
/**
* Update the panelizer variable to be more feature module friendly.
*/
function panelizer_update_7100() {
$panelizer_defaults = variable_get('panelizer_defaults', array());
if (!empty($panelizer_defaults)) {
foreach ($panelizer_defaults as $entity => $bundles) {
foreach ($bundles as $bundle => $values) {
variable_set('panelizer_defaults_' . $entity . '_' . $bundle, $values);
}
}
}
variable_del('panelizer_defaults');
return t('Updated panelizer variables.');
}
/**
* Update the panelizer node table to be the panelizer entity table.
*/
function panelizer_update_7101() {
// Rename the table.
db_rename_table('panelizer_node', 'panelizer_entity');
// Remove the primary key.
db_drop_primary_key('panelizer_entity');
// Add the entity type.
$spec = array(
'description' => 'The type of the entity this panel is attached to.',
'type' => 'varchar',
'length' => 255,
);
db_add_field('panelizer_entity', 'entity_type', $spec);
// Rename nid to entity_id.
$spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The entity ID this panel is attached to.',
);
db_change_field('panelizer_entity', 'nid', 'entity_id', $spec);
// Update the entity_type field to 'node' since all pre-existing
// panelizer objects are nodes.
db_update('panelizer_entity')
->fields(array('entity_type' => 'node'))
->execute();
// Add the new index
db_add_primary_key('panelizer_entity', array('entity_type', 'entity_id'));
}
/**
* Add revision support.
*/
function panelizer_update_7102() {
// Remove the primary key.
db_drop_primary_key('panelizer_entity');
// Add the revision ID field.
$spec = array(
'description' => 'The revision id of the entity.',
'type' => 'int',
'unsigned' => TRUE,
);
db_add_field('panelizer_entity', 'revision_id', $spec);
db_query("UPDATE {panelizer_entity} pe LEFT JOIN {node} n ON pe.entity_id = n.nid SET pe.revision_id = n.vid");
// Add the new index.
db_add_primary_key('panelizer_entity', array('entity_type', 'entity_id', 'revision_id'));
return t('Added revision support.');
}
/**
* Set primary keys to NOT NULL.
*/
function panelizer_update_7103() {
$spec = array(
'description' => 'The type of the entity this panel is attached to.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
);
db_change_field('panelizer_entity', 'entity_type', 'entity_type', $spec);
$spec = array(
'description' => 'The revision id of the entity.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
);
db_change_field('panelizer_entity', 'revision_id', 'revision_id', $spec);
$spec = array(
'type' => 'serial',
'description' => 'The database primary key.',
'no export' => TRUE,
'not null' => TRUE,
);
db_change_field('panelizer_defaults', 'pnid', 'pnid', $spec);
}
/**
* Add the {panelizer_defaults}.access field.
*/
function panelizer_update_7104() {
$spec = array(
'type' => 'text',
'size' => 'big',
'description' => 'Contains the access control for editing this default.',
'serialize' => TRUE,
'object default' => array(),
);
db_add_field('panelizer_defaults', 'access', $spec);
}
/**
* Add the view mode field.
*/
function panelizer_update_7105() {
$spec = array(
'type' => 'varchar',
'length' => '128',
'description' => 'Contains the view mode this panelizer is for.',
'not null' => TRUE,
);
db_add_field('panelizer_defaults', 'view_mode', $spec);
db_add_field('panelizer_entity', 'view_mode', $spec);
db_update('panelizer_defaults')
->fields(array(
'view_mode' => 'page_manager',
))
->execute();
db_update('panelizer_entity')
->fields(array(
'view_mode' => 'page_manager',
))
->execute();
}
/**
* Add the view_mode to the primary key for the {panelizer_entity} table.
*/
function panelizer_update_7106() {
db_drop_primary_key('panelizer_entity');
if (db_index_exists('panelizer_entity', 'PRIMARY')) {
throw new DrupalUpdateException(t('Could not drop the panelizer_entity primary key in order to recreate it.'));
}
// Add the new index.
db_add_primary_key('panelizer_entity', array(
'entity_type',
'entity_id',
'revision_id',
'view_mode',
));
if (db_index_exists('panelizer_entity', 'PRIMARY')) {
return t('The Panelizer database scheme has been updated.');
}
else {
throw new DrupalUpdateException(t('There was a problem recreating the panelizer_entity primary key.'));
}
}
/**
* Add the css class and element title fields.
*/
function panelizer_update_7107() {
$spec = array(
'type' => 'varchar',
'length' => '255',
'description' => 'The CSS class this panel should use.',
'default' => '',
);
db_add_field('panelizer_defaults', 'css_class', $spec);
db_add_field('panelizer_entity', 'css_class', $spec);
$spec = array(
'type' => 'varchar',
'length' => '255',
'description' => 'The HTML element the title should use.',
'default' => 'H2',
);
db_add_field('panelizer_defaults', 'title_element', $spec);
db_add_field('panelizer_entity', 'title_element', $spec);
}
/**
* Add the link_to_entity field
*/
function panelizer_update_7108() {
$spec = array(
'type' => 'int',
'size' => 'tiny',
'description' => 'Whether or not the title should link to the entity.',
'default' => 1,
);
db_add_field('panelizer_defaults', 'link_to_entity', $spec);
db_add_field('panelizer_entity', 'link_to_entity', $spec);
}
/**
* Add the extra field so that modules can extend panelizer more easily.
*/
function panelizer_update_7109() {
$spec = array(
'type' => 'text',
'size' => 'big',
'description' => 'Contains extra data that can be added by modules.',
'serialize' => TRUE,
'object default' => array(),
);
db_add_field('panelizer_defaults', 'extra', $spec);
db_add_field('panelizer_entity', 'extra', $spec);
}
/**
* Changing the size of the entity_type field of panelizer_entity.
*/
function panelizer_update_7110() {
db_drop_primary_key('panelizer_entity');
$spec = array(
'description' => 'The type of the entity this panel is attached to.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
);
$keys = array(
'primary key' => array('entity_type', 'entity_id', 'revision_id', 'view_mode'),
);
db_change_field('panelizer_entity', 'entity_type', 'entity_type', $spec, $keys);
}
/**
* This update script was removed, nothing to see here.
*/
function panelizer_update_7111() {
// Nothing.
}
/**
* Fix Panelizer settings.
*/
function panelizer_update_7112() {
foreach (entity_get_info() as $entity_type => $entity_info) {
if (!empty($entity_info) && !empty($entity_info['bundles'])) {
foreach ($entity_info['bundles'] as $bundle => &$bundle_info) {
$var_name = 'panelizer_defaults_' . $entity_type . '_' . $bundle;
$settings = variable_get($var_name);
if (!empty($settings) && !empty($settings['view modes'])) {
foreach ($settings['view modes'] as $view_mode => &$config) {
// If the bundle itself or this view mode are disabled, make sure
// all settings are disabled.
if (empty($settings['status']) || empty($config['status'])) {
foreach ($config as $key => $val) {
$config[$key] = 0;
}
}
}
// Update the settings.
variable_set($var_name, $settings);
}
}
}
}
}
/**
* Make {panelizer_entity}.view_mode NOT NULL.
*/
function panelizer_update_7113() {
db_drop_primary_key('panelizer_entity');
$spec = array(
'description' => 'Contains the view mode this panelizer is for.',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
);
$keys = array('primary key' =>
array('entity_type', 'entity_id', 'revision_id', 'view_mode'),
);
db_change_field('panelizer_entity', 'view_mode', 'view_mode', $spec, $keys);
}
/**
* Clear the menu cache to fix the display actions page arguments.
*/
function panelizer_update_7114() {
variable_set('menu_rebuild_needed', TRUE);
}
/**
* Ensure that each Panelizer display is only used once, so that each
* revision has a separate record.
*/
function panelizer_update_7115(&$sandbox) {
// This loops through all of the records in {panelizer_entity}, looks for any
// displays that are used more than once and clones any additional copies
// that are needed. The goal is to have each display only used once.
// Process records by groups of 1 (arbitrary value). Doing this one at a time
// because some sites can have a LOT of revisions.
$limit = 1;
// When ran through Drush it's Ok to process a larger number of objects at a
// time.
if (drupal_is_cli()) {
$limit = 10;
}
// The update hasn't been ran before.
if (!isset($sandbox['progress'])) {
// The count of records visited so far.
$sandbox['progress'] = 0;
// Load any 'did' values that are used in more than one revision.
$records = db_query("SELECT did
FROM {panelizer_entity}
WHERE revision_id > 0 AND did <> 0 AND did IS NOT NULL
GROUP BY did
HAVING count(revision_id) > 1");
// If there are no records, there's nothing to do.
if ($records->rowCount() == 0) {
return t('No Panelizer display records need fixing.');
}
// Total records that must be processed.
$sandbox['max'] = $records->rowCount();
watchdog('panelizer', 'Need to fix @count duplicate displays.', array('@count' => $records->rowCount()));
}
// Loop through the records in smaller chunks.
$dids = db_query_range("SELECT did
FROM {panelizer_entity}
WHERE revision_id > 0 AND did <> 0 AND did IS NOT NULL
GROUP BY did
HAVING count(revision_id) > 1", 0, $limit)->fetchCol();
// Track the entities that need to be reset.
$cache_clear = array();
ctools_include('plugins', 'panels');
ctools_include('content');
// Load all of the requested displays.
foreach (panels_load_displays($dids) as $original_did => $display) {
// Load each panelizer_entity record for this display.
$panelizers = db_query("SELECT * FROM {panelizer_entity} WHERE did=:did", array(':did' => $display->did));
$ctr = 0;
foreach ($panelizers as $panelizer) {
$ctr++;
// Skip the first record.
if ($ctr === 1) {
$ctr++;
continue;
}
// Reset the 'did' value so that a new record can be created.
unset($display->did);
// Regenerate the UUID.
$display->uuid = ctools_uuid_generate();
// Save the display, thus creating a new 'did' value. Also, using
// db_insert() as it's safer than using drupal_write_record() directly
// during an update script. Also, doing each field individually to avoid
// corrupting data during hook_panels_display_save.
$display->did = db_insert('panels_display')
->fields(array(
'layout' => $display->layout,
'layout_settings' => serialize($display->layout_settings),
'panel_settings' => serialize($display->panel_settings),
'cache' => serialize($display->cache),
'title' => $display->title,
'hide_title' => $display->hide_title,
'title_pane' => $display->title_pane,
'uuid' => $display->uuid,
))
->execute();
$message = 'Panelizer update 7115: created display %did for %entity_type %entity_id';
$message_args = array(
'%did' => $display->did,
'%entity_type' => $panelizer->entity_type,
'%entity_id' => $panelizer->entity_id,
);
watchdog('panelizer', $message, $message_args, WATCHDOG_NOTICE);
// Reset the 'pid' values of each pane, using a new UUID. Because its
// non-numeric, when the display is saved it'll create a new record for
// each pane, but still keep all of the internal pointers accurate.
foreach ($display->panels as $region => $panes) {
foreach ((array) $panes as $position => $pid) {
// Pane not found. Shouldn't happen, but you never know.
if (!isset($display->content[$pid])) {
watchdog('panelizer', 'Panelizer update 7115: couldn\'t load pane %pid for display %did', array('%pid' => $pid, '%did' => $display->did), WATCHDOG_WARNING);
continue;
}
// Load the pane.
$new_pane = clone $display->content[$pid];
// This appears to only serve the purpose of ensuring necessary APIs
// and include files are loaded.
ctools_get_content_type($new_pane->type);
// Remove the pid, it'll be created during the database insertion.
unset($new_pane->pid);
// Generate a new UUID.
$new_pane->uuid = ctools_uuid_generate();
// Update the pane's did.
$new_pane->did = $display->did;
// Create the pane record, save the return ID as the pane pid. Again,
// using db_insert directly because it's safer than
// drupal_write_record during an update script. Also, doing the fields
// individually so that the data isn't corrupted during
// hook_panels_pane_insert.
$new_pane->pid = db_insert('panels_pane')
->fields(array(
'did' => $new_pane->did,
'panel' => $new_pane->panel,
'type' => $new_pane->type,
'subtype' => $new_pane->subtype,
'shown' => $new_pane->shown,
'access' => serialize($new_pane->access),
'configuration' => serialize($new_pane->configuration),
'cache' => serialize($new_pane->cache),
'style' => serialize($new_pane->style),
'css' => serialize($new_pane->css),
'extras' => serialize($new_pane->extras),
'locks' => serialize($new_pane->locks),
'uuid' => $new_pane->uuid,
))
->execute();
// Tell the world.
module_invoke_all('panels_pane_insert', $new_pane);
watchdog('panelizer', 'Panelizer update 7115: created pane %pid for display %did', array('%pid' => $new_pane->pid, '%did' => $new_pane->did), WATCHDOG_NOTICE);
// Update the optional title pane.
if (isset($display->title_pane) && $display->title_pane == $pid) {
$display->title_pane = $new_pane->pid;
// Do a simple update query to write it so we don't have to rewrite
// the whole record. We can't just save writing the whole record
// here because it was needed to get the did. Chicken, egg, more
// chicken.
db_update('panels_display')
->fields(array(
'title_pane' => $new_pane->pid
))
->condition('did', $display->did)
->execute();
}
}
}
// Allow other modules to take action when a display is saved.
module_invoke_all('panels_display_save', $display);
// Assign the new display to this Panelizer record.
$panelizer->did = $display->did;
// Update the {panelizer} record.
db_update('panelizer_entity')
->fields((array) $panelizer)
->condition('entity_type', $panelizer->entity_type)
->condition('entity_id', $panelizer->entity_id)
->condition('revision_id', $panelizer->revision_id)
->condition('view_mode', $panelizer->view_mode)
->execute();
// Clear this entity's cache.
$cache_clear[$panelizer->entity_type][] = $panelizer->entity_id;
}
watchdog('panelizer', 'Panelizer update 7115: finished fixing %did', array('%did' => $original_did), WATCHDOG_NOTICE);
$sandbox['progress']++;
}
// Clear the caches for any entities that are updated.
foreach ($cache_clear as $entity_type => $entity_ids) {
entity_get_controller($entity_type)->resetCache($entity_ids);
}
$sandbox['#finished'] = ($sandbox['progress'] >= $sandbox['max']) ? TRUE : ($sandbox['progress'] / $sandbox['max']);
return t('Fixed @count Panelizer record(s) (out of @total) that were using the same display.', array('@count' => $sandbox['progress'], '@total' => $sandbox['max']));
}
/**
* Notify the site builder that the "Panelizer" tabs have been renamed.
*/
function panelizer_update_7116() {
drupal_set_message(t('Note: the "Panelizer" tabs on content, user, term pages, etc have been renamed to "Customize display".'));
}
/**
* Clear the menu cache to pull in the new menu paths.
*/
function panelizer_update_7117() {
variable_set('menu_rebuild_needed', TRUE);
drupal_set_message(t('Note: the main Panelizer configuration page has moved to the "Structure" menu instead of the "Config" menu.'));
}
/**
* Reload the menus to fix the 'content' default local tasks.
*/
function panelizer_update_7118() {
variable_set('menu_rebuild_needed', TRUE);
}
/**
* Fix any {panelizer_entity} records that were broken by update 7115. This may
* take some time.
*/
function panelizer_update_7119(&$sandbox) {
// Process records by groups of 10 (arbitrary value).
$limit = 10;
// When ran through Drush it's Ok to process a larger number of objects at a
// time.
if (drupal_is_cli()) {
$limit = 100;
}
// The update hasn't been ran before.
if (!isset($sandbox['progress'])) {
// The count of records visited so far.
$sandbox['progress'] = 0;
// Load any 'panelizer_entity' values that are corrupt.
$records = db_query("SELECT DISTINCT entity_type, entity_id
FROM {panelizer_entity}
WHERE contexts LIKE 's:%'
OR relationships LIKE 's:%'
OR extra LIKE 's:%'");
// If there are no records, there's nothing to do.
if ($records->rowCount() == 0) {
return t('No {panelizer_entity} records were corrupted by update 7115.');
}
// Total records that must be processed.
$sandbox['max'] = $records->rowCount();
watchdog('panelizer', 'Need to fix {panelizer_entity} records for @count entities that were damaged by update 7115.', array('@count' => $records->rowCount()));
}
// Get a small batch of records.
$records = db_query_range("SELECT DISTINCT entity_type, entity_id
FROM {panelizer_entity}
WHERE contexts LIKE 's:%'
OR relationships LIKE 's:%'
OR extra LIKE 's:%'", 0, $limit);
// Loop over each record.
foreach ($records as $record) {
// Track whether this entity needs to be fixed.
$entity_updated = FALSE;
// Get each {panelizer_record} for this entity.
$entity_records = db_query("SELECT *
FROM {panelizer_entity}
WHERE entity_type = :entity_type
AND entity_id = :entity_id
ORDER BY revision_id", (array)$record);
foreach ($entity_records as $panelizer) {
$last_display = NULL;
// Unserialize each of the serialized values.
foreach (array('contexts', 'relationships', 'extra') as $val) {
$panelizer->$val = unserialize($panelizer->$val);
}
// Keep track of whether the record needs to be saved.
$panelizer_updated = FALSE;
// Verify each of the items is an array or if it was double-serialized.
foreach (array('contexts', 'relationships', 'extra') as $val) {
if (is_string($panelizer->$val)) {
$panelizer->$val = unserialize($panelizer->$val);
$panelizer_updated = TRUE;
$entity_updated = TRUE;
}
}
// Update the {panelizer_entity} record.
if ($panelizer_updated) {
db_update('panelizer_entity')
->fields(array(
'contexts' => serialize($panelizer->contexts),
'relationships' => serialize($panelizer->relationships),
'extra' => serialize($panelizer->extra),
))
->condition('entity_type', $panelizer->entity_type)
->condition('entity_id', $panelizer->entity_id)
->condition('revision_id', $panelizer->revision_id)
->condition('view_mode', $panelizer->view_mode)
->execute();
}
}
// The entity was updated so clear its cache.
if ($entity_updated) {
entity_get_controller($panelizer->entity_type)->resetCache(array($panelizer->entity_id));
}
$sandbox['progress']++;
}
$sandbox['#finished'] = ($sandbox['progress'] >= $sandbox['max']) ? TRUE : ($sandbox['progress'] / $sandbox['max']);
return t('Fixed {panelizer_entity} records for @count entities out of @total total.', array('@count' => $sandbox['progress'], '@total' => $sandbox['max']));
}