diff --git a/eZ/Bundle/EzPublishIOBundle/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php b/eZ/Bundle/EzPublishIOBundle/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php index c744eb0642..714c04e8ea 100644 --- a/eZ/Bundle/EzPublishIOBundle/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php +++ b/eZ/Bundle/EzPublishIOBundle/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php @@ -19,7 +19,7 @@ final class LegacyStorageFileIterator implements FileIteratorInterface /** @var mixed Last fetched item. */ private $item; - /** @var int Iteration cursor on. */ + /** @var int Iteration cursor on statement. */ private $cursor; /** @var \eZ\Bundle\EzPublishIOBundle\Migration\FileLister\FileRowReaderInterface Used to get file rows. */ diff --git a/eZ/Publish/Core/FieldType/FieldType.php b/eZ/Publish/Core/FieldType/FieldType.php index 01f7169218..9664c4a8cc 100644 --- a/eZ/Publish/Core/FieldType/FieldType.php +++ b/eZ/Publish/Core/FieldType/FieldType.php @@ -6,6 +6,7 @@ */ namespace eZ\Publish\Core\FieldType; +use eZ\Publish\SPI\FieldType\Comparable; use eZ\Publish\SPI\FieldType\FieldType as SPIFieldType; use eZ\Publish\Core\Persistence\TransformationProcessor; use eZ\Publish\SPI\FieldType\Value as SPIValue; @@ -30,7 +31,7 @@ * Field types are primed and pre-configured with the Field Definitions found in * Content Types. */ -abstract class FieldType extends SPIFieldType +abstract class FieldType extends SPIFieldType implements Comparable { /** * The setting keys which are available on this field type. @@ -575,4 +576,9 @@ public function getRelations(SPIValue $fieldValue) { return []; } + + public function valuesEqual(SPIValue $value1, SPIValue $value2): bool + { + return $this->toHash($value1) === $this->toHash($value2); + } } diff --git a/eZ/Publish/Core/FieldType/Image/Type.php b/eZ/Publish/Core/FieldType/Image/Type.php index 81ef80e2e1..7bf2b7b40f 100644 --- a/eZ/Publish/Core/FieldType/Image/Type.php +++ b/eZ/Publish/Core/FieldType/Image/Type.php @@ -358,4 +358,14 @@ public function fromPersistenceValue(FieldValue $fieldValue) return $result; } + + public function valuesEqual(SPIValue $value1, SPIValue $value2): bool + { + $hashValue1 = $this->toHash($value1); + $hashValue2 = $this->toHash($value2); + + unset($hashValue1['imageId'], $hashValue2['imageId']); + + return $hashValue1 === $hashValue2; + } } diff --git a/eZ/Publish/Core/FieldType/Tests/FieldTypeTest.php b/eZ/Publish/Core/FieldType/Tests/FieldTypeTest.php index 5a29814186..6e54b44c49 100644 --- a/eZ/Publish/Core/FieldType/Tests/FieldTypeTest.php +++ b/eZ/Publish/Core/FieldType/Tests/FieldTypeTest.php @@ -8,6 +8,7 @@ use eZ\Publish\SPI\FieldType\Tests\FieldTypeTest as BaseFieldTypeTest; use eZ\Publish\Core\Persistence\TransformationProcessor; +use eZ\Publish\SPI\FieldType\Value as SPIValue; abstract class FieldTypeTest extends BaseFieldTypeTest { @@ -26,4 +27,26 @@ protected function getTransformationProcessorMock() ['transform', 'transformByGroup'] ); } + + public function provideInputForValuesEqual(): array + { + return $this->provideInputForFromHash(); + } + + /** + * @dataProvider provideInputForValuesEqual + * + * @param mixed $inputValue1Hash + */ + public function testValuesEqual($inputValue1Hash, SPIValue $inputValue2): void + { + $fieldType = $this->getFieldTypeUnderTest(); + + $inputValue1 = $fieldType->fromHash($inputValue1Hash); + + self::assertTrue( + $fieldType->valuesEqual($inputValue1, $inputValue2), + 'valuesEqual() method did not create expected result.' + ); + } } diff --git a/eZ/Publish/Core/FieldType/Tests/ImageTest.php b/eZ/Publish/Core/FieldType/Tests/ImageTest.php index 96ef26eaaa..403446f719 100644 --- a/eZ/Publish/Core/FieldType/Tests/ImageTest.php +++ b/eZ/Publish/Core/FieldType/Tests/ImageTest.php @@ -817,4 +817,39 @@ public function provideInvalidDataForValidate() ], ]; } + + /** + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + */ + public function provideInputForValuesEqual(): array + { + return [ + [ + [ + 'id' => $this->getImageInputPath(), + 'fileName' => 'Sindelfingen-Squirrels.jpg', + 'fileSize' => 23, + 'alternativeText' => 'This is so Sindelfingen!', + 'imageId' => '123-12345', + 'uri' => 'http://' . $this->getImageInputPath(), + 'width' => 123, + 'height' => 456, + ], + new ImageValue( + [ + 'id' => $this->getImageInputPath(), + 'path' => $this->getImageInputPath(), + 'fileName' => 'Sindelfingen-Squirrels.jpg', + 'fileSize' => 23, + 'alternativeText' => 'This is so Sindelfingen!', + 'imageId' => '123-12317', + 'uri' => 'http://' . $this->getImageInputPath(), + 'inputUri' => null, + 'width' => 123, + 'height' => 456, + ] + ), + ], + ]; + } } diff --git a/eZ/Publish/Core/Repository/ContentService.php b/eZ/Publish/Core/Repository/ContentService.php index 94991279c6..b978b56f36 100644 --- a/eZ/Publish/Core/Repository/ContentService.php +++ b/eZ/Publish/Core/Repository/ContentService.php @@ -28,6 +28,9 @@ use eZ\Publish\Core\Repository\Values\Content\Location; use eZ\Publish\API\Repository\Values\Content\Language; use eZ\Publish\SPI\Persistence\Filter\Content\Handler as ContentFilteringHandler; +use eZ\Publish\SPI\FieldType\Comparable; +use eZ\Publish\SPI\FieldType\FieldType; +use eZ\Publish\SPI\FieldType\Value; use eZ\Publish\SPI\Persistence\Handler; use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct as APIContentUpdateStruct; use eZ\Publish\API\Repository\Values\ContentType\ContentType; @@ -1535,7 +1538,8 @@ protected function copyTranslationsFromPublishedVersion(APIVersionInfo $versionI if ($newValue !== null && $field->value !== null - && $fieldType->toHash($newValue) === $fieldType->toHash($field->value)) { + && $this->fieldValuesAreEqual($fieldType, $newValue, $field->value) + ) { continue; } @@ -1555,6 +1559,26 @@ protected function copyTranslationsFromPublishedVersion(APIVersionInfo $versionI $this->internalUpdateContent($versionInfo, $updateStruct); } + protected function fieldValuesAreEqual(FieldType $fieldType, Value $value1, Value $value2): bool + { + if ($fieldType instanceof Comparable) { + return $fieldType->valuesEqual($value1, $value2); + } else { + @trigger_error( + \sprintf( + 'In eZ Platform 2.5 and 3.x %s should implement %s. ' . + 'Since the 4.0 major release FieldType\Comparable contract will be a part of %s', + get_class($fieldType), + Comparable::class, + FieldType::class + ), + E_USER_DEPRECATED + ); + + return $fieldType->toHash($value1) === $fieldType->toHash($value2); + } + } + /** * Publishes a content version. * diff --git a/eZ/Publish/SPI/FieldType/Comparable.php b/eZ/Publish/SPI/FieldType/Comparable.php new file mode 100644 index 0000000000..214318a90a --- /dev/null +++ b/eZ/Publish/SPI/FieldType/Comparable.php @@ -0,0 +1,14 @@ +