/**
* Invalidates any cached files.
*
* @param UploadedFile $file The file to invalidate
*/
public function invalidate(UploadedFile $file)
{
/**
* @var EntityManager
*/
$entityManager = $this->container->get('doctrine')->getManager();
$queryBuilder = $entityManager->createQueryBuilder();
$queryBuilder->select(['c'])->from('PartKeepr\\ImageBundle\\Entity\\CachedImage', 'c')->where('c.originalId = :id')->andWhere('c.originalType = :type')->setParameter('id', $file->getId())->setParameter('type', $file->getType());
$query = $queryBuilder->getQuery();
foreach ($query->getResult() as $file) {
/**
* @var CachedImage
*/
if (file_exists($file->getCacheFile())) {
unlink($file->getCacheFile());
}
$entityManager->remove($file);
}
}