/** * {@inheritdoc} */ public function delete($id) { $mediaEntity = $this->mediaRepository->findMediaById($id); if (!$mediaEntity) { throw new MediaNotFoundException('Media with the ID ' . $id . ' not found.'); } /** @var File $file */ foreach ($mediaEntity->getFiles() as $file) { /** @var FileVersion $fileVersion */ foreach ($file->getFileVersions() as $fileVersion) { $this->formatManager->purge($mediaEntity->getId(), $fileVersion->getName(), $fileVersion->getStorageOptions()); } } $this->em->remove($mediaEntity); $this->em->flush(); }
/** * {@inheritdoc} */ public function delete($id, $checkSecurity = false) { $mediaEntity = $this->getEntityById($id); if ($checkSecurity) { $this->securityChecker->checkPermission(new SecurityCondition('sulu.media.collections', null, Collection::class, $mediaEntity->getCollection()->getId()), 'delete'); } /** @var File $file */ foreach ($mediaEntity->getFiles() as $file) { /** @var FileVersion $fileVersion */ foreach ($file->getFileVersions() as $fileVersion) { $this->formatManager->purge($mediaEntity->getId(), $fileVersion->getName(), $fileVersion->getStorageOptions()); $this->storage->remove($fileVersion->getStorageOptions()); } } $this->em->remove($mediaEntity); $this->em->flush(); }
/** * Purges a file-version of a media with a given id. * * @param int $mediaId * @param FileVersion $fileVersion */ private function purgeMedia($mediaId, FileVersion $fileVersion) { $this->formatManager->purge($mediaId, $fileVersion->getName(), $fileVersion->getStorageOptions()); }