Call to a member function getFileUri()

Created on 25 October 2023, 8 months ago
Updated 11 February 2024, 5 months ago

Problem/Motivation

When calling "drush content:export node" in version 1.4.3 on Drupal 10.1.5 I get the error about calling getFileUri()

Steps to reproduce

Install Drupal 10.1.5 and single_content_sync 1.4.3 and then try to run "drush content:export node"

Proposed resolution

Update reference to getFileUri()

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

1.4

Component

Code

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @a.crowe
  • Status changed to Postponed: needs info 8 months ago
  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk

    Hi @a.crowe,
    Can you please post the exact error and stack trace?

  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk
  • Sorry, My account was blocked as I hadn't disabled add blockers!

    The stack trace is as follows,

    Many thanks.

    Andy

    drupal@d10dev:/var/www/d10dev.opengroup.org$ drush content:export

    Executing drush content:export node

    [error] Error: Call to a member function getFileUri() on null in Drupal\single_content_sync\Plugin\SingleContentSyncFieldProcessor\FileAsset->exportFieldValue() (line 117 of /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/Plugin/SingleContentSyncFieldProcessor/FileAsset.php) #0 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(355): Drupal\single_content_sync\Plugin\SingleContentSyncFieldProcessor\FileAsset->exportFieldValue()
    #1 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(334): Drupal\single_content_sync\ContentExporter->getFieldValue()
    #2 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(242): Drupal\single_content_sync\ContentExporter->exportCustomValues()
    #3 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/Plugin/SingleContentSyncFieldProcessor/EntityReferenceRevisions.php(31): Drupal\single_content_sync\ContentExporter->doExportToArray()
    #4 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(355): Drupal\single_content_sync\Plugin\SingleContentSyncFieldProcessor\EntityReferenceRevisions->exportFieldValue()
    #5 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(334): Drupal\single_content_sync\ContentExporter->getFieldValue()
    #6 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(242): Drupal\single_content_sync\ContentExporter->exportCustomValues()
    #7 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(299): Drupal\single_content_sync\ContentExporter->doExportToArray()
    #8 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentFileGenerator.php(67): Drupal\single_content_sync\ContentExporter->doExportToYml()
    #9 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentFileGenerator.php(115): Drupal\single_content_sync\ContentFileGenerator->generateYamlFile()
    #10 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/Commands/ContentSyncCommands.php(174): Drupal\single_content_sync\ContentFileGenerator->generateBulkZipFile()
    #11 [internal function]: Drupal\single_content_sync\Commands\ContentSyncCommands->exportEntitiesCommand()
    #12 /var/www/d10dev.opengroup.org/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
    #13 /var/www/d10dev.opengroup.org/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
    #14 /var/www/d10dev.opengroup.org/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
    #15 /var/www/d10dev.opengroup.org/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process()
    #16 /var/www/d10dev.opengroup.org/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
    #17 /var/www/d10dev.opengroup.org/vendor/symfony/console/Application.php(1081): Symfony\Component\Console\Command\Command->run()
    #18 /var/www/d10dev.opengroup.org/vendor/symfony/console/Application.php(320): Symfony\Component\Console\Application->doRunCommand()
    #19 /var/www/d10dev.opengroup.org/vendor/symfony/console/Application.php(174): Symfony\Component\Console\Application->doRun()
    #20 /var/www/d10dev.opengroup.org/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run()
    #21 /var/www/d10dev.opengroup.org/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun()
    #22 /var/www/d10dev.opengroup.org/vendor/drush/drush/drush.php(79): Drush\Runtime\Runtime->run()
    #23 /var/www/d10dev.opengroup.org/vendor/drush/drush/includes/preflight.inc(18): require('...')
    #24 phar:///usr/local/bin/drush/bin/drush.php(143): drush_main()
    #25 /usr/local/bin/drush(14): require('...')
    #26 {main}.
    Error: Call to a member function getFileUri() on null in /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/Plugin/SingleContentSyncFieldProcessor/FileAsset.php on line 117 #0 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(355): Drupal\single_content_sync\Plugin\SingleContentSyncFieldProcessor\FileAsset->exportFieldValue()
    #1 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(334): Drupal\single_content_sync\ContentExporter->getFieldValue()
    #2 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(242): Drupal\single_content_sync\ContentExporter->exportCustomValues()
    #3 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/Plugin/SingleContentSyncFieldProcessor/EntityReferenceRevisions.php(31): Drupal\single_content_sync\ContentExporter->doExportToArray()
    #4 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(355): Drupal\single_content_sync\Plugin\SingleContentSyncFieldProcessor\EntityReferenceRevisions->exportFieldValue()
    #5 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(334): Drupal\single_content_sync\ContentExporter->getFieldValue()
    #6 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(242): Drupal\single_content_sync\ContentExporter->exportCustomValues()
    #7 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentExporter.php(299): Drupal\single_content_sync\ContentExporter->doExportToArray()
    #8 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentFileGenerator.php(67): Drupal\single_content_sync\ContentExporter->doExportToYml()
    #9 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/ContentFileGenerator.php(115): Drupal\single_content_sync\ContentFileGenerator->generateYamlFile()
    #10 /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/Commands/ContentSyncCommands.php(174): Drupal\single_content_sync\ContentFileGenerator->generateBulkZipFile()
    #11 [internal function]: Drupal\single_content_sync\Commands\ContentSyncCommands->exportEntitiesCommand()
    #12 /var/www/d10dev.opengroup.org/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
    #13 /var/www/d10dev.opengroup.org/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
    #14 /var/www/d10dev.opengroup.org/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
    #15 /var/www/d10dev.opengroup.org/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process()
    #16 /var/www/d10dev.opengroup.org/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
    #17 /var/www/d10dev.opengroup.org/vendor/symfony/console/Application.php(1081): Symfony\Component\Console\Command\Command->run()
    #18 /var/www/d10dev.opengroup.org/vendor/symfony/console/Application.php(320): Symfony\Component\Console\Application->doRunCommand()
    #19 /var/www/d10dev.opengroup.org/vendor/symfony/console/Application.php(174): Symfony\Component\Console\Application->doRun()
    #20 /var/www/d10dev.opengroup.org/vendor/drush/drush/src/Runtime/Runtime.php(124): Symfony\Component\Console\Application->run()
    #21 /var/www/d10dev.opengroup.org/vendor/drush/drush/src/Runtime/Runtime.php(51): Drush\Runtime\Runtime->doRun()
    #22 /var/www/d10dev.opengroup.org/vendor/drush/drush/drush.php(79): Drush\Runtime\Runtime->run()
    #23 /var/www/d10dev.opengroup.org/vendor/drush/drush/includes/preflight.inc(18): require('...')
    #24 phar:///usr/local/bin/drush/bin/drush.php(143): drush_main()
    #25 /usr/local/bin/drush(14): require('...')
    #26 {main}
    Error: Call to a member function getFileUri() on null in Drupal\single_content_sync\Plugin\SingleContentSyncFieldProcessor\FileAsset->exportFieldValue() (line 117 of /var/www/d10dev.opengroup.org/web/modules/contrib/single_content_sync/src/Plugin/SingleContentSyncFieldProcessor/FileAsset.php).
    [warning] Drush command terminated abnormally.

  • Status changed to Needs work 7 months ago
  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk

    Had a quick look in the code, it is possible that the issue is happening if the field is referencing non-existing file.

    From FileAsset.php:

          $file = $file_storage->load($item['target_id']);
    
          $file_item = [
            'uri' => $file->getFileUri(),
            'url' => $file->createFileUrl(FALSE),
          ];
    
    

    Just as a quick test, can you please add the following line after $file = $file_storage->load($item['target_id']); (line 114 in FileAsset.php)?

    if (!$file) { continue; }
    

    Note this is not a correct fix, just a quick check to see if I guessed correctly.

  • That was a quick response, and worked a treat thanks. :-)

    Now when I run it I get the following (success)

    ---------
    drupal@d10dev:/var/www/d10dev.opengroup.org$ drush content:export

    Executing drush content:export node

    [warning] Message: The value of /Comments/ is empty because field type "comment" is not
    exportable out-of-the-box. Check README for a workaround.

    [warning] Message: The value of /Feeds item/ is empty because field type "feeds_item" is not
    exportable out-of-the-box. Check README for a workaround.

    [notice] Message: Successfully exported the content. You can find the exported file at the
    following location:
    /var/www/d10dev.opengroup.org/web/scs-export/content-bulk-export-21_11_2023-09_31.zip
    ----------

    What is the next step to get this into a release?

    Many thanks

    Andy.

  • Assigned to abramm
  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk

    Thanks for a quick test!
    I'll handle the rest, just wanted to make sure I guessed the correct reason for this.
    Not sure about timing but I'm planning to get into this someday this week.

  • πŸ‡ΊπŸ‡¦Ukraine nginex
  • Issue was unassigned.
  • Status changed to Needs review 5 months ago
  • πŸ‡ΊπŸ‡¦Ukraine nginex
  • Assigned to danmer
  • πŸ‡ΊπŸ‡¦Ukraine danmer
  • Status changed to RTBC 5 months ago
  • πŸ‡ΊπŸ‡¦Ukraine danmer

    It looks good to be merged

  • Issue was unassigned.
  • Status changed to Fixed 5 months ago
  • πŸ‡ΊπŸ‡¦Ukraine nginex
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024