/**
* @param FileUpload $file
* @return Image
* @throws NotImageUploadedException
* @throws FileSizeException
* @throws DBALException
* @throws InvalidStateException
*/
public function processImage(FileUpload $file)
{
if (!$file->isImage()) {
throw new NotImageUploadedException();
}
if (\filesize($file->getTemporaryFile()) > Image::MAX_FILE_SIZE) {
throw new FileSizeException();
}
try {
$this->em->beginTransaction();
$image = new Image($file);
$this->em->persist($image)->flush();
$file->move($this->composeImageLocation($image));
$this->em->commit();
} catch (InvalidStateException $is) {
$this->em->rollback();
$this->em->close();
$this->logger->addError('Error occurs while moving temp. image file to new location.');
throw $is;
} catch (DBALException $e) {
$this->em->rollback();
$this->em->close();
$this->logger->addError('Image error');
// todo err message
throw $e;
}
return $image;
}