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:
$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.

jero
View Replies:
A3020 replied on at Permalink Reply
A3020
I just added this to a public/application/bootstrap.php on a 8.4.2 instance:

$file = \Concrete\Core\File\File::getByID(333333);
dd($file);

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.
jero replied on at Permalink Reply
jero
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.
ConcreteOwl replied on at Permalink Reply
ConcreteOwl
What happens if you replace this
if (is_object($thumb))

with this
if ($thumb):
jero replied on at Permalink Reply
jero
It makes no difference. The exception still occurs.
mnakalay replied on at Permalink Reply
mnakalay
Can you check which class name that $thumb object has?
jero replied on at Permalink Reply
jero
According to get_class(), it's an instance of
DoctrineProxies\__CG__\Concrete\Core\Entity\File\File
mnakalay replied on at Permalink Reply
mnakalay
I think you might fix the problem by refreshing your Doctrine entities.
jero replied on at Permalink Reply
jero
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
c5dragon replied on at Permalink Reply
c5dragon
Medon replied on at Permalink Reply
Medon
This might help until it is solved.
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.