/** * Copies current file * * @param string $copyOptions defines copy options in case if file already exists * in target directory: * - autorename - renames current file (see File::autorename()) * - overwrite - overwrites existing file * * @return bool true if file was copied successfully * * @throws \Exception */ public function doCopy($copyOptions) { $originalFileStream = $this->getContentsStream(); $originalFileName = $this->getFilename(); // Don't copy file to itself if ($this->targetFolder->getBackend() === $this->resourceType->getBackend() && $this->targetFolder->getPath() === $this->getPath()) { $this->addError(Error::SOURCE_AND_TARGET_PATH_EQUAL); return false; // Check if file already exists in target backend dir } elseif ($this->targetFolder->containsFile($this->getFilename()) && strpos($copyOptions, 'overwrite') === false) { if (strpos($copyOptions, 'autorename') !== false) { $this->autorename(); } else { $this->addError(Error::ALREADY_EXIST); return false; } } if ($this->targetFolder->putStream($this->getFilename(), $originalFileStream)) { $resizedImageRepository = $this->resourceType->getResizedImageRepository(); $resizedImageRepository->copyResizedImages($this->resourceType, $this->folder, $originalFileName, $this->targetFolder->getResourceType(), $this->targetFolder->getClientCurrentFolder(), $this->getFilename()); $this->getCache()->copy(Path::combine($this->resourceType->getName(), $this->folder, $originalFileName), Path::combine($this->targetFolder->getResourceType()->getName(), $this->targetFolder->getClientCurrentFolder(), $this->getFilename())); return true; } else { $this->addError(Error::ACCESS_DENIED); return false; } }
/** * Main command method. * * @param Request $request Current request object * @param WorkingFolder $workingFolder Current working folder object * * @return array * * @throws \Exception */ public function execute(Request $request, WorkingFolder $workingFolder) { $fileName = $request->get('fileName'); $backend = $workingFolder->getBackend(); if (!$workingFolder->containsFile($fileName)) { throw new \Exception('File not found', Error::FILE_NOT_FOUND); } $fileMetadada = $backend->getMetadata(Path::combine($workingFolder->getPath(), $fileName)); return $fileMetadada; }
/** * @copydoc File::autorename() */ public function autorename(Backend $backend = null, $path = '') { return parent::autorename($this->workingFolder->getBackend(), $this->workingFolder->getPath()); }