Skip to content

Commit

Permalink
Add SchemaIgnoreClasses property for #8195.
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Podlipsky <simon@podlipsky.net>
  • Loading branch information
ianef and simPod committed Nov 24, 2021
1 parent 146b465 commit ebc75b7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
20 changes: 20 additions & 0 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,4 +1003,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 string[]
*/
public function getSchemaIgnoreClasses(): array
{
return $this->_attributes['schemaIgnoreClasses'] ?? [];
}

/**
* Sets a list of entity class names to be ignored by the SchemaTool
*
* @param string[] $schemaIgnoreClasses Array of entity class names
*/
public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): array
{
$this->_attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses;
}
}
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}

/**
Expand Down

0 comments on commit ebc75b7

Please sign in to comment.