public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context)
 {
     if ($field->value->externalData === null) {
         // Nothing to store
         return false;
     }
     // no mimeType means we are dealing with an input, local file
     if (!isset($field->value->externalData['mimeType'])) {
         $field->value->externalData['mimeType'] = $this->mimeTypeDetector->getFromPath($field->value->externalData['inputUri']);
     }
     $storedValue = $field->value->externalData;
     // The file referenced in externalData MAY be an existing IOService file which we can use
     if ($storedValue['id'] === null) {
         $createStruct = $this->IOService->newBinaryCreateStructFromLocalFile($storedValue['inputUri']);
         $storagePath = $this->pathGenerator->getStoragePathForField($field, $versionInfo);
         $createStruct->id = $storagePath;
         $binaryFile = $this->IOService->createBinaryFile($createStruct);
         $storedValue['id'] = $binaryFile->id;
         $storedValue['mimeType'] = $createStruct->mimeType;
         $storedValue['uri'] = isset($this->downloadUrlGenerator) ? $this->downloadUrlGenerator->getStoragePathForField($field, $versionInfo) : $binaryFile->uri;
     }
     $field->value->externalData = $storedValue;
     $this->removeOldFile($field->id, $versionInfo->versionNo, $context);
     $this->getGateway($context)->storeFileReference($versionInfo, $field);
 }
 /**
  * Stores image alias in the IO Repository.
  * A temporary file is created to dump the filtered image and is used as basis for creation in the IO Repository.
  *
  * {@inheritDoc}
  */
 public function store(BinaryInterface $binary, $path, $filter)
 {
     $tmpFile = tmpfile();
     fwrite($tmpFile, $binary->getContent());
     $tmpMetadata = stream_get_meta_data($tmpFile);
     $binaryCreateStruct = $this->ioService->newBinaryCreateStructFromLocalFile($tmpMetadata['uri']);
     $binaryCreateStruct->id = $this->getFilePath($path, $filter);
     $this->ioService->createBinaryFile($binaryCreateStruct);
     fclose($tmpFile);
 }
 public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context)
 {
     $contentMetaData = array('fieldId' => $field->id, 'versionNo' => $versionInfo->versionNo, 'languageCode' => $field->languageCode);
     // new image
     if (isset($field->value->externalData)) {
         $targetPath = sprintf('%s/%s', $this->pathGenerator->getStoragePathForField($field->id, $versionInfo->versionNo, $field->languageCode), $field->value->externalData['fileName']);
         if (isset($field->value->externalData['id'])) {
             $binaryFile = $this->IOService->loadBinaryFile($field->value->externalData['id']);
         } else {
             if ($this->IOService->exists($targetPath)) {
                 $binaryFile = $this->IOService->loadBinaryFile($targetPath);
             } else {
                 if (isset($field->value->externalData['inputUri'])) {
                     $localFilePath = $field->value->externalData['inputUri'];
                     unset($field->value->externalData['inputUri']);
                     $binaryFileCreateStruct = $this->IOService->newBinaryCreateStructFromLocalFile($localFilePath);
                     $binaryFileCreateStruct->id = $targetPath;
                     $binaryFile = $this->IOService->createBinaryFile($binaryFileCreateStruct);
                     $imageSize = getimagesize($localFilePath);
                     $field->value->externalData['width'] = $imageSize[0];
                     $field->value->externalData['height'] = $imageSize[1];
                 } else {
                     throw new InvalidArgumentException("inputUri", "No source image could be obtained from the given external data");
                 }
             }
         }
         $field->value->externalData['imageId'] = $versionInfo->contentInfo->id . '-' . $field->id;
         $field->value->externalData['uri'] = $binaryFile->uri;
         $field->value->externalData['id'] = $binaryFile->id;
         $field->value->externalData['mime'] = $this->IOService->getMimeType($binaryFile->id);
         $field->value->data = array_merge($field->value->externalData, $contentMetaData);
         $field->value->externalData = null;
     } else {
         if ($field->value->data === null) {
             // Store empty value only with content meta data
             $field->value->data = $contentMetaData;
             return false;
         }
         $this->IOService->loadBinaryFile($field->value->data['id']);
         $field->value->data = array_merge($field->value->data, $contentMetaData);
         $field->value->externalData = null;
     }
     $this->getGateway($context)->storeImageReference($field->value->data['uri'], $field->id);
     // Data has been updated and needs to be stored!
     return true;
 }
 public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context)
 {
     if ($field->value->externalData === null) {
         $this->deleteFieldData($versionInfo, [$field->id], $context);
         return false;
     }
     if (isset($field->value->externalData['inputUri'])) {
         $field->value->externalData['mimeType'] = $this->mimeTypeDetector->getFromPath($field->value->externalData['inputUri']);
         $createStruct = $this->IOService->newBinaryCreateStructFromLocalFile($field->value->externalData['inputUri']);
         $createStruct->id = $this->pathGenerator->getStoragePathForField($field, $versionInfo);
         $binaryFile = $this->IOService->createBinaryFile($createStruct);
         $field->value->externalData['id'] = $binaryFile->id;
         $field->value->externalData['mimeType'] = $createStruct->mimeType;
         $field->value->externalData['uri'] = isset($this->downloadUrlGenerator) ? $this->downloadUrlGenerator->getStoragePathForField($field, $versionInfo) : $binaryFile->uri;
     }
     $this->removeOldFile($field->id, $versionInfo->versionNo, $context);
     $this->getGateway($context)->storeFileReference($versionInfo, $field);
 }
 /**
  * @see \eZ\Publish\SPI\FieldType\FieldStorage
  */
 public function storeFieldData(VersionInfo $versionInfo, Field $field, array $context)
 {
     /*$storedValue = isset( $field->value->externalData )
       // New image
       ? $field->value->externalData
       // Copied / updated image
       : $field->value->data;*/
     $contentMetaData = array('fieldId' => $field->id, 'versionNo' => $versionInfo->versionNo, 'languageCode' => $field->languageCode);
     // new image
     if (isset($field->value->externalData)) {
         $targetPath = sprintf('%s/%s', $this->pathGenerator->getStoragePathForField($field->id, $versionInfo->versionNo, $field->languageCode), $field->value->externalData['fileName']);
         if ($this->IOService->exists($targetPath)) {
             $binaryFile = $this->IOService->loadBinaryFile($targetPath);
         } else {
             if (isset($field->value->externalData['inputUri'])) {
                 $localFilePath = $field->value->externalData['inputUri'];
                 unset($field->value->externalData['inputUri']);
             } else {
                 $this->deprecationWarner->log("Using the Image\\Value::\$id property to create images is deprecated. Use 'inputUri'");
                 $localFilePath = $field->value->externalData['id'];
             }
             $binaryFileCreateStruct = $this->IOService->newBinaryCreateStructFromLocalFile($localFilePath);
             $binaryFileCreateStruct->id = $targetPath;
             $binaryFile = $this->IOService->createBinaryFile($binaryFileCreateStruct);
         }
         $field->value->externalData['mimeType'] = $binaryFile->mimeType;
         $field->value->externalData['imageId'] = $versionInfo->contentInfo->id . '-' . $field->id;
         $field->value->externalData['uri'] = $binaryFile->uri;
         $field->value->externalData['id'] = ltrim($binaryFile->uri, '/');
         $field->value->data = array_merge($field->value->externalData, $this->IOService->getMetadata($this->imageSizeMetadataHandler, $binaryFile), $contentMetaData);
         $field->value->externalData = null;
     } else {
         if ($field->value->data === null) {
             // Store empty value only with content meta data
             $field->value->data = $contentMetaData;
             return false;
         }
         try {
             $binaryFile = $this->IOService->loadBinaryFile($field->value->data['id']);
             $metadata = $this->IOService->getMetadata($this->imageSizeMetadataHandler, $binaryFile);
         } catch (NotFoundException $e) {
             if (isset($this->logger)) {
                 $this->logger->error("Image with ID {$field->value->data['id']} not found");
             }
             return false;
         }
         $field->value->data = array_merge($field->value->data, $metadata, $contentMetaData);
         $field->value->externalData = null;
     }
     $this->getGateway($context)->storeImageReference($field->value->data['uri'], $field->id);
     // Data has been updated and needs to be stored!
     return true;
 }
 public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct)
 {
     return $this->publishedIOService->createBinaryFile($binaryFileCreateStruct);
 }
    /**
     * @see \eZ\Publish\SPI\FieldType\FieldStorage
     */
    public function storeFieldData( VersionInfo $versionInfo, Field $field, array $context )
    {
        $contentMetaData = array(
            'fieldId' => $field->id,
            'versionNo' => $versionInfo->versionNo,
            'languageCode' => $field->languageCode,
        );

        // new image
        if ( isset( $field->value->externalData ) )
        {
            $targetPath = sprintf(
                '%s/%s',
                $this->pathGenerator->getStoragePathForField(
                    $field->id,
                    $versionInfo->versionNo,
                    $field->languageCode
                ),
                $field->value->externalData['fileName']
            );

            if ( $this->IOService->exists( $targetPath ) )
            {
                $binaryFile = $this->IOService->loadBinaryFile( $targetPath );
            }
            else
            {
                if ( isset( $field->value->externalData['inputUri'] ) )
                {
                    $localFilePath = $field->value->externalData['inputUri'];
                    unset( $field->value->externalData['inputUri'] );
                }
                else
                {
                    $this->deprecationWarner->log(
                        "Using the Image\\Value::\$id property to create images is deprecated. Use 'inputUri'"
                    );
                    $localFilePath = $field->value->externalData['id'];
                }
                $binaryFileCreateStruct = $this->IOService->newBinaryCreateStructFromLocalFile( $localFilePath );
                $binaryFileCreateStruct->id = $targetPath;
                $binaryFile = $this->IOService->createBinaryFile( $binaryFileCreateStruct );

                $imageSize = getimagesize( $localFilePath );
                $field->value->externalData['width'] = $imageSize[0];
                $field->value->externalData['height'] = $imageSize[1];
            }
            $field->value->externalData['imageId'] = $versionInfo->contentInfo->id . '-' . $field->id;
            $field->value->externalData['uri'] = $binaryFile->uri;
            $field->value->externalData['id'] = $binaryFile->id;
            $field->value->externalData['mime'] = $this->IOService->getMimeType( $binaryFile->id );

            $field->value->data = array_merge(
                $field->value->externalData,
                $contentMetaData
            );

            $field->value->externalData = null;
        }
        // existing image from another version
        else
        {
            if ( $field->value->data === null )
            {
                // Store empty value only with content meta data
                $field->value->data = $contentMetaData;
                return false;
            }

            $this->IOService->loadBinaryFile( $field->value->data['id'] );

            $field->value->data = array_merge(
                $field->value->data,
                $contentMetaData
            );
            $field->value->externalData = null;
        }

        $this->getGateway( $context )->storeImageReference( $field->value->data['uri'], $field->id );

        // Data has been updated and needs to be stored!
        return true;
    }