/**
  * @param Asset $asset
  */
 private function clearSubAssets(Asset $asset)
 {
     /** @var SubAsset $subAsset */
     foreach ($asset->getSubAssets() as $subAsset) {
         $this->entityManager->remove($subAsset, false);
     }
     $this->entityManager->flush();
 }
 /**
  * @param Asset $asset
  * @return string
  */
 public function handleSave(Asset $asset)
 {
     /** @var SubAsset $subAsset */
     foreach ($asset->getSubAssets() as $subAsset) {
         $this->entityManager->remove($subAsset, false);
     }
     $this->entityManager->flush();
     /** If it's the same field, skip initializing and uploading it. */
     if ($asset->getOriginalFileName() !== $asset->getUploadedFile()->getClientOriginalName()) {
         $asset->setOriginalFileName($asset->getUploadedFile()->getClientOriginalName());
         $ext = $asset->getUploadedFile()->guessExtension();
         $asset->setFileType($ext);
         $key = substr(sha1(uniqid()), 0, 15);
         $newFilename = $key . "." . $ext;
         $asset->setFilename($newFilename);
         $this->assetStorage->uploadAsset($asset);
     }
 }
Exemple #3
0
 /**
  * @param Asset $asset
  */
 public function removeAsset(Asset $asset)
 {
     if (strlen($asset->getRelativeUrl()) > 20) {
         $this->s3Client->deleteObject(['Key' => $asset->getRelativeUrl(), 'Bucket' => $this->bucket]);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getUrlForAsset(Asset $asset)
 {
     return $asset->getRelativeUrl();
 }
 /**
  * @param Asset $asset
  */
 public function removeAsset(Asset $asset)
 {
     unlink($this->basePath . $asset->getRelativeUrl());
 }
 /**
  * @param Asset $asset
  * @return boolean
  */
 public function supportsAsset(Asset $asset)
 {
     return $asset->isImage();
 }