public function create(BinaryFileCreateStruct $binaryFileCreateStruct)
 {
     try {
         $this->filesystem->writeStream($binaryFileCreateStruct->id, $binaryFileCreateStruct->getInputStream(), array('mimetype' => $binaryFileCreateStruct->mimeType, 'visibility' => AdapterInterface::VISIBILITY_PUBLIC));
     } catch (FileExistsException $e) {
         $this->filesystem->updateStream($binaryFileCreateStruct->id, $binaryFileCreateStruct->getInputStream(), array('mimetype' => $binaryFileCreateStruct->mimeType, 'visibility' => AdapterInterface::VISIBILITY_PUBLIC));
     }
 }
 /**
  * Creates and stores a new BinaryFile based on the BinaryFileCreateStruct $file
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the target path already exists
  *
  * @param BinaryFileCreateStruct $createStruct
  *
  * @return BinaryFile The newly created BinaryFile object
  */
 public function create(BinaryFileCreateStruct $createStruct)
 {
     if (isset($this->storage[$createStruct->id])) {
         throw new InvalidArgumentException("\$createFilestruct->id", "file '{$createStruct->id}' already exists");
     }
     $this->data[$createStruct->id] = base64_encode(fread($createStruct->getInputStream(), $createStruct->size));
     $binaryFile = new BinaryFile();
     $binaryFile->id = $createStruct->id;
     $binaryFile->mtime = new DateTime();
     $binaryFile->size = $createStruct->size;
     return $this->storage[$binaryFile->id] = $binaryFile;
 }
Exemple #3
0
 /**
  * Creates and stores a new BinaryFile based on the BinaryFileCreateStruct $file
  *
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If the target path already exists
  *
  * @param \eZ\Publish\SPI\IO\BinaryFileCreateStruct $createStruct
  *
  * @return \eZ\Publish\SPI\IO\BinaryFile The newly created BinaryFile object
  */
 public function create(BinaryFileCreateStruct $createStruct)
 {
     if ($this->exists($createStruct->id)) {
         throw new InvalidArgumentException("\$createFilestruct->id", "file '" . $this->getStoragePath($createStruct->id) . "' already exists");
     }
     $storagePath = $this->getStoragePath($createStruct->id);
     $scope = $this->getScope($storagePath);
     $clusterHandler = $this->getClusterHandler();
     $this->getLegacyKernel()->runCallback(function () use($createStruct, $storagePath, $scope, $clusterHandler) {
         $clusterHandler->fileStoreContents($storagePath, fread($createStruct->getInputStream(), $createStruct->size), $scope, $createStruct->mimeType);
     }, false, false);
     return $this->load($createStruct->id);
 }
 /**
  * Creates and stores a new BinaryFile based on the BinaryFileCreateStruct $file
  *
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If the target path already exists
  * @throws \RuntimeException If the directory in $createStruct->spiBinaryFileIdi exists but is a file
  *
  * @param \eZ\Publish\SPI\IO\BinaryFileCreateStruct $createStruct
  *
  * @return \eZ\Publish\SPI\IO\BinaryFile The newly created BinaryFile object
  */
 public function create(BinaryFileCreateStruct $createStruct)
 {
     if ($this->exists($createStruct->id)) {
         throw new InvalidArgumentException("\$createFilestruct->id", "file '{$createStruct->id}' already exists");
     }
     $storagePath = $this->getStoragePath($createStruct->id);
     $outputDirectory = dirname($createStruct->id);
     if (file_exists($outputDirectory) && !is_dir($outputDirectory)) {
         throw new RuntimeException("Directory {$outputDirectory} exists but is a file");
     }
     if (!file_exists($outputDirectory)) {
         $this->createFolderStructure($outputDirectory);
     }
     $outputStream = fopen($storagePath, 'wb');
     stream_copy_to_stream($createStruct->getInputStream(), $outputStream);
     return $this->load($createStruct->id);
 }