From 1f4cb2a203411cf02022b11fd79e435f1a7687dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20R?= <289757+andrerom@users.noreply.github.com> Date: Fri, 13 Nov 2020 17:18:04 +0100 Subject: [PATCH 1/2] [CS] Update PHP-CS-Fixer to 2.15.9 in order to support Composer v2 (#3079) * [CS] Update PHP-CS-Fixer to 2.15.9 in order to support Composer v2 Closes #3075 * Force composer root version with solr to make sure to install latests version Workaround for 1.13 branch, AFAIK not to be ported to newer branches. --- .php_cs | 6 ++++++ .travis.yml | 2 +- composer.json | 2 +- .../EventListener/IndexRequestListener.php | 1 - .../FileLister/FileIterator/LegacyStorageFileIterator.php | 2 +- eZ/Bundle/EzPublishRestBundle/Tests/Functional/RoleTest.php | 1 - eZ/Publish/Core/FieldType/Image/ImageStorage.php | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.php_cs b/.php_cs index b3d4aad67c..7918a92273 100644 --- a/.php_cs +++ b/.php_cs @@ -26,6 +26,12 @@ return PhpCsFixer\Config::create() 'php_unit_construct' => false, 'standardize_increment' => false, 'fopen_flags' => false, + // Rules changed between php-cs-fixer 2.15.3 and 2.15.9 that we don't care to adapt 6.13 for at this point due to conflicts + 'no_superfluous_phpdoc_tags' => false, + 'ordered_imports' => false, + 'phpdoc_trim' => false, + 'phpdoc_trim_consecutive_blank_line_separation' => false, + 'function_to_constant' => false, ]) ->setRiskyAllowed(true) ->setFinder( diff --git a/.travis.yml b/.travis.yml index d101f78c41..f8846bdb0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ matrix: env: TEST_CONFIG="phpunit-integration-legacy.xml" DB="postgresql" DATABASE="pgsql://postgres@localhost/testdb" # 7.0 - php: 7.0 - env: SOLR_VERSION="6.4.2" TEST_CONFIG="phpunit-integration-legacy-solr.xml" CUSTOM_CACHE_POOL="singleredis" CORES_SETUP="shared" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml" + env: COMPOSER_ROOT_VERSION=6.13.x-dev SOLR_VERSION="6.4.2" TEST_CONFIG="phpunit-integration-legacy-solr.xml" CUSTOM_CACHE_POOL="singleredis" CORES_SETUP="shared" SOLR_CONFIG="vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/schema.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/custom-fields-types.xml vendor/ezsystems/ezplatform-solr-search-engine/lib/Resources/config/solr/language-fieldtypes.xml" # 7.1 - php: 7.1 env: PHP_IMAGE=ezsystems/php:7.1-v1 BEHAT_OPTS="--profile=core --tags=~@broken" RUN_INSTALL=1 SYMFONY_ENV=behat SYMFONY_DEBUG=1 COMPOSER_MEMORY_LIMIT=-1 diff --git a/composer.json b/composer.json index 40a641bd1b..fe65e4d0ca 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "twig/twig": "~1.35|~2.4" }, "require-dev": { - "friendsofphp/php-cs-fixer": "2.15.3", + "friendsofphp/php-cs-fixer": "2.15.9", "phpunit/phpunit": "^5.7", "matthiasnoback/symfony-dependency-injection-test": "~1.0", "symfony/assetic-bundle": "~2.8.2", diff --git a/eZ/Bundle/EzPublishCoreBundle/EventListener/IndexRequestListener.php b/eZ/Bundle/EzPublishCoreBundle/EventListener/IndexRequestListener.php index a33271a59c..b2592ae92a 100644 --- a/eZ/Bundle/EzPublishCoreBundle/EventListener/IndexRequestListener.php +++ b/eZ/Bundle/EzPublishCoreBundle/EventListener/IndexRequestListener.php @@ -13,7 +13,6 @@ use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\HttpFoundation\Request; class IndexRequestListener implements EventSubscriberInterface { diff --git a/eZ/Bundle/EzPublishIOBundle/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php b/eZ/Bundle/EzPublishIOBundle/Migration/FileLister/FileIterator/LegacyStorageFileIterator.php index 484774f58a..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 $statement. */ + /** @var int Iteration cursor on statement. */ private $cursor; /** @var \eZ\Bundle\EzPublishIOBundle\Migration\FileLister\FileRowReaderInterface Used to get file rows. */ diff --git a/eZ/Bundle/EzPublishRestBundle/Tests/Functional/RoleTest.php b/eZ/Bundle/EzPublishRestBundle/Tests/Functional/RoleTest.php index d2f4329b11..7293776427 100644 --- a/eZ/Bundle/EzPublishRestBundle/Tests/Functional/RoleTest.php +++ b/eZ/Bundle/EzPublishRestBundle/Tests/Functional/RoleTest.php @@ -9,7 +9,6 @@ namespace eZ\Bundle\EzPublishRestBundle\Tests\Functional; use eZ\Bundle\EzPublishRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase; -use eZ\Publish\API\Repository\Values\User\Limitation; class RoleTest extends RESTFunctionalTestCase { diff --git a/eZ/Publish/Core/FieldType/Image/ImageStorage.php b/eZ/Publish/Core/FieldType/Image/ImageStorage.php index e67ad37222..8870007f68 100644 --- a/eZ/Publish/Core/FieldType/Image/ImageStorage.php +++ b/eZ/Publish/Core/FieldType/Image/ImageStorage.php @@ -37,7 +37,7 @@ class ImageStorage extends GatewayBasedStorage /** @var \eZ\Publish\Core\FieldType\Image\AliasCleanerInterface */ protected $aliasCleaner; - /** @var \eZ\Publish\Core\FieldType\Image\ImageStorage\Gateway $gateway */ + /** @var \eZ\Publish\Core\FieldType\Image\ImageStorage\Gateway */ protected $gateway; public function __construct( From 4b6717c4500362d3b5a3fa2cb6e359414113a366 Mon Sep 17 00:00:00 2001 From: mateuszdebinski <58430570+mateuszdebinski@users.noreply.github.com> Date: Wed, 18 Nov 2020 14:35:34 +0100 Subject: [PATCH 2/2] EZP-31681: Fixed Image Value comparison via FT Comparable contract (#3060) --- eZ/Publish/Core/FieldType/FieldType.php | 8 ++++- eZ/Publish/Core/FieldType/Image/Type.php | 10 ++++++ .../Core/FieldType/Tests/FieldTypeTest.php | 22 ++++++++++++ eZ/Publish/Core/FieldType/Tests/ImageTest.php | 35 +++++++++++++++++++ eZ/Publish/Core/Repository/ContentService.php | 26 +++++++++++++- eZ/Publish/SPI/FieldType/Comparable.php | 14 ++++++++ 6 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 eZ/Publish/SPI/FieldType/Comparable.php diff --git a/eZ/Publish/Core/FieldType/FieldType.php b/eZ/Publish/Core/FieldType/FieldType.php index db89120b75..bba5f14828 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 FieldTypeInterface; 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 implements FieldTypeInterface +abstract class FieldType implements FieldTypeInterface, 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 c67bf66d3c..c053ecba0c 100644 --- a/eZ/Publish/Core/FieldType/Image/Type.php +++ b/eZ/Publish/Core/FieldType/Image/Type.php @@ -365,4 +365,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 efc31ea485..c910696576 100644 --- a/eZ/Publish/Core/FieldType/Tests/FieldTypeTest.php +++ b/eZ/Publish/Core/FieldType/Tests/FieldTypeTest.php @@ -511,6 +511,11 @@ public function provideInvalidDataForValidate() ]; } + public function provideInputForValuesEqual(): array + { + return $this->provideInputForFromHash(); + } + /** * Retrieves a test wide cached version of the field type under test. * @@ -974,5 +979,22 @@ protected function doValidate($fieldDefinitionData, $value) return $validationErrors; } + /** + * @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.' + ); + } + // @todo: More test methods … } diff --git a/eZ/Publish/Core/FieldType/Tests/ImageTest.php b/eZ/Publish/Core/FieldType/Tests/ImageTest.php index 547d2051d4..04232d677a 100644 --- a/eZ/Publish/Core/FieldType/Tests/ImageTest.php +++ b/eZ/Publish/Core/FieldType/Tests/ImageTest.php @@ -811,4 +811,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 56beb95b6b..ce55aead1c 100644 --- a/eZ/Publish/Core/Repository/ContentService.php +++ b/eZ/Publish/Core/Repository/ContentService.php @@ -18,6 +18,9 @@ use eZ\Publish\Core\Repository\Values\Content\Content; use eZ\Publish\Core\Repository\Values\Content\Location; use eZ\Publish\API\Repository\Values\Content\Language; +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; @@ -1723,7 +1726,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; } @@ -1743,6 +1747,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 @@ +