コード例 #1
0
 /**
  * Update attachment entity before upload
  *
  * @param File $entity
  */
 public function preUpload(File $entity)
 {
     if ($entity->isEmptyFile()) {
         if ($this->filesystem->has($entity->getFilename())) {
             $this->filesystem->delete($entity->getFilename());
         }
         $entity->setFilename(null);
         $entity->setExtension(null);
         $entity->setOriginalFilename(null);
     }
     if ($entity->getFile() !== null && $entity->getFile()->isFile()) {
         $entity->setOwner($this->securityFacadeLink->getService()->getLoggedUser());
         $file = $entity->getFile();
         if ($entity->getFilename() !== null && $this->filesystem->has($entity->getFilename())) {
             $this->filesystem->delete($entity->getFilename());
         }
         $entity->setExtension($file->guessExtension());
         if ($file instanceof UploadedFile) {
             $entity->setOriginalFilename($file->getClientOriginalName());
             $entity->setMimeType($file->getClientMimeType());
             $entity->setFileSize($file->getClientSize());
         } else {
             $entity->setOriginalFilename($file->getFileName());
             $entity->setMimeType($file->getMimeType());
             $entity->setFileSize($file->getSize());
         }
         $entity->setFilename(uniqid() . '.' . $entity->getExtension());
         if ($this->filesystem->getAdapter() instanceof MetadataSupporter) {
             $this->filesystem->getAdapter()->setMetadata($entity->getFilename(), ['contentType' => $entity->getMimeType()]);
         }
     }
 }
コード例 #2
0
 /**
  * delete the given file
  *
  * @param string $file
  */
 public function deleteFile($file)
 {
     if (!$this->filesystem->has($file)) {
         return;
     }
     $this->filesystem->delete($file);
     $this->cacheManager->remove($file);
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function clearCache($maxAge)
 {
     $delTime = time() - (int) $maxAge;
     $num = 0;
     foreach ($this->temporaryFilesystem->keys() as $key) {
         if (!$this->temporaryFilesystem->getAdapter()->isDirectory($key)) {
             if ($delTime > $this->temporaryFilesystem->mtime($key)) {
                 $this->temporaryFilesystem->delete($key);
                 $num++;
             }
         }
     }
     return $num;
 }
コード例 #4
0
 /**
  * @test
  * @group functional
  */
 public function shouldDeleteFile()
 {
     $this->filesystem->write('foo', 'Some content');
     $this->assertTrue($this->filesystem->has('foo'));
     $this->filesystem->delete('foo');
     $this->assertFalse($this->filesystem->has('foo'));
 }
コード例 #5
0
 /**
  * @test
  * @group functional
  */
 public function shouldWorkWithHiddenFiles()
 {
     $this->filesystem->write('.foo', 'hidden');
     $this->assertTrue($this->filesystem->has('.foo'));
     $this->assertContains('.foo', $this->filesystem->keys());
     $this->filesystem->delete('.foo');
     $this->assertFalse($this->filesystem->has('.foo'));
 }
コード例 #6
0
 /**
  * @test
  * @group functional
  */
 public function shouldWrtieToSameFile()
 {
     $FileObjectA = $this->filesystem->createFile('somefile');
     $FileObjectA->setContent('ABC');
     $FileObjectB = $this->filesystem->createFile('somefile');
     $FileObjectB->setContent('DEF');
     $this->assertEquals('DEF', $FileObjectB->getContent());
     $this->filesystem->delete('somefile');
 }
コード例 #7
0
 /**
  * Delete a file
  * @param AbstractProductMedia $media
  */
 protected function delete(AbstractProductMedia $media)
 {
     if ($media->getFilename() !== "" && $this->fileExists($media)) {
         $this->filesystem->delete($media->getFilename());
     }
     $media->setOriginalFilename(null);
     $media->setFilename(null);
     $media->setFilepath(null);
     $media->setMimeType(null);
 }
コード例 #8
0
 public function cleanup(UserProfile $prop)
 {
     if ($prop->getProperty()->getFieldType() === ProfileProperty::TYPE_FILE) {
         /*$fileName = str_replace($this->getBaseFileUrl() . '/', '', $prop->getPropertyValue());
           if ( is_file($this->getBaseFilePath() . '/' . $fileName) ) {
               echo 'maybe removing ' . $this->getBaseFilePath() . '/' . $fileName;
               @unlink($this->getBaseFilePath() . '/' . $fileName);
           }*/
         $fileKey = AbstractUploader::extractKey($prop->getPropertyValue(), $this->awsBucket);
         if ($fileKey && $this->filesystem->has($fileKey)) {
             $this->filesystem->delete($fileKey);
         }
     }
 }
コード例 #9
0
ファイル: ImageManager.php プロジェクト: bravo3/image-manager
 /**
  * Delete an image from the remote.
  *
  * @param Image $image
  *
  * @return $this
  */
 public function remove(Image $image)
 {
     $this->filesystem->delete($image->getKey());
     $this->untag($image->getKey());
     return $this;
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function remove($path)
 {
     return $this->filesystem->delete($path);
 }
コード例 #11
0
 /**
  * Deletes an image.
  *
  * @param string $imagePath
  *
  * @return boolean
  */
 public function deleteImage($imagePath)
 {
     return $this->files->delete($imagePath);
 }
コード例 #12
0
ファイル: Gaufrette.php プロジェクト: radnan/rdn-upload
 public function delete($id)
 {
     $this->assertHasObject($id);
     $this->filesystem->delete($id);
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 public function remove($path)
 {
     $path = $this->stripLeadingSlash($path);
     if (!$this->getAdapter()->isDirectory($path)) {
         parent::delete($path);
         return;
     }
     $keys = $this->listKeys($path);
     foreach ($keys['keys'] as $tmp) {
         parent::delete($tmp);
     }
     // sort array according after directory depth (DESC)
     $directories = array_unique($keys['dirs']);
     usort($directories, function ($left, $right) {
         $depthLeft = substr_count($left, '/');
         $depthRight = substr_count($right, '/');
         if ($depthLeft == $depthRight) {
             return 0;
         } else {
             return $depthLeft > $depthRight ? -1 : +1;
         }
     });
     foreach ($directories as $tmp) {
         parent::delete($tmp);
     }
     if ($path != '' && $this->exists($path)) {
         parent::delete($path);
     }
 }
コード例 #14
0
ファイル: MediaUploader.php プロジェクト: dasklney/kreta
 /**
  * {@inheritdoc}
  */
 public function remove($name)
 {
     return $this->filesystem->delete($name);
 }
コード例 #15
0
ファイル: MediaUploaderSpec.php プロジェクト: cespedosa/kreta
 function it_does_not_remove(Filesystem $filesystem)
 {
     $filesystem->delete('media-name')->shouldBeCalled()->willReturn(false);
     $this->remove('media-name')->shouldReturn(false);
 }
コード例 #16
0
 /**
  * @param \Gaufrette\Filesystem $filesystem
  */
 function it_deletes_file_from_filesystem($filesystem)
 {
     $filesystem->delete('filename')->shouldBeCalled()->willReturn(true);
     $this->delete()->shouldReturn(true);
 }
コード例 #17
0
 /**
  * @When I delete file :key
  */
 public function iDeleteFile($key)
 {
     $this->filesystem->delete($key);
 }