diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index 8e8442af98b..56305c443dd 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -440,6 +440,20 @@ That will be available for all entities without a custom repository class. The default value is ``Doctrine\ORM\EntityRepository``. Any repository class must be a subclass of EntityRepository otherwise you got an ORMException +Default Repository (***OPTIONAL***) +----------------------------------- + +Specifies the Entity FQCNs. SchemaTool will then ignore these (e.g. when comparing schemas). + +.. code-block:: php + + setSchemaIgnoreClasses([$fqcn]); + $config->getSchemaIgnoreClasses(); + +The default value is ``Doctrine\ORM\EntityRepository``. +Any repository class must be a subclass of EntityRepository otherwise you got an ORMException + Setting up the Console ---------------------- diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index e83317c490b..a0b9190edd5 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -1012,4 +1012,24 @@ public function setDefaultQueryHint($name, $value) { $this->_attributes['defaultQueryHints'][$name] = $value; } + + /** + * Gets a list of entity class names to be ignored by the SchemaTool + * + * @return list + */ + public function getSchemaIgnoreClasses(): array + { + return $this->_attributes['schemaIgnoreClasses'] ?? []; + } + + /** + * Sets a list of entity class names to be ignored by the SchemaTool + * + * @param list $schemaIgnoreClasses List of entity class names + */ + public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): void + { + $this->_attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses; + } } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 1225946138a..e0ea175c824 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -129,7 +129,8 @@ private function processingNotRequired( return isset($processedClasses[$class->name]) || $class->isMappedSuperclass || $class->isEmbeddedClass || - ($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName); + ($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName) || + in_array($class->name, $this->em->getConfiguration()->getSchemaIgnoreClasses()); } /** diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index 766af976a2c..5faa3146ece 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -338,6 +338,34 @@ public function testIncorrectUniqueConstraintsBasedOnFields(): void $this->expectException(MappingException::class); $schemaTool->getSchemaFromMetadata([$class]); } + + /** + * @group schema-configuration + */ + public function testConfigurationSchemaIgnoredEntity(): void + { + $em = $this->getTestEntityManager(); + $schemaTool = new SchemaTool($em); + + $classes = [ + $em->getClassMetadata(FirstEntity::class), + $em->getClassMetadata(SecondEntity::class), + ]; + + $schema = $schemaTool->getSchemaFromMetadata($classes); + + self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.'); + self::assertTrue($schema->hasTable('second_entity'), 'Table second_entity should exist.'); + + $em->getConfiguration()->setSchemaIgnoreClasses([ + SecondEntity::class, + ]); + + $schema = $schemaTool->getSchemaFromMetadata($classes); + + self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.'); + self::assertFalse($schema->hasTable('second_entity'), 'Table second_entity should not exist.'); + } } /**