Problem/Motivation
This can perhaps be seen as follow-up on
#2551727: Menu link migrations should be defensive →
, at least it's a very close topic. I'm not sure if this is a problem with migration or with menu system.
I did a Drupal 6 to Drupal 9 migration with
drush migrate:upgrade
in the step "d6_menu_links_translation" the following happened:
[notice] Upgrading d6_menu_links_translation
[error] Error: Call to a member function getUrl() on null in Drupal\menu_link_content\Entity\MenuLinkContent->getUrlObject() (line 94 of /web/core/modules/menu_link_content/src/Entity/MenuLinkContent.php) #0 /web/core/modules/menu_link_content/src/Entity/MenuLinkContent.php(156): Drupal\menu_link_content\Entity\MenuLinkContent->getUrlObject()
#1 /web/core/modules/menu_link_content/src/Entity/MenuLinkContent.php(222): Drupal\menu_link_content\Entity\MenuLinkContent->getPluginDefinition()
#2 /web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(529): Drupal\menu_link_content\Entity\MenuLinkContent->postSave()
#3 /web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(685): Drupal\Core\Entity\EntityStorageBase->doPostSave()
#4 /web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(455): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave()
#5 /web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(801): Drupal\Core\Entity\EntityStorageBase->save()
#6 /web/core/lib/Drupal/Core/Entity/EntityBase.php(339): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save()
#7 /web/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php(207): Drupal\Core\Entity\EntityBase->save()
#8 /web/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php(167): Drupal\migrate\Plugin\migrate\destination\EntityContentBase->save()
#9 /web/core/modules/migrate/src/MigrateExecutable.php(230): Drupal\migrate\Plugin\migrate\destination\EntityContentBase->import()
#10 /vendor/drush/drush/includes/drush.inc(206): Drupal\migrate\MigrateExecutable->import()
#11 /vendor/drush/drush/includes/drush.inc(197): drush_call_user_func_array()
#12 /web/modules/contrib/migrate_upgrade/src/MigrateUpgradeDrushRunner.php(232): drush_op()
#13 /web/modules/contrib/migrate_upgrade/src/Commands/MigrateUpgradeCommands.php(87): Drupal\migrate_upgrade\MigrateUpgradeDrushRunner->import()
#14 [internal function]: Drupal\migrate_upgrade\Commands\MigrateUpgradeCommands->upgrade()
#15 /vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array()
#16 /vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#17 /vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#18 /vendor/consolidation/annotated-command/src/AnnotatedCommand.php(311): Consolidation\AnnotatedCommand\CommandProcessor->process()
#19 /vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#20 /vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run()
#21 /vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#22 /vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#23 /vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run()
#24 /vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun()
#25 /vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run()
#26 /vendor/drush/drush/drush(4): require('/var/www/vhosts...')
#27 {main}.
I went to the mentioned function and added the following check for debugging:
/**
* {@inheritdoc}
*/
public function getUrlObject() {
if(empty($this->link) || $this->link->first() === NULL){
throw new Exception('Menu link "' . $this->get('title')->value . '" is broken!');
}
return $this->link->first()->getUrl();
}
Which resulted in these three exceptions:
[error] Exception: Menu link "Blog topics" is broken! in Drupal\menu_link_content\Entity\MenuLinkContent->getUrlObject() (line 96 of /web/core/modules/menu_link_content/src/Entity/MenuLinkContent.php).
[notice] Menu link "Blog topics" is broken! (/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:810)
[error] Exception: Menu link "Keywords" is broken! in Drupal\menu_link_content\Entity\MenuLinkContent->getUrlObject() (line 96 of /web/core/modules/menu_link_content/src/Entity/MenuLinkContent.php).
[notice] Menu link "Keywords" is broken! (/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:810)
[error] Exception: Menu link "Sitemap" is broken! in Drupal\menu_link_content\Entity\MenuLinkContent->getUrlObject() (line 96 of /web/core/modules/menu_link_content/src/Entity/MenuLinkContent.php).
As I have no clue why this happens, I exported the "Sitemap" Entry as JSON from the DB:
[
{
"type":"header",
"version":"5.1.0",
"comment":"Export to JSON plugin for PHPMyAdmin"
},
{
"type":"database",
"name":"usr_web16_3"
},
{
"type":"table",
"name":"drupalmenu_links",
"database":"usr_web16_3",
"data":[
{
"menu_name":"secondary-links",
"mlid":"5287",
"plid":"0",
"link_path":"sitemap",
"router_path":"sitemap",
"link_title":"Sitemap",
"options":"0x613a323a7b733a31303a2261747472696275746573223b613a313a7b733a353a227469746c65223b733a303a22223b7d733a353a22616c746572223b623a313b7d",
"module":"menu",
"hidden":"0",
"external":"0",
"has_children":"0",
"expanded":"0",
"weight":"-48",
"depth":"1",
"customized":"1",
"p1":"5287",
"p2":"0",
"p3":"0",
"p4":"0",
"p5":"0",
"p6":"0",
"p7":"0",
"p8":"0",
"p9":"0",
"updated":"0"
}
]
}
]
Steps to reproduce
See above. I'm unsure what's the specific problem with these three Drupal 6 menu entries, but it should be handled more defensive, I guess.
Proposed resolution
Do not let migrate create such "broken" objects or ensure there's no null-pointer.
Remaining tasks
Add data that causes the problem to the Drupal 6 migration test fixture
Update \Drupal\Tests\menu_link_content\Kernel\Migrate\d6\MigrateMenuLinkTranslationTest
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A