Prevent book saving error

Created on 30 August 2018, almost 6 years ago
Updated 17 June 2024, 10 days ago

Problem/Motivation

Exception when saving a node that is part of a book:

TypeError: Argument 2 passed to Drupal\book\BookManager::moveChildren() must be of the type array, boolean given, called in                        [error]
/var/www/docroot/core/modules/book/src/BookManager.php on line 812 in Drupal\book\BookManager->moveChildren() (line 842 of
/var/www/docroot/core/modules/book/src/BookManager.php) #0 /var/www/docroot/core/modules/book/src/BookManager.php(812):
Drupal\book\BookManager->moveChildren(Array, false)
#1 /var/www/docroot/core/modules/book/src/BookManager.php(292): Drupal\book\BookManager->saveBookLink(Array, false)
#2 /var/www/docroot/core/modules/book/book.module(275): Drupal\book\BookManager->updateOutline(Object(Drupal\node\Entity\Node))
#3 [internal function]: book_node_update(Object(Drupal\node\Entity\Node))
#4 /var/www/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(402): call_user_func_array('book_node_updat...', Array)
#5 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(167): Drupal\Core\Extension\ModuleHandler->invokeAll('node_update', Array)
#6 /var/www/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(730): Drupal\Core\Entity\EntityStorageBase->invokeHook('update',
Object(Drupal\node\Entity\Node))
#7 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(469): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update',
Object(Drupal\node\Entity\Node))
#8 /var/www/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(615):
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\node\Entity\Node), true)
#9 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(394):
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\node\Entity\Node), true)
#10 /var/www/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(820):
Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\node\Entity\Node))
#11 /var/www/docroot/core/lib/Drupal/Core/Entity/Entity.php(391):
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\node\Entity\Node))
#12 /var/www/docroot/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php(169): Drupal\Core\Entity\Entity->save()
#13 /var/www/docroot/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php(150):
Drupal\migrate\Plugin\migrate\destination\EntityContentBase->save(Object(Drupal\node\Entity\Node), Array)
#14 /var/www/docroot/core/modules/migrate/src/MigrateExecutable.php(224):
Drupal\migrate\Plugin\migrate\destination\EntityContentBase->import(Object(Drupal\migrate\Row), Array)
#15 /var/www/vendor/drush/drush/includes/drush.inc(720): Drupal\migrate\MigrateExecutable->import()
#16 /var/www/vendor/drush/drush/includes/drush.inc(711): drush_call_user_func_array(Array, Array)
#17 /var/www/docroot/modules/contrib/migrate_tools/migrate_tools.drush.inc(289): drush_op(Array)
#18 [internal function]: _drush_migrate_tools_execute_migration(Object(Drupal\migrate\Plugin\Migration), 'platform_articl...', Array)
#19 /var/www/docroot/modules/contrib/migrate_tools/migrate_tools.drush.inc(255): array_walk(Array, '_drush_migrate_...', Array)
#20 /var/www/vendor/drush/drush/includes/command.inc(422): drush_migrate_tools_migrate_import('platform_articl...')
#21 /var/www/vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#22 /var/www/vendor/drush/drush/includes/command.inc(199): drush_command('platform_articl...')
#23 /var/www/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#24 /var/www/vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#25 /var/www/vendor/drush/drush/drush.php(12): drush_main()
#26 {main}.

This happened in the process of a migration, so maybe it is an edge case, but the logic change is IMHO still beneficial.

Detection of a new book node is done at Drupal\book\BookManager::updateOutline(), and the reaction seems to have a logic error.

Proposed resolution

Verify the output of loadBookLink(), which can be FALSE, to prevent passing a wrong value to saveBookLink().

Remaining tasks


Review

User interface changes

No.

API changes

No.

Data model changes

N.A.

πŸ› Bug report
Status

Postponed: needs info

Version

1.0

Component
BookΒ  β†’

Last updated 1 day ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @pwolanin
Created by

πŸ‡΅πŸ‡ͺPeru marvil07

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024