コード例 #1
1
ファイル: FlySystemAdapter.php プロジェクト: karion/mydrinks
 /**
  * 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);
     }
 }
コード例 #2
0
ファイル: FlySystemStorage.php プロジェクト: svycka/sv-images
 /**
  * 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;
     }
 }
コード例 #3
0
ファイル: BaseGenerator.php プロジェクト: clarkeash/machine
 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);
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function remove(File $file) : bool
 {
     $key = $file->getKey();
     if ($this->filesystem->has($key)) {
         return $this->filesystem->delete($key);
     }
     return true;
 }
コード例 #5
0
 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();
 }
コード例 #6
0
 /**
  * @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']);
         }
     }
 }
コード例 #7
0
 /**
  * @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;
 }
コード例 #8
0
ファイル: flysystem.php プロジェクト: ninjasilicon/core
	/**
	 * {@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;
		}
	}
コード例 #9
0
 /**
  * @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);
     }
 }
コード例 #10
0
ファイル: HandleFiles.php プロジェクト: ablunier/crud
 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];
 }
コード例 #11
0
ファイル: Backup.php プロジェクト: phalcon/forum
 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);
 }
コード例 #12
0
 /**
  * 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;
     }
 }
コード例 #13
0
 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()));
     }
 }
コード例 #14
0
 /**
  * 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);
     }
 }
コード例 #15
0
ファイル: ImageManager.php プロジェクト: sadok-f/fly-image
 /**
  * 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);
 }
コード例 #16
0
ファイル: Local.php プロジェクト: da-vinci-studio/file-bundle
 /**
  * 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();
     }
 }
コード例 #17
0
 /**
  * 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;
     }
 }
コード例 #18
0
 /**
  * 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);
 }
コード例 #19
0
 /**
  * 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;
 }
コード例 #20
0
 /**
  * @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;
 }
コード例 #21
0
 /**
  * @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());
         }
     }
 }
コード例 #22
0
 /**
  * {@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);
 }
コード例 #23
0
 /**
  * @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;
 }
コード例 #24
0
 /**
  * @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;
 }
コード例 #25
0
 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);
     }
 }
コード例 #26
0
 /**
  * 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);
 }
コード例 #27
0
 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;
         });
     }
 }
コード例 #28
0
ファイル: HandleFiles.php プロジェクト: anavel/crud
 /**
  * @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];
 }
コード例 #29
0
 /**
  * @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));
             }
         }
     }
 }
コード例 #30
0
ファイル: Helpers.php プロジェクト: rougin/weasley
 /**
  * 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);
     }
 }