Error: Call to a member function getType() on bool in filefield_paths_filefield_paths_process_file()

Created on 21 March 2024, 8 months ago
Updated 9 May 2024, 7 months ago

Problem/Motivation

I am performing a migration with the migrate module, I have configured a migration of files that are assigned to another migration of media entities. When migrating the media entities occurs the following error:

[error]  Error: Call to a member function getType() on bool in filefield_paths_filefield_paths_process_file() (line 75 of /var/www/html/web/modules/contrib/filefield_paths/filefield_paths.inc) #0 /var/www/html/web/modules/contrib/hook_event_dispatcher/src/HookEventDispatcherModuleHandler.php(52): filefield_paths_filefield_paths_process_file(Object(Drupal\media\Entity\Media), Object(Drupal\file\Plugin\Field\FieldType\FileFieldItemList), Array)
#1 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(388): Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler::Drupal\hook_event_dispatcher\{closure}(Object(Closure), 'filefield_paths')
#2 /var/www/html/web/modules/contrib/hook_event_dispatcher/src/HookEventDispatcherModuleHandler.php(67): Drupal\Core\Extension\ModuleHandler->invokeAllWith('filefield_paths...', Object(Closure))
#3 /var/www/html/web/modules/contrib/hook_event_dispatcher/src/HookEventDispatcherModuleHandler.php(51): Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler->invokeAllWith('filefield_paths...', Object(Closure))
#4 /var/www/html/web/modules/contrib/filefield_paths/filefield_paths.module(352): Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler->invokeAll('filefield_paths...', Array)
#5 /var/www/html/web/modules/contrib/filefield_paths/filefield_paths.module(337): filefield_paths_entity_update(Object(Drupal\media\Entity\Media))
#6 /var/www/html/web/modules/contrib/hook_event_dispatcher/src/HookEventDispatcherModuleHandler.php(52): filefield_paths_entity_insert(Object(Drupal\media\Entity\Media))
#7 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(388): Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler::Drupal\hook_event_dispatcher\{closure}(Object(Closure), 'filefield_paths')
#8 /var/www/html/web/modules/contrib/hook_event_dispatcher/src/HookEventDispatcherModuleHandler.php(67): Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_insert', Object(Closure))
#9 /var/www/html/web/modules/contrib/hook_event_dispatcher/src/HookEventDispatcherModuleHandler.php(51): Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler->invokeAllWith('entity_insert', Object(Closure))
#10 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(217): Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler->invokeAll('entity_insert', Array)
#11 /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(900): Drupal\Core\Entity\EntityStorageBase->invokeHook('insert', Object(Drupal\media\Entity\Media))
#12 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(564): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('insert', Object(Drupal\media\Entity\Media))
#13 /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(781): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\media\Entity\Media), false)
#14 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(489): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\media\Entity\Media), false)
#15 /var/www/html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(806): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\media\Entity\Media))
#16 /var/www/html/web/core/modules/media/src/MediaStorage.php(29): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\media\Entity\Media))
#17 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(354): Drupal\media\MediaStorage->save(Object(Drupal\media\Entity\Media))
#18 /var/www/html/web/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php(237): Drupal\Core\Entity\EntityBase->save()
#19 /var/www/html/web/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php(175): Drupal\migrate\Plugin\migrate\destination\EntityContentBase->save(Object(Drupal\media\Entity\Media), Array)
#20 /var/www/html/web/core/modules/migrate/src/MigrateExecutable.php(248): Drupal\migrate\Plugin\migrate\destination\EntityContentBase->import(Object(Drupal\migrate\Row), Array)
#21 /var/www/html/vendor/drush/drush/includes/drush.inc(62): Drupal\migrate\MigrateExecutable->import()
#22 /var/www/html/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array(Array, Array)
#23 /var/www/html/vendor/drush/drush/src/Commands/core/MigrateRunnerCommands.php(421): drush_op(Array)
#24 [internal function]: Drush\Commands\core\MigrateRunnerCommands->executeMigration(Object(Drupal\migrate\Plugin\Migration), 'reina_migrate_a...', Array)
#25 /var/www/html/vendor/drush/drush/src/Commands/core/MigrateRunnerCommands.php(401): array_walk(Array, Array, Array)
#26 [internal function]: Drush\Commands\core\MigrateRunnerCommands->executeMigration(Object(Drupal\migrate\Plugin\Migration), 'reina_migrate_a...', Array)
#27 /var/www/html/vendor/drush/drush/src/Commands/core/MigrateRunnerCommands.php(371): array_walk(Array, Array, Array)
#28 [internal function]: Drush\Commands\core\MigrateRunnerCommands->import('reina_migrate_a...', Array)
#29 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
#30 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#31 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#32 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(387): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#33 /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))
#34 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
#40 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#41 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...')
#42 {main}.

Proposed resolution

After checking the line where the error occurs (line 75 of /var/www/html/web/modules/contrib/filefield_paths/filefield_paths.inc), I noticed that the error occurs in the following fragment:

  /** @var \Drupal\file\Entity\File $file */
  foreach ($field->referencedEntities() as $file) {
    /** @var \Drupal\Core\StreamWrapper\StreamWrapperInterface $source_scheme */
    $source_scheme = $stream_wrapper_manager->getViaUri($file->getFileUri());
    $source_scheme_name = key($stream_wrapper_manager->getWrappers($source_scheme->getType()));
    if (in_array($source_scheme_name, $schemas) && !empty($wrappers[$destination_scheme_name])) {

The file's URI is obtained, but when obtaining the Stream Wrapper from that URI, the Stream Wrapper returns NULL. To avoid this (and possible future errors) a Stream Wrapper integrity check can be added.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇪🇸Spain enchufe Spain

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024