Block import blows up if no custom blocks have been exported

Created on 13 July 2023, over 1 year ago

Problem/Motivation

This is less of a problem than 🐛 Import breaks when no taxonomy terms have been exported (patch available) Fixed or 🐛 Import breaks when no menu's have been exported (patch available) Fixed because the blocks import runs last so doesn't interrupt the other imports— but it still blows up spectacularly and it doesn't need to; the same fix as for those should work the same.

Steps to reproduce

Simply export both taxonomies and menus but not blocks, and then use "import all" to try to import both taxonomies and menus:

mass [new-design]$ d ia
Importing taxonomies...

 What import style would you like?:
  [0] Full
  [1] Safe
  [2] Force
 > 1

Using "Safe" import style
 [notice] Taxonomy import started
 [notice] Using "safe" style for taxonomy import
 [notice] Successfully imported taxonomies
Importing blocks...
 What import style would you like?:
  [0] Full
  [1] Safe
  [2] Force
 > 1

Using "Safe" import style
 [notice] Custom blocks import started
 [notice] Using "safe" style for custom blocks import
 [error]  TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 343 of /var/www/html/web/modules/contrib/structure_sync/src/Controller/BlocksController.php) #0 /var/www/html/web/modules/contrib/structure_sync/src/Controller/BlocksController.php(343): count(NULL)     
#1 /var/www/html/web/modules/contrib/structure_sync/src/Controller/BlocksController.php(154): Drupal\structure_sync\Controller\BlocksController::importBlocksSafe(NULL, Array)                                    
#2 /var/www/html/web/modules/contrib/structure_sync/src/StructureSyncHelper.php(60): Drupal\structure_sync\Controller\BlocksController->importBlocks(Array, NULL)                                                 
#3 /var/www/html/web/modules/contrib/structure_sync/src/Commands/StructureSyncCommands.php(119): Drupal\structure_sync\StructureSyncHelper::importCustomBlocks(Array)                                             
#4 /var/www/html/web/modules/contrib/structure_sync/src/Commands/StructureSyncCommands.php(197): Drupal\structure_sync\Commands\StructureSyncCommands->importBlocks(Array)                                        
#5 [internal function]: Drupal\structure_sync\Commands\StructureSyncCommands->importAll(Array)           
#6 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)                                                                                         
#7 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))                                                                                                      
#8 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))                                                                                              
#9 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))                                                  
#10 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                     
#11 /var/www/html/vendor/symfony/console/Application.php(1081): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                  
#12 /var/www/html/vendor/symfony/console/Application.php(320): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                     
#13 /var/www/html/vendor/symfony/console/Application.php(174): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                     
#14 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))                                                                                                   
#15 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))                                                     
#16 /var/www/html/vendor/drush/drush/drush.php(79): Drush\Runtime\Runtime->run(Array)                    
#17 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')                             
#18 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...')                                   
#19 {main}.                                                                                              
TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/www/html/web/modules/contrib/structure_sync/src/Controller/BlocksController.php on line 343 #0 /var/www/html/web/modules/contrib/structure_sync/src/Controller/BlocksController.php(343): count(NULL)
#1 /var/www/html/web/modules/contrib/structure_sync/src/Controller/BlocksController.php(154): Drupal\structure_sync\Controller\BlocksController::importBlocksSafe(NULL, Array)
#2 /var/www/html/web/modules/contrib/structure_sync/src/StructureSyncHelper.php(60): Drupal\structure_sync\Controller\BlocksController->importBlocks(Array, NULL)
#3 /var/www/html/web/modules/contrib/structure_sync/src/Commands/StructureSyncCommands.php(119): Drupal\structure_sync\StructureSyncHelper::importCustomBlocks(Array)
#4 /var/www/html/web/modules/contrib/structure_sync/src/Commands/StructureSyncCommands.php(197): Drupal\structure_sync\Commands\StructureSyncCommands->importBlocks(Array)
#5 [internal function]: Drupal\structure_sync\Commands\StructureSyncCommands->importAll(Array)
#6 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
#7 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#8 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#9 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/html/vendor/symfony/console/Application.php(1081): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/html/vendor/symfony/console/Application.php(320): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/vendor/symfony/console/Application.php(174): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/html/vendor/drush/drush/drush.php(79): Drush\Runtime\Runtime->run(Array)
#17 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#18 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...')
#19 {main}
TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 343 of /var/www/html/web/modules/contrib/structure_sync/src/Controller/BlocksController.php).
 [warning] Drush command terminated abnormally.
Failed to run drush ia: exit status 1

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇺🇸United States mlncn Minneapolis, MN, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024