diff --git a/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md b/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md index e04e5638415..4eefe38ffdf 100644 --- a/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md +++ b/doc/Development_Documentation/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md @@ -8,6 +8,7 @@ This method will return the field/column name for the current version and provide a way to support both version for bundles. E.g. passing `o_id` in Pimcore 10 will return `o_id`, but `id` in Pimcore 11. - [Ecommerce] Elasticsearch 7 support has been deprecated, elasticsearch 8 supported was added. +- [ClassSavedInterface] Introduced additional interface implementing the `classSaved` method. The interface will be used by field definitions in `Pimcore\Model\DataObject\ClassDefinition\Data\*`. If your custom field definition implements the `classSaved` method, please use the `ClassSavedInterface` interface. Make sure that you either provide a default value (e.g. `$params = []`) for `$params` or don't use a second parameter in the method signature at all. Note that using the `classSaved` method without implementing the interface is deprecated and won't work in Pimcore 11. ## 10.5.10 diff --git a/models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php b/models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php index a57b89acad8..8afed6fe3b4 100644 --- a/models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php +++ b/models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php @@ -25,7 +25,7 @@ /** * @method DataObject\Data\ObjectMetadata\Dao getDao() */ -class AdvancedManyToManyObjectRelation extends ManyToManyObjectRelation implements IdRewriterInterface, PreGetDataInterface, LayoutDefinitionEnrichmentInterface +class AdvancedManyToManyObjectRelation extends ManyToManyObjectRelation implements IdRewriterInterface, PreGetDataInterface, LayoutDefinitionEnrichmentInterface, ClassSavedInterface { use DataObject\Traits\ElementWithMetadataComparisonTrait; use DataObject\ClassDefinition\Data\Extension\PositionSortTrait; @@ -757,7 +757,7 @@ public function setEnableBatchEdit($enableBatchEdit) * @param DataObject\ClassDefinition $class * @param array $params */ - public function classSaved($class, $params = []) + public function classSaved($class/**, $params = []**/) { /** @var DataObject\Data\ObjectMetadata $temp */ $temp = \Pimcore::getContainer()->get('pimcore.model.factory') diff --git a/models/DataObject/ClassDefinition/Data/AdvancedManyToManyRelation.php b/models/DataObject/ClassDefinition/Data/AdvancedManyToManyRelation.php index 9f27b240187..8a66f4037ab 100644 --- a/models/DataObject/ClassDefinition/Data/AdvancedManyToManyRelation.php +++ b/models/DataObject/ClassDefinition/Data/AdvancedManyToManyRelation.php @@ -23,7 +23,7 @@ use Pimcore\Model\Document; use Pimcore\Model\Element; -class AdvancedManyToManyRelation extends ManyToManyRelation implements IdRewriterInterface, PreGetDataInterface +class AdvancedManyToManyRelation extends ManyToManyRelation implements IdRewriterInterface, PreGetDataInterface, ClassSavedInterface { use DataObject\Traits\ElementWithMetadataComparisonTrait; use DataObject\ClassDefinition\Data\Extension\PositionSortTrait; @@ -775,7 +775,7 @@ public function getColumnKeys() /** * @param DataObject\ClassDefinition $class */ - public function classSaved($class) + public function classSaved($class/**, $params = [] **/) { /** @var DataObject\Data\ElementMetadata $temp */ $temp = \Pimcore::getContainer()->get('pimcore.model.factory') diff --git a/models/DataObject/ClassDefinition/Data/ClassSavedInterface.php b/models/DataObject/ClassDefinition/Data/ClassSavedInterface.php new file mode 100644 index 00000000000..49c10703790 --- /dev/null +++ b/models/DataObject/ClassDefinition/Data/ClassSavedInterface.php @@ -0,0 +1,14 @@ +setClass($class); diff --git a/models/DataObject/ClassDefinition/Data/Fieldcollections.php b/models/DataObject/ClassDefinition/Data/Fieldcollections.php index af1b3bc45d1..6fbdf93fc78 100644 --- a/models/DataObject/ClassDefinition/Data/Fieldcollections.php +++ b/models/DataObject/ClassDefinition/Data/Fieldcollections.php @@ -687,9 +687,14 @@ public function classSaved($class, $params = []) foreach ($fieldDefinition as $fd) { //TODO Pimcore 11 remove method_exists call - if (!$fd instanceof DataContainerAwareInterface && method_exists($fd, 'classSaved')) { + if (!$fd instanceof DataContainerAwareInterface && ($fd instanceof ClassSavedInterface || method_exists($fd, 'classSaved'))) { + if (!$fd instanceof ClassSavedInterface) { + trigger_deprecation('pimcore/pimcore', '10.6', + sprintf('Usage of method_exists is deprecated since version 10.6 and will be removed in Pimcore 11.' . + 'Implement the %s interface instead.', ClassSavedInterface::class)); + } // defer creation - $fd->classSaved($class); + $fd->classSaved($class, $params); } } diff --git a/models/DataObject/ClassDefinition/Data/Localizedfields.php b/models/DataObject/ClassDefinition/Data/Localizedfields.php index c3237572bca..3cce4e81895 100644 --- a/models/DataObject/ClassDefinition/Data/Localizedfields.php +++ b/models/DataObject/ClassDefinition/Data/Localizedfields.php @@ -572,7 +572,12 @@ public function classSaved($class, $params = []) foreach ($this->getFieldDefinitions() as $fd) { //TODO Pimcore 11 remove method_exists call - if (!$fd instanceof DataContainerAwareInterface && method_exists($fd, 'classSaved')) { + if (!$fd instanceof DataContainerAwareInterface && ($fd instanceof ClassSavedInterface || method_exists($fd, 'classSaved'))) { + if (!$fd instanceof ClassSavedInterface) { + trigger_deprecation('pimcore/pimcore', '10.6', + sprintf('Usage of method_exists is deprecated since version 10.6 and will be removed in Pimcore 11.' . + 'Implement the %s interface instead.', ClassSavedInterface::class)); + } $fd->classSaved($class, $params); } } diff --git a/models/DataObject/ClassDefinition/Data/Objectbricks.php b/models/DataObject/ClassDefinition/Data/Objectbricks.php index 3f66adf2c7a..3096125f292 100644 --- a/models/DataObject/ClassDefinition/Data/Objectbricks.php +++ b/models/DataObject/ClassDefinition/Data/Objectbricks.php @@ -903,11 +903,14 @@ public function classSaved($class, $params = []) foreach ($fieldDefinition as $fd) { //TODO Pimcore 11 remove method_exists call - if (method_exists($fd, 'classSaved')) { - // defer creation - if (!$fd instanceof DataContainerAwareInterface) { - $fd->classSaved($class); + if (!$fd instanceof DataContainerAwareInterface && ($fd instanceof ClassSavedInterface || method_exists($fd, 'classSaved'))) { + if (!$fd instanceof ClassSavedInterface) { + trigger_deprecation('pimcore/pimcore', '10.6', + sprintf('Usage of method_exists is deprecated since version 10.6 and will be removed in Pimcore 11.' . + 'Implement the %s interface instead.', ClassSavedInterface::class)); } + // defer creation + $fd->classSaved($class, $params); } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d7abf87562c..7cfff68c51d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -309,3 +309,10 @@ parameters: message: "#^PHPDoc type Elastic\\\\Elasticsearch\\\\Client\\|null of property Pimcore\\\\Bundle\\\\EcommerceFrameworkBundle\\\\IndexService\\\\Worker\\\\ElasticSearch\\\\DefaultElasticSearch8\\:\\:\\$elasticSearchClient is not covariant with PHPDoc type Elasticsearch\\\\Client\\|null of overridden property Pimcore\\\\Bundle\\\\EcommerceFrameworkBundle\\\\IndexService\\\\Worker\\\\ElasticSearch\\\\AbstractElasticSearch\\:\\:\\$elasticSearchClient\\.$#" count: 1 path: bundles/EcommerceFrameworkBundle/IndexService/Worker/ElasticSearch/DefaultElasticSearch8.php + + - + message: "#^PHPDoc tag \\@param references unknown parameter\\: \\$params$#" + paths: + - models/DataObject/ClassDefinition/Data/AdvancedManyToManyObjectRelation.php + - models/DataObject/ClassDefinition/Data/ClassSavedInterface.php + - models/DataObject/ClassDefinition/Data/Classificationstore.php \ No newline at end of file