Skip to content

Commit

Permalink
Merged branch '1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Nov 19, 2020
2 parents 637bc97 + 2bd637e commit 976e52a
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 7 additions & 1 deletion eZ/Publish/Core/FieldType/FieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
}
10 changes: 10 additions & 0 deletions eZ/Publish/Core/FieldType/Image/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
23 changes: 23 additions & 0 deletions eZ/Publish/Core/FieldType/Tests/FieldTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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.'
);
}
}
35 changes: 35 additions & 0 deletions eZ/Publish/Core/FieldType/Tests/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
),
],
];
}
}
26 changes: 25 additions & 1 deletion eZ/Publish/Core/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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.
*
Expand Down
14 changes: 14 additions & 0 deletions eZ/Publish/SPI/FieldType/Comparable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace eZ\Publish\SPI\FieldType;

interface Comparable
{
public function valuesEqual(Value $value1, Value $value2): bool;
}

0 comments on commit 976e52a

Please sign in to comment.