/** * 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()]); } } }
/** * 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); }
/** * {@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; }
/** * @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')); }
/** * @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')); }
/** * @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'); }
/** * 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); }
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); } } }
/** * 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; }
/** * {@inheritdoc} */ public function remove($path) { return $this->filesystem->delete($path); }
/** * Deletes an image. * * @param string $imagePath * * @return boolean */ public function deleteImage($imagePath) { return $this->files->delete($imagePath); }
public function delete($id) { $this->assertHasObject($id); $this->filesystem->delete($id); }
/** * {@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); } }
/** * {@inheritdoc} */ public function remove($name) { return $this->filesystem->delete($name); }
function it_does_not_remove(Filesystem $filesystem) { $filesystem->delete('media-name')->shouldBeCalled()->willReturn(false); $this->remove('media-name')->shouldReturn(false); }
/** * @param \Gaufrette\Filesystem $filesystem */ function it_deletes_file_from_filesystem($filesystem) { $filesystem->delete('filename')->shouldBeCalled()->willReturn(true); $this->delete()->shouldReturn(true); }
/** * @When I delete file :key */ public function iDeleteFile($key) { $this->filesystem->delete($key); }