/** * Remove file or a directory * * @param $path * @return void */ public function remove($path) { if (!$this->filesystem->has($path)) { return; } $meta = $this->filesystem->getMetadata($path); if ($meta['type'] === 'file') { $this->filesystem->delete($path); } else { $this->filesystem->deleteDir($path); } }
/** * Removes a value from the cache. * * @param string $key A unique key * * @return bool True on success, false on failure. */ public function remove($key) { try { return $this->filesystem->delete($key); } catch (FileNotFoundException $exception) { return false; } }
protected function write($data) { $destination = $this->composer->getClassPath($this->data['name']); if ($this->force && $this->external->has($destination)) { $this->external->delete($destination); } return $this->external->write($destination, $data); }
/** * {@inheritdoc} */ public function remove(File $file) : bool { $key = $file->getKey(); if ($this->filesystem->has($key)) { return $this->filesystem->delete($key); } return true; }
function it_should_execute_the_delete_old_files_command(Filesystem $filesystem, DateTime $olderThan) { $filesystem->listWith(['timestamp'], '/dir', false)->willReturn([['path' => '/dir/file-new.gz', 'timestamp' => 2000], ['path' => '/dir/file-old.gz', 'timestamp' => 1000], ['path' => '/dir/file-older.gz', 'timestamp' => 500]]); $olderThan->getTimestamp()->willReturn(1500); $filesystem->delete('/dir/file-older.gz')->shouldBeCalled(); $filesystem->delete('/dir/file-old.gz')->shouldBeCalled(); $this->beConstructedWith($filesystem, '/dir', $olderThan); $this->execute(); }
/** * @return bool */ public function execute() { $files = $this->filesystem->listWith(['timestamp'], $this->directoryPath, false); foreach ($files as $file) { if ($file['timestamp'] < $this->olderThan->getTimestamp()) { $this->filesystem->delete($file['path']); } } }
/** * @param File $file * @param Version $version * @param VersionProvider $versionProvider * @param Linker $linker * @return bool */ public function unpublish(File $file, Version $version, VersionProvider $versionProvider, Linker $linker) { $path = $linker->getLink($file, $version, $versionProvider->getExtension($file, $version)); if (!$this->filesystem->has($path)) { return false; } $this->filesystem->delete($path); return true; }
/** * {@inheritdoc} */ public function unlink($path) { if ($this->is_dir($path)) { return $this->rmdir($path); } try { return $this->flysystem->delete($this->buildPath($path)); } catch (FileNotFoundException $e) { return false; } }
/** * @return bool */ public function execute() { if ($this->filesystem->getMimetype($this->filePath) == 'application/x-gzip') { if ($this->filesystem->getMimetype(str_replace('.tar.gz', '', $this->filePath)) == 'directory') { $this->filesystem->deleteDir(str_replace('.tar.gz', '', $this->filePath)); } } if ($this->filesystem->getMimetype($this->filePath) == 'directory') { return $this->filesystem->deleteDir($this->filePath); } else { return $this->filesystem->delete($this->filePath); } }
protected function handleField(Request $request, $item, array $fields, $groupName, $fieldName) { $modelFolder = $this->slug . DIRECTORY_SEPARATOR; $basePath = base_path(DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . config('anavel-crud.uploads_path')); $modelPath = $basePath . $modelFolder; $skip = null; $requestValue = null; if (!empty($fields["{$fieldName}__delete"])) { //We never want to save this field, it doesn't exist in the DB $skip = "{$fieldName}__delete"; //If user wants to delete the existing file if (!empty($request->input("{$groupName}.{$fieldName}__delete"))) { $adapter = new Local($basePath); $filesystem = new Filesystem($adapter); if ($filesystem->has($item->{$fieldName})) { $filesystem->delete($item->{$fieldName}); } $item->setAttribute($fieldName, null); return ['skip' => $skip]; } } if ($request->hasFile($groupName . '.' . $fieldName)) { $fileName = uniqid() . '.' . $request->file($groupName . '.' . $fieldName)->getClientOriginalExtension(); $request->file($groupName . '.' . $fieldName)->move($modelPath, $fileName); $requestValue = $modelFolder . $fileName; } elseif (!empty($request->file($groupName . '.' . $fieldName)) && !$request->file($groupName . '.' . $fieldName)->isValid()) { throw new \Exception($request->file($groupName . '.' . $fieldName)->getErrorMessage()); } return ['requestValue' => $requestValue, 'skip' => $skip]; }
public function generate() { if (PHP_SAPI != 'cli') { throw new \Exception("This script only can be used in CLI"); } $config = $this->config->get('database'); system(sprintf('/usr/bin/mysqldump -u %s -h %s -p%s -r /tmp/phosphorum.sql %s', $config->username, $config->host, $config->password, $config->dbname)); system('bzip2 -f /tmp/phosphorum.sql'); $config = $this->config->get('dropbox'); if (!$config instanceof Config) { throw new \Exception("Unable to retrieve Dropbox credentials. Please check Forum Configuration"); } if (!$config->get('appSecret') || !$config->get('accessToken')) { throw new \Exception("Please provide correct 'appSecret' and 'accessToken' config values"); } $sourcePath = '/tmp/phosphorum.sql.bz2'; if (!file_exists($sourcePath)) { throw new \Exception("Backup could not be created"); } $client = new Client($config->get('accessToken'), $config->get('appSecret')); $adapter = new DropboxAdapter($client, $config->get('prefix', null)); $filesystem = new Filesystem($adapter); $dropboxPath = '/phosphorum.sql.bz2'; if ($filesystem->has($dropboxPath)) { $filesystem->delete($dropboxPath); } $fp = fopen($sourcePath, "rb"); $filesystem->putStream($dropboxPath, $fp); fclose($fp); @unlink($sourcePath); }
/** * Get cached string from store. * * @param string $key * * @return null|string */ public function get($key) { if (!is_string($key)) { return; } try { $file = $this->get_file_name($key); // Expire the file if the expires time is not zero. if ($this->args['expires'] > 0) { $time = $this->filesystem->getTimestamp($file); // If time is bigger than expires and file timestamp // the file should be deleted and null should be returned // since the cache has expired. if (time() > $this->args['expires'] * $time) { $this->filesystem->delete($file); return; } } // Try to read the file. $content = $this->filesystem->read($file); // Delete the file if empty. if (empty($content)) { $this->filesystem->delete($file); } return $content; } catch (FileNotFoundException $e) { return; } }
public function deleteVersion(Versionable $versionable, Version $version) { $ret = $this->filesystem->delete($this->getVersionPathName($versionable, $version)); if (!$ret) { throw new FileIOException(sprintf("Failed to delete version '%s' of versionable %s;%s", $version->toString(), get_class($versionable), $versionable->getId())); } }
/** * Cleanup output files after each test */ public function tearDown() { $cleanup = ['sprite.jpg', 'sprite.vtt', 'blubber.jpg', 'blubber.vtt']; foreach ($cleanup as $file) { $this->outputFS->has($file) && $this->outputFS->delete($file); } }
/** * Process give source file with given options * * @param array $options * @param $sourceFile * @return string */ public function process($options, $sourceFile) { //check restricted_domains is enabled if ($this->params['restricted_domains'] && is_array($this->params['whitelist_domains']) && !in_array(parse_url($sourceFile, PHP_URL_HOST), $this->params['whitelist_domains'])) { throw new \Exception('Restricted domains enabled, the domain your fetching from is not allowed: ' . parse_url($sourceFile, PHP_URL_HOST)); } $options = $this->parseOptions($options); $newFileName = md5(implode('.', $options) . $sourceFile); if ($this->filesystem->has($newFileName) && $options['refresh']) { $this->filesystem->delete($newFileName); } if (!$this->filesystem->has($newFileName)) { $this->saveNewFile($sourceFile, $newFileName, $options); } return $this->filesystem->read($newFileName); }
/** * Delete a file. * * @param string $path * * @throws FileNotFoundException * * @return bool True on success, false on failure. */ public function delete($path) { try { return $this->filesystem->delete($path); } catch (FlysystemFileNotFoundException $e) { FileNotFoundException::fileNotExists(); } }
/** * Remove a file from oc * @param string $path * * @return bool */ public function removeFile($path = '') { try { return $this->fs->delete($path); } catch (FileNotFoundException $e) { return false; } }
/** * Create skip file to lessons */ public function writeSkipSeries() { $file = SERIES_FOLDER . '/.skip'; $series = serialize($this->getSeries()); if ($this->system->has($file)) { $this->system->delete($file); } $this->system->write($file, $series); }
/** * Release the lock for a given key. * * @param string $key * * @return bool */ protected function unlock($key) { $path = $key . '.lock'; try { $this->filesystem->delete($path); } catch (FileNotFoundException $e) { return false; } return true; }
/** * @param $sourceFile * @param $repoFile * * @return bool * */ public function moveToRepo($sourceFile, $repoFile) { $filesystem = new Filesystem(new Adapter('/')); if ($filesystem->has($repoFile)) { $filesystem->delete($repoFile); } $result = $filesystem->rename($sourceFile, $repoFile); unset($filesystem); return $result; }
/** * @param array $fileList */ public function delete(array $fileList) { foreach ($fileList as $file) { $this->logger->notice('Deleting ' . $file . ' in s3 bucket ' . $this->filesystem->getAdapter()->getBucket()); try { $this->filesystem->delete($file); } catch (\Exception $e) { $this->logger->error('Exception while deleting ' . $file . ': ' . $e->getMessage()); } } }
/** * {@inheritdoc} */ protected function delete(ServerRequestInterface $request) { $this->assertAdmin($request->getAttribute('actor')); $path = $this->settings->get('favicon_path'); $this->settings->set('favicon_path', null); $uploadDir = new Filesystem(new Local($this->app->publicPath() . '/assets')); if ($uploadDir->has($path)) { $uploadDir->delete($path); } return new EmptyResponse(204); }
/** * @param string $providerPrefix * * @return bool */ public function invalidate($providerPrefix) { $pattern = $this->prefix . strtolower($providerPrefix) . '_'; $files = $this->filesystem->listContents(); foreach ($files as $file) { if (stripos($file['filename'], $pattern) === 0) { $this->filesystem->delete($file['filename']); } } return true; }
/** * @inheritdoc */ public function delete($path) { try { $innerPath = $this->getInnerPath($path); } catch (FileNotFoundException $e) { throw $this->exceptionWrapper($e, $path); } $return = $this->fileSystem->delete($innerPath); if ($return !== false) { $this->invokePlugin("removePathFromIndex", [$path, $innerPath], $this); } return $return; }
public function testLargeSitemapCreatesIndex() { $urls = []; for ($i = 1; $i <= 50002; $i++) { $urls[] = ['url' => 'http://foo.com/' . $i]; } $path = $this->factory->createSitemap(new ArrayIterator($urls)); $this->assertTrue($this->filesystem->has($path)); foreach ($this->factory->getFilesCreated() as $file) { $this->assertTrue($this->filesystem->has($file)); $this->filesystem->delete($file); } }
/** * Handle the command * * @param $command * @return mixed */ public function handle($command) { $client = S3Client::factory(array('key' => $this->config->get('services.s3.key'), 'secret' => $this->config->get('services.s3.secret'))); /* * Delete image from S3 */ $filesystem = new Flysystem(new Adapter($client, $this->config->get('sightseeing.s3-bucket'))); $image = $this->sightRepository->getImageById($command->imageId); $filesystem->delete($image->path); /* * Delete DB record */ $this->sightRepository->deleteImageById($command->imageId); }
private function handleOptions() { if ($this->delete) { $this->getItemsToDelete()->each(function ($item) { if ($item['type'] === 'dir') { dump($item); $this->filesystem->deleteDir($item['path']); return true; } $this->filesystem->delete($item['path']); return true; }); } }
/** * @param Request $request * @param Model $item * @param array $fields * @param $groupName * @param $fieldName * @param bool $mustDeleteFilesInFilesystem * * @throws \Exception * * @return array */ protected function handleField(Request $request, $item, array $fields, $groupName, $fieldName, $mustDeleteFilesInFilesystem = false) { $normalizeGroupName = str_replace('.', '#', $groupName); $contentFromUploadedField = "uploaded-content.{$normalizeGroupName}#{$fieldName}#"; $modelFolder = $this->slug . DIRECTORY_SEPARATOR; $basePath = base_path(DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . config('anavel-crud.uploads_path')); $modelPath = $basePath . $modelFolder; $skip = null; $requestValue = null; if (!empty($fields["{$fieldName}__delete"])) { //We never want to save this field, it doesn't exist in the DB $skip = "{$fieldName}__delete"; //If user wants to delete the existing file if (!empty($request->input("{$groupName}.{$fieldName}__delete"))) { $adapter = new Local($basePath); $filesystem = new Filesystem($adapter); if ($filesystem->has($item->{$fieldName}) && $mustDeleteFilesInFilesystem) { $filesystem->delete($item->{$fieldName}); } $item->setAttribute($fieldName, null); return ['skip' => $skip]; } } if ($request->has($contentFromUploadedField)) { $requestValue = $request->input($contentFromUploadedField); } elseif ($request->hasFile($groupName . '.' . $fieldName)) { $fileName = pathinfo($request->file($groupName . '.' . $fieldName)->getClientOriginalName(), PATHINFO_FILENAME); $extension = pathinfo($request->file($groupName . '.' . $fieldName)->getClientOriginalName(), PATHINFO_EXTENSION); $fileName = uniqid() . '_' . slugify($fileName); if (!empty($extension)) { $fileName .= '.' . $extension; } $request->file($groupName . '.' . $fieldName)->move($modelPath, $fileName); $requestValue = $modelFolder . $fileName; } elseif (!empty($request->file($groupName . '.' . $fieldName)) && !$request->file($groupName . '.' . $fieldName)->isValid()) { throw new \Exception($request->file($groupName . '.' . $fieldName)->getErrorMessage()); } //Avoid losing the existing filename if the user doesn't change it: if (empty($requestValue) && !empty($item->{$fieldName})) { $requestValue = $item->{$fieldName}; } return ['requestValue' => $requestValue, 'skip' => $skip]; }
/** * @param string[] $paths The paths where the original files are expected to be. * @param string[] $filters The imagine filters in effect. */ public function remove(array $paths, array $filters) { if (empty($paths) && empty($filters)) { return; } if (empty($paths)) { foreach ($filters as $filter) { $filterCacheDir = $this->cacheRoot . '/' . $filter; $this->flysystem->deleteDir($filterCacheDir); } return; } foreach ($paths as $path) { foreach ($filters as $filter) { if ($this->flysystem->has($this->getFilePath($path, $filter))) { $this->flysystem->delete($this->getFilePath($path, $filter)); } } } }
/** * Renders the specified templates. * * @param \League\Flysystem\Filesystem $filesystem * @param \Twig_Environment $renderer * @param array $templates * @param array $data * @return void */ public static function render(Filesystem $filesystem, \Twig_Environment $renderer, array $templates = [], array $data = []) { $slash = DIRECTORY_SEPARATOR; foreach ($templates as $template) { $sourceFile = str_replace($data['directory'] . $slash, '', $template); if ($filesystem->has($sourceFile)) { $filesystem->delete($sourceFile); } if (strpos($sourceFile, '.twig') === false) { $contents = $renderer->render('Application' . $slash . $sourceFile, $data); } else { $contents = file_get_contents($data['directory'] . $slash . $sourceFile); $contents = str_replace('{application}', $data['application']->name, $contents); } if (strpos($sourceFile, '.file') !== false) { $sourceFile = str_replace('.file', '', $sourceFile); } $filesystem->write($sourceFile, $contents); } }