示例#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
 /**
  * {@inheritdoc}
  */
 public function getUuidForClass($className)
 {
     $entityRepository = $this->entityManager->getRepository($className);
     do {
         $uuid = $this->randomStringUtil->getRandomString(static::UUID_LENGTH);
         $existingEntity = $entityRepository->findOneBy(['uuid' => $uuid]);
     } while ($existingEntity !== null);
     return $uuid;
 }
 /**
  * @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);
     }
 }