/**
  * Handle the command.
  *
  * @param FileRepositoryInterface   $files
  * @param FolderRepositoryInterface $folders
  */
 public function handle(FileRepositoryInterface $files, FolderRepositoryInterface $folders)
 {
     $folder = $folders->findBySlug(dirname($this->file->getPath()));
     $file = $files->findByNameAndFolder(basename($this->file->getPath()), $folder);
     if ($file) {
         $files->delete($file);
     }
 }
 /**
  * @param $event \trntv\filekit\events\StorageEvent
  */
 public function afterSave($event)
 {
     $file = new File($event->filesystem, $event->path);
     $model = new FileStorageItem();
     $model->component = $this->component;
     $model->path = $file->getPath();
     $model->base_url = $this->getStorage()->baseUrl;
     $model->size = $file->getSize();
     $model->type = $file->getMimeType();
     $model->name = pathinfo($file->getPath(), PATHINFO_FILENAME);
     if (Yii::$app->request->getIsConsoleRequest() === false) {
         $model->upload_ip = Yii::$app->request->getUserIP();
     }
     $model->save(false);
 }
 /**
  * {@inheritdoc}
  *
  * @param Migrated $versions
  *
  * @return int
  *
  * @throws StorageException
  */
 public function saveCollection(Migrated $versions)
 {
     $ids = array_map(function (VersionInterface $v) {
         return $v->getId();
     }, $versions->toArray());
     $contents = implode("\n", $ids);
     $result = $this->file->put($contents);
     if ($result === false) {
         throw new StorageException(sprintf('Could not write to file "%s".', $this->file->getPath()));
     }
     return (bool) $result;
 }
 /**
  * Sends the file.
  */
 public function sendContent()
 {
     if (!$this->isSuccessful()) {
         parent::sendContent();
         return;
     }
     if (0 === $this->maxlen) {
         return;
     }
     $out = fopen('php://output', 'wb');
     $file = $this->filesystem->readStream($this->file->getPath());
     stream_copy_to_stream($file, $out, $this->maxlen, $this->offset);
     fclose($out);
     fclose($file);
 }
 /**
  * Sync the files folder.
  *
  * @param File          $resource
  * @param DiskInterface $disk
  * @return null|FolderInterface
  */
 protected function syncFolder(File $resource, DiskInterface $disk)
 {
     $path = dirname($resource->getPath());
     if ($path === '.') {
         return null;
     }
     /* @var FolderInterface|null $parent */
     $parent = null;
     $folder = null;
     foreach (explode('/', $path) as $name) {
         if (!($folder = $this->folders->findByName($name, $disk, $parent))) {
             $folder = $this->folders->create(['name' => $name, 'disk_id' => $disk->getId(), 'parent_id' => $parent ? $parent->getId() : null]);
         }
         $parent = $folder;
     }
     return $folder;
 }
 public function __construct(File $file, Filesystem $filesystem, $streamWrapperPrefix = null)
 {
     parent::__construct($filesystem, $file->getPath());
     $this->streamWrapperPrefix = $streamWrapperPrefix;
 }
Exemple #7
0
 /**
  * Backup the YAML file.
  */
 protected function backup()
 {
     $this->file->copy($this->file->getPath() . '.' . date('Ymd-His'));
 }
Exemple #8
0
 /**
  * Gather the 'similar' files, if present.
  *
  * i.e., if we're editing config.yml, we also want to check for
  * config.yml.dist and config_local.yml
  *
  * @param FilesystemInterface $filesystem
  * @param File                $file
  *
  * @return array
  */
 private function getFileGroup(FilesystemInterface $filesystem, File $file)
 {
     $basename = str_replace('.yml', '', str_replace('_local', '', $file->getPath()));
     $filegroup = [];
     if ($filesystem->has($basename . '.yml')) {
         $filegroup[] = basename($basename . '.yml');
     }
     if ($filesystem->has($basename . '_local.yml')) {
         $filegroup[] = basename($basename . '_local.yml');
     }
     return $filegroup;
 }
 public function testFileGetPath()
 {
     $file = new File();
     $file->setPath('path.txt');
     $this->assertEquals('path.txt', $file->getPath());
 }