/**
  * Replaces a file with a local file (e.g. a freshly uploaded file)
  *
  * @param FileInterface $file
  * @param string $localFilePath
  *
  * @return FileInterface
  *
  * @throws Exception\IllegalFileExtensionException
  * @throws \InvalidArgumentException
  */
 public function replaceFile(FileInterface $file, $localFilePath)
 {
     $this->assureFileWritePermissions($file);
     if (!$this->checkFileExtensionPermission($localFilePath)) {
         throw new Exception\IllegalFileExtensionException('Source file extension not allowed.', 1378132239);
     }
     if (!file_exists($localFilePath)) {
         throw new \InvalidArgumentException('File "' . $localFilePath . '" does not exist.', 1325842622);
     }
     $this->emitPreFileReplaceSignal($file, $localFilePath);
     $result = $this->driver->replaceFile($file->getIdentifier(), $localFilePath);
     if ($file instanceof File) {
         $this->getIndexer()->updateIndexEntry($file);
     }
     $this->emitPostFileReplaceSignal($file, $localFilePath);
     return $result;
 }
예제 #2
0
 /**
  * Replaces a file with a local file (e.g. a freshly uploaded file)
  *
  * @param FileInterface $file
  * @param string $localFilePath
  *
  * @return FileInterface
  *
  * @throws Exception\IllegalFileExtensionException
  * @throws \InvalidArgumentException
  */
 public function replaceFile(FileInterface $file, $localFilePath)
 {
     $this->assureFileReplacePermissions($file);
     if (!$this->checkFileExtensionPermission($localFilePath)) {
         throw new Exception\IllegalFileExtensionException('Source file extension not allowed.', 1378132239);
     }
     if (!file_exists($localFilePath)) {
         throw new \InvalidArgumentException('File "' . $localFilePath . '" does not exist.', 1325842622);
     }
     $this->emitPreFileReplaceSignal($file, $localFilePath);
     $this->driver->replaceFile($file->getIdentifier(), $localFilePath);
     if ($file instanceof File) {
         $this->getIndexer()->updateIndexEntry($file);
     }
     if ($this->autoExtractMetadataEnabled()) {
         $indexer = GeneralUtility::makeInstance(Indexer::class, $this);
         $indexer->extractMetaData($file);
     }
     $this->emitPostFileReplaceSignal($file, $localFilePath);
     return $file;
 }