WSOD Error when file entity doesn't exist

Created on 5 October 2023, about 1 year ago
Updated 14 November 2023, about 1 year ago

Problem/Motivation

I'm getting a WSOD error when a file entity doesn't exist, this happens in this piece of code:
./src/Controller/WebformDownloadAllController::add lines 190-196

        foreach ($file as $f) {
          $file_obj = $this->entityTypeManager->getStorage('file')->load($f);
          if ($file_obj) {
            $file = $this->fileSystem->realpath($file_obj->getFileUri());
          }
          $file_zip->add($file);
        }

The problem is that $file only gets set if the bool value of $file_obj is TRUE, so I think the simple fix would be to move the $file_zip->add($file); line to the inside of that if statement.

Steps to reproduce

I don't know the exact steps of how this came to be, but the cause is a file entity that's still somehow linked in a webform submission without actually existing.

Proposed resolution

Moving the $file_zip->add($file); line to inside the if statement.

[Warning]: After this issue I ran into some other strange stuff and decided to refactor a bit of code. Hence the patch will be rather large.

Please review and hopefully commit the fix.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇧🇪Belgium RandalV

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

Comments & Activities

Production build 0.71.5 2024