@@ -517,3 +517,92 @@ function ghi_blocks_deploy_90010_update_funding_coverage_default_label_page_temp
517
517
]);
518
518
}
519
519
}
520
+
521
+ /**
522
+ * Fix broken configuration for headline figure elements on nodes.
523
+ */
524
+ function ghi_blocks_deploy_9010_fix_broken_block_config (&$ sandbox ) {
525
+ set_time_limit (30 );
526
+ if (!isset ($ sandbox ['nodes ' ])) {
527
+ $ result = \Drupal::database ()->select ('node__layout_builder__layout ' )
528
+ ->fields ('node__layout_builder__layout ' , ['entity_id ' ])
529
+ ->condition ('layout_builder__layout_section ' , '%processing";s:0% ' , 'LIKE ' )
530
+ ->orderBy ('entity_id ' )
531
+ ->execute ();
532
+ $ sandbox ['nodes ' ] = array_map (function ($ row ) {
533
+ return $ row ->entity_id ;
534
+ }, $ result ->fetchAll ());
535
+ $ sandbox ['total ' ] = count ($ sandbox ['nodes ' ]);
536
+ $ sandbox ['updated ' ] = 0 ;
537
+ }
538
+ for ($ i = 0 ; $ i < 25 ; $ i ++) {
539
+ if (empty ($ sandbox ['nodes ' ])) {
540
+ continue ;
541
+ }
542
+ $ node_id = array_shift ($ sandbox ['nodes ' ]);
543
+ /** @var \Drupal\node\NodeInterface $node */
544
+ $ node = \Drupal::entityTypeManager ()->getStorage ('node ' )->load ($ node_id );
545
+ if (!$ node ) {
546
+ continue ;
547
+ }
548
+
549
+ $ changed = FALSE ;
550
+ if (!$ node ->hasField (OverridesSectionStorage::FIELD_NAME )) {
551
+ continue ;
552
+ }
553
+ $ sections = $ node ->get (OverridesSectionStorage::FIELD_NAME )->getValue ();
554
+ if (empty ($ sections )) {
555
+ continue ;
556
+ }
557
+ /** @var \Drupal\layout_builder\Section $section */
558
+ $ section = &$ sections [0 ]['section ' ];
559
+ $ components = $ section ->getComponents ();
560
+ if (empty ($ components )) {
561
+ continue ;
562
+ }
563
+ foreach ($ components as $ component ) {
564
+ if ($ component ->getPluginId () != 'plan_headline_figures ' ) {
565
+ continue ;
566
+ }
567
+ $ configuration = $ component ->get ('configuration ' );
568
+ if (empty ($ configuration ['hpc ' ]['key_figures ' ]['items ' ])) {
569
+ return $ changed ;
570
+ }
571
+
572
+ $ items = &$ configuration ['hpc ' ]['key_figures ' ]['items ' ];
573
+ $ original_count = count ($ items );
574
+ $ items = array_filter ($ items , function ($ item ) {
575
+ if ($ item ['item_type ' ] != 'attachment_data ' ) {
576
+ return TRUE ;
577
+ }
578
+ return !empty ($ item ['config ' ]['data_point ' ]['processing ' ]);
579
+ });
580
+ if (count ($ items ) != $ original_count ) {
581
+ $ changed = TRUE ;
582
+ $ component ->setConfiguration ($ configuration );
583
+ }
584
+ }
585
+
586
+ if ($ changed ) {
587
+ $ node ->get (OverridesSectionStorage::FIELD_NAME )->setValue ($ sections );
588
+ $ node ->setNewRevision (FALSE );
589
+ $ node ->setSyncing (TRUE );
590
+ $ node ->save ();
591
+ $ sandbox ['updated ' ]++;
592
+ }
593
+ }
594
+
595
+ $ sandbox ['#finished ' ] = 1 / (count ($ sandbox ['nodes ' ]) + 1 );
596
+ if ($ sandbox ['#finished ' ] === 1 ) {
597
+ return t ('Updated configurations in @count_changed / @count_total nodes ' , [
598
+ '@count_changed ' => $ sandbox ['updated ' ],
599
+ '@count_total ' => $ sandbox ['total ' ],
600
+ ]);
601
+ }
602
+ else {
603
+ return t ('Processed @count_processed / @count_total nodes ' , [
604
+ '@count_processed ' => $ sandbox ['total ' ] - count ($ sandbox ['nodes ' ]),
605
+ '@count_total ' => $ sandbox ['total ' ],
606
+ ]);
607
+ }
608
+ }
0 commit comments