Deleted Image Causes Exception
Permalink
So here's a good one: I have a site recently upgraded from 5.7.5.13 to 8.4.2. I have a custom page template that attempts to find the thumbnail attribute for a page:
But the user has deleted the image from the file manager, which results in an exception:
Entity of type 'Concrete\Core\Entity\File\File' for IDs fID(7) was not found
There seems to be no way to determine if the file actually exists without throwing an exception. 5.7 simply returned null or false rather than an object so it was easy to tell, but now it seems impossible to tell and moreover much more likely for users to shoot themselves in the foot.
$thumb = $page->getAttribute('thumbnail'); if (is_object($thumb)) $img = $imgHelper->getThumbnail($thumb, 250, 250) ...
But the user has deleted the image from the file manager, which results in an exception:
Entity of type 'Concrete\Core\Entity\File\File' for IDs fID(7) was not found
There seems to be no way to determine if the file actually exists without throwing an exception. 5.7 simply returned null or false rather than an object so it was easy to tell, but now it seems impossible to tell and moreover much more likely for users to shoot themselves in the foot.
I've cleared the cache, using dashboard, cmd line and also by nuking the cache folder from orbit. Refreshed all database entities for good measure - no effect. I turned on development mode so that the entities are generated each time, and then blew them all away - still the same result.
\Concrete\Core\File\File::getByID(7) returns NULL in my template, but $page->getAttribute('thumbnail') returns an object which you can do very little with.
Also trying to view the page properties seems to result in a blue page with nothing showing - because/ccm/system/panels/details/page/composer?cID=199 is throwing the same exception - so it's not just my template that's at fault here.
\Concrete\Core\File\File::getByID(7) returns NULL in my template, but $page->getAttribute('thumbnail') returns an object which you can do very little with.
Also trying to view the page properties seems to result in a blue page with nothing showing - because/ccm/system/panels/details/page/composer?cID=199 is throwing the same exception - so it's not just my template that's at fault here.
It makes no difference. The exception still occurs.
Can you check which class name that $thumb object has?
According to get_class(), it's an instance of
DoctrineProxies\__CG__\Concrete\Core\Entity\File\File
DoctrineProxies\__CG__\Concrete\Core\Entity\File\File
I think you might fix the problem by refreshing your Doctrine entities.
I've refreshed them several times, and even removed everything from the application/config/doctrine/proxies folder. I also switched to using doctrine development mode. Still have the same problem.
It's not just my template either, attempting to access page attributes from the site map appears not to do anything, but the AJAX response is a 500 with the json error having the same error: Entity of type 'Concrete\Core\Entity\File\File' for IDs fID(7) was not found
It's not just my template either, attempting to access page attributes from the site map appears not to do anything, but the AJAX response is a 500 with the json error having the same error: Entity of type 'Concrete\Core\Entity\File\File' for IDs fID(7) was not found
Still a bug in v8.5.0 / php7.1
https://www.concrete5.org/developers/bugs/8-5-0/entity-of-type-concr...
https://www.concrete5.org/developers/bugs/8-5-0/entity-of-type-concr...
This might help until it is solved.
You can just comment out error output.
if($page->getAttribute('thumbnail')) { $img = $page->getAttribute('thumbnail'); try { $thumb = $ih->getThumbnail($img, 500, 375, false); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; $img = false; $thumb = false; } }
You can just comment out error output.
That shows NULL for me, and I don't get an exception. I wonder if you're doing some kind of caching in your template. If you cache the object, and the object is then removed from the file manager, it may cause an exception in the wake method in one of the Doctrine classes.