Check if File:getById is empty
Permalink
Hey
In my block I update a PDF and want to show it in frontend. In view.php I´m getting the file path by $file = File::getById($content). How is it possible to check if the file is not available?
In my block I update a PDF and want to show it in frontend. In view.php I´m getting the file path by $file = File::getById($content). How is it possible to check if the file is not available?
Hey John. Thanks for your reply! But I think my question is bad!
Let´s assume that I´m showing a picture with the image-block. The image is shown. Yeah. But now someone removes the image from the server. The database-value for the image (e.g. imageId: 2) is still there but not the image itself. I´m submitting a new add-on to the marketplace but one of the PRB members said, that I have to check if the file/image is available before I get the version. So I got this code:
Now, how is it possible to ensure, that the $file-getVersion() is not called, when the file is not longer available.
Let´s assume that I´m showing a picture with the image-block. The image is shown. Yeah. But now someone removes the image from the server. The database-value for the image (e.g. imageId: 2) is still there but not the image itself. I´m submitting a new add-on to the marketplace but one of the PRB members said, that I have to check if the file/image is available before I get the version. So I got this code:
$file = File::getById($content); $filePath = $file->getVersion()->getRelativePath();
Now, how is it possible to ensure, that the $file-getVersion() is not called, when the file is not longer available.
Maybe something like below. Each time you get an object, check it exists before doing anything with it.
Does anyone have an idea for an approach in 5.8?
It appears 5.8 is much more aggressive in the way it handles missing files. Returning FileNotFound exceptions if a file is missing and also issues if a File Attribute points to a file that no longer exists.
We have an image attribute, that was assigned to a page. Subsequently someone has deleted the file which now in 5.8 returns an Entity not found exception Exception.
It appears 5.8 is much more aggressive in the way it handles missing files. Returning FileNotFound exceptions if a file is missing and also issues if a File Attribute points to a file that no longer exists.
We have an image attribute, that was assigned to a page. Subsequently someone has deleted the file which now in 5.8 returns an Entity not found exception Exception.
Entity of type 'Concrete\Core\Entity\File\File' for IDs fID(file_id) was not found
instanceof File doesn't work any more in v8, is_object($file) works
You can also combine more than one of the above with &&.
Some getByID methods, like page/collection objects, can also return an object with an error state, so you sometimes see