public function setArticleRendition($articleNumber, Rendition $rendition, ImageInterface $image, $imageSpecs = null) { if ($image->getWidth() < $rendition->getWidth() || $image->getHeight() < $rendition->getHeight()) { throw new \InvalidArgumentException("Image too small."); } $old = $this->getArticleRendition($articleNumber, $rendition); if ($old !== null) { $this->orm->remove($old); $this->orm->flush(); } $articleRendition = new ArticleRendition($articleNumber, $rendition, $image, $imageSpecs); $this->orm->persist($articleRendition); $this->orm->flush($articleRendition); return $articleRendition; }