Skip to content

EspoCRM – Open Source CRM Application

Test refactoring, fixes, data manager exception handling

Yuriide7a6caa76e7
diff --git a/application/Espo/Core/DataManager.php b/application/Espo/Core/DataManager.php
index a409586a79..3dd74d85ab 100644
--- a/application/Espo/Core/DataManager.php
+++ b/application/Espo/Core/DataManager.php
@@ -157,19 +157,23 @@ class DataManager
$schemaManager = $this->schemaManager;
+ $exception = null;
+
try {
$result = $schemaManager->rebuild($entityTypeList, $mode);
} catch (Throwable $e) {
$result = false;
- $this->log->error(
- "Failed to rebuild database schema. {$e->getMessage()}; {$e->getFile()}:{$e->getLine()}",
- ['exception' => $e]
- );
+ $this->log->error("Failed to rebuild database schema. {message}", [
+ 'exception' => $e,
+ 'message' => $e->getMessage(),
+ ]);
+
+ $exception = $e;
}
if (!$result) {
- throw new Error("Error while rebuilding database. See log file for details.");
+ throw new Error("Error while rebuilding database. See log file for details.", previous: $exception);
}
$databaseType = strtolower($schemaManager->getDatabaseHelper()->getType());
diff --git a/application/Espo/Core/Utils/Database/Schema/SchemaManager.php b/application/Espo/Core/Utils/Database/Schema/SchemaManager.php
index 85a41f6da5..c3ac62daa3 100644
--- a/application/Espo/Core/Utils/Database/Schema/SchemaManager.php
+++ b/application/Espo/Core/Utils/Database/Schema/SchemaManager.php
@@ -38,7 +38,6 @@ use Doctrine\DBAL\Schema\ComparatorConfig;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Schema\SchemaException;
-use Doctrine\DBAL\Types\Exception\TypesException;
use Doctrine\DBAL\Types\Type;
use Espo\Core\Binding\BindingContainerBuilder;
@@ -157,9 +156,7 @@ class SchemaManager
try {
$this->processPreRebuildActions($fromSchema, $schema);
} catch (Throwable $e) {
- $this->log->alert('Rebuild database pre-rebuild error: '. $e->getMessage());
-
- return false;
+ throw new RuntimeException("Rebuild database pre-rebuild error.", previous: $e);
}
$diff = $this->comparator->compareSchemas($fromSchema, $schema);
diff --git a/tests/integration/Core/Tester.php b/tests/integration/Core/Tester.php
index 457fc44b20..ef7838e987 100644
--- a/tests/integration/Core/Tester.php
+++ b/tests/integration/Core/Tester.php
@@ -376,11 +376,13 @@ class Tester
$schemaManager = $connection->createSchemaManager();
$platform = $connection->getDatabasePlatform();
- if (in_array($dbname, $schemaManager->listDatabases())) {
- return;
+ foreach ($schemaManager->introspectDatabaseNames() as $databaseName) {
+ if ($dbname === $databaseName->getIdentifier()->getValue()) {
+ return;
+ }
}
- $schemaManager->createDatabase($platform->quoteIdentifier($dbname));
+ $schemaManager->createDatabase($platform->quoteSingleIdentifier($dbname));
}
/**
@@ -402,10 +404,10 @@ class Tester
$pdo = $databaseHelper->getPDO();
- $tables = $schemaManager->listTableNames();
+ $tables = $schemaManager->introspectTables();
foreach ($tables as $table) {
- $tableQuoted = $platform->quoteIdentifier($table);
+ $tableQuoted = $table->getObjectName()->toString();
$sql = $platform->getDropTableSQL($tableQuoted);