コード例 #1
0
 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;
     } 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;
 }
コード例 #2
0
 /**
  * @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;
 }