Skip to content
Snippets Groups Projects
Commit 896105cf authored by nicxvan's avatar nicxvan
Browse files

Convert 57 to MR

parent 16964d02
Branches
Tags
No related merge requests found
Pipeline #134024 failed
......@@ -40,12 +40,20 @@ public function validate($module) {
$entity_types = $this->entityTypeManager->getDefinitions();
$reasons = [];
foreach ($entity_types as $entity_type) {
if ($module == $entity_type->getProvider() && $entity_type instanceof ContentEntityTypeInterface && $this->entityTypeManager->getStorage($entity_type->id())->hasData()) {
$reasons[] = $this->t('There is content for the entity type: @entity_type. <a href=":url">Remove @entity_type_plural</a>.', [
'@entity_type' => $entity_type->getLabel(),
'@entity_type_plural' => $entity_type->getPluralLabel(),
':url' => Url::fromRoute('system.prepare_modules_entity_uninstall', ['entity_type_id' => $entity_type->id()])->toString(),
]);
try {
if ($module == $entity_type->getProvider() && $entity_type instanceof ContentEntityTypeInterface && $this->entityTypeManager->getStorage($entity_type->id())->hasData()) {
$reasons[] = $this->t('There is content for the entity type: @entity_type. <a href=":url">Remove @entity_type_plural</a>.', [
'@entity_type' => $entity_type->getLabel(),
'@entity_type_plural' => $entity_type->getPluralLabel(),
':url' => Url::fromRoute('system.prepare_modules_entity_uninstall', ['entity_type_id' => $entity_type->id()])->toString(),
]);
}
}
catch (\Throwable $th) {
// An exception here means that the table does not exist. That means
// there is no data. This exception is caught to allow to uninstall
// modules with incorrectly installed entity types.
return $reasons = [];
}
}
return $reasons;
......
......@@ -430,4 +430,15 @@ public function testIdentifierSchema() {
$this->assertEquals($expected_revision_id_schema, $revision_id_schema);
}
/**
* Manually drop one of the test entity type tables to simulate a scenario
* where a table was not created or an entity type is new.
*/
public function testUninstall() {
$this->installModule('entity_test');
\Drupal::database()->schema()->dropTable('entity_test');
// Uninstall the entity_test module.
$this->container->get('module_installer')->uninstall(['entity_test']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment