Skip to content

Commit 4219506

Browse files
simPodianef
andauthored
Add SchemaIgnoreClasses property for #8195. (#9202)
Co-authored-by: Simon Podlipsky <[email protected]> Co-authored-by: Iab Foulds <[email protected]>
1 parent ac5aea1 commit 4219506

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

docs/en/reference/advanced-configuration.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,19 @@ That will be available for all entities without a custom repository class.
440440
The default value is ``Doctrine\ORM\EntityRepository``.
441441
Any repository class must be a subclass of EntityRepository otherwise you got an ORMException
442442

443+
Ignoring entities (***OPTIONAL***)
444+
-----------------------------------
445+
446+
Specifies the Entity FQCNs to ignore.
447+
SchemaTool will then skip these (e.g. when comparing schemas).
448+
449+
.. code-block:: php
450+
451+
<?php
452+
$config->setSchemaIgnoreClasses([$fqcn]);
453+
$config->getSchemaIgnoreClasses();
454+
455+
443456
Setting up the Console
444457
----------------------
445458

lib/Doctrine/ORM/Configuration.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,4 +1012,24 @@ public function setDefaultQueryHint($name, $value)
10121012
{
10131013
$this->_attributes['defaultQueryHints'][$name] = $value;
10141014
}
1015+
1016+
/**
1017+
* Gets a list of entity class names to be ignored by the SchemaTool
1018+
*
1019+
* @return list<class-string>
1020+
*/
1021+
public function getSchemaIgnoreClasses(): array
1022+
{
1023+
return $this->_attributes['schemaIgnoreClasses'] ?? [];
1024+
}
1025+
1026+
/**
1027+
* Sets a list of entity class names to be ignored by the SchemaTool
1028+
*
1029+
* @param list<class-string> $schemaIgnoreClasses List of entity class names
1030+
*/
1031+
public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): void
1032+
{
1033+
$this->_attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses;
1034+
}
10151035
}

lib/Doctrine/ORM/Tools/SchemaTool.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ private function processingNotRequired(
129129
return isset($processedClasses[$class->name]) ||
130130
$class->isMappedSuperclass ||
131131
$class->isEmbeddedClass ||
132-
($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName);
132+
($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName) ||
133+
in_array($class->name, $this->em->getConfiguration()->getSchemaIgnoreClasses());
133134
}
134135

135136
/**

tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,34 @@ public function testIncorrectUniqueConstraintsBasedOnFields(): void
338338
$this->expectException(MappingException::class);
339339
$schemaTool->getSchemaFromMetadata([$class]);
340340
}
341+
342+
/**
343+
* @group schema-configuration
344+
*/
345+
public function testConfigurationSchemaIgnoredEntity(): void
346+
{
347+
$em = $this->getTestEntityManager();
348+
$schemaTool = new SchemaTool($em);
349+
350+
$classes = [
351+
$em->getClassMetadata(FirstEntity::class),
352+
$em->getClassMetadata(SecondEntity::class),
353+
];
354+
355+
$schema = $schemaTool->getSchemaFromMetadata($classes);
356+
357+
self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.');
358+
self::assertTrue($schema->hasTable('second_entity'), 'Table second_entity should exist.');
359+
360+
$em->getConfiguration()->setSchemaIgnoreClasses([
361+
SecondEntity::class,
362+
]);
363+
364+
$schema = $schemaTool->getSchemaFromMetadata($classes);
365+
366+
self::assertTrue($schema->hasTable('first_entity'), 'Table first_entity should exist.');
367+
self::assertFalse($schema->hasTable('second_entity'), 'Table second_entity should not exist.');
368+
}
341369
}
342370

343371
/**

0 commit comments

Comments
 (0)