예제 #1
0
 /**
  * @param Asset $asset
  */
 private function clearSubAssets(Asset $asset)
 {
     /** @var SubAsset $subAsset */
     foreach ($asset->getSubAssets() as $subAsset) {
         $this->entityManager->remove($subAsset, false);
     }
     $this->entityManager->flush();
 }
예제 #2
0
 /**
  * @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);
     }
 }