mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 15:06:06 +00:00
refactoring
This commit is contained in:
@@ -36,7 +36,8 @@ use Espo\Core\Utils\{
|
||||
File\Manager as FileManager,
|
||||
Log,
|
||||
Database\Schema\Schema,
|
||||
Database\Schema\Utils as SchemaUtils
|
||||
Database\Schema\Utils as SchemaUtils,
|
||||
Module\PathProvider,
|
||||
};
|
||||
|
||||
use Doctrine\DBAL\{
|
||||
@@ -58,11 +59,9 @@ class Converter
|
||||
|
||||
private $log;
|
||||
|
||||
protected $tablePaths = [
|
||||
'corePath' => 'application/Espo/Core/Utils/Database/Schema/tables',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/Core/Utils/Database/Schema/tables',
|
||||
'customPath' => 'custom/Espo/Custom/Core/Utils/Database/Schema/tables',
|
||||
];
|
||||
private $pathProvider;
|
||||
|
||||
private $tablesPath = 'Core/Utils/Database/Schema/tables';
|
||||
|
||||
protected $typeList;
|
||||
|
||||
@@ -87,7 +86,7 @@ class Converter
|
||||
];
|
||||
|
||||
protected $notStorableTypes = [
|
||||
'foreign'
|
||||
'foreign',
|
||||
];
|
||||
|
||||
protected $maxIndexLength;
|
||||
@@ -97,32 +96,19 @@ class Converter
|
||||
FileManager $fileManager,
|
||||
Schema $databaseSchema,
|
||||
Config $config,
|
||||
Log $log
|
||||
Log $log,
|
||||
PathProvider $pathProvider
|
||||
) {
|
||||
$this->metadata = $metadata;
|
||||
$this->fileManager = $fileManager;
|
||||
$this->databaseSchema = $databaseSchema;
|
||||
$this->config = $config;
|
||||
$this->log = $log;
|
||||
$this->pathProvider = $pathProvider;
|
||||
|
||||
$this->typeList = array_keys(DbalType::getTypesMap());
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get schema
|
||||
*
|
||||
@@ -467,7 +453,7 @@ class Converter
|
||||
}
|
||||
}
|
||||
|
||||
$databaseParams = $this->getConfig()->get('database');
|
||||
$databaseParams = $this->config->get('database');
|
||||
|
||||
if (!isset($databaseParams['charset']) || $databaseParams['charset'] == 'utf8mb4') {
|
||||
$dbFieldParams['platformOptions'] = [
|
||||
@@ -542,28 +528,24 @@ class Converter
|
||||
*/
|
||||
protected function getCustomTables(array $ormMeta)
|
||||
{
|
||||
$customTables = $this->loadData($this->tablePaths['corePath']);
|
||||
$customTables = $this->loadData($this->pathProvider->getCore() . $this->tablesPath);
|
||||
|
||||
if (!empty($this->tablePaths['modulePath'])) {
|
||||
$moduleDir = strstr($this->tablePaths['modulePath'], '{*}', true);
|
||||
foreach ($this->metadata->getModuleList() as $moduleName) {
|
||||
$modulePath = $this->pathProvider->getModule($moduleName) . $this->tablesPath;
|
||||
|
||||
$moduleList = isset($this->metadata) ?
|
||||
$this->getMetadata()->getModuleList() :
|
||||
$this->getFileManager()->getFileList($moduleDir, false, '', false);
|
||||
|
||||
foreach ($moduleList as $moduleName) {
|
||||
$modulePath = str_replace('{*}', $moduleName, $this->tablePaths['modulePath']);
|
||||
|
||||
$customTables = Util::merge($customTables, $this->loadData($modulePath));
|
||||
}
|
||||
$customTables = Util::merge(
|
||||
$customTables,
|
||||
$this->loadData($modulePath)
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($this->tablePaths['customPath'])) {
|
||||
$customTables = Util::merge($customTables, $this->loadData($this->tablePaths['customPath']));
|
||||
}
|
||||
$customTables = Util::merge(
|
||||
$customTables,
|
||||
$this->loadData($this->pathProvider->getCustom() . $this->tablesPath)
|
||||
);
|
||||
|
||||
//get custom tables from metdata 'additionalTables'
|
||||
foreach ($ormMeta as $entityName => $entityParams) {
|
||||
// Get custom tables from metdata 'additionalTables'.
|
||||
foreach ($ormMeta as $entityParams) {
|
||||
if (isset($entityParams['additionalTables']) && is_array($entityParams['additionalTables'])) {
|
||||
$customTables = Util::merge($customTables, $entityParams['additionalTables']);
|
||||
}
|
||||
@@ -615,10 +597,10 @@ class Converter
|
||||
return $tables;
|
||||
}
|
||||
|
||||
$fileList = $this->getFileManager()->getFileList($path, false, '\.php$', true);
|
||||
$fileList = $this->fileManager->getFileList($path, false, '\.php$', true);
|
||||
|
||||
foreach($fileList as $fileName) {
|
||||
$fileData = $this->getFileManager()->getPhpContents($path . '/' . $fileName);
|
||||
$fileData = $this->fileManager->getPhpContents($path . '/' . $fileName);
|
||||
|
||||
if (is_array($fileData)) {
|
||||
$tables = Util::merge($tables, $fileData);
|
||||
|
||||
@@ -47,6 +47,7 @@ use Espo\Core\{
|
||||
Utils\Database\DBAL\Schema\Comparator,
|
||||
Utils\Database\Converter as DatabaseConverter,
|
||||
Utils\Log,
|
||||
Utils\Module\PathProvider,
|
||||
};
|
||||
|
||||
use Throwable;
|
||||
@@ -73,10 +74,7 @@ class Schema
|
||||
|
||||
private $log;
|
||||
|
||||
protected $fieldTypePaths = [
|
||||
'application/Espo/Core/Utils/Database/DBAL/FieldTypes',
|
||||
'custom/Espo/Custom/Core/Utils/Database/DBAL/FieldTypes',
|
||||
];
|
||||
private $fieldTypePath = 'application/Espo/Core/Utils/Database/DBAL/FieldTypes';
|
||||
|
||||
private $rebuildActionsPath = 'Core/Utils/Database/Schema/rebuildActions';
|
||||
|
||||
@@ -96,7 +94,8 @@ class Schema
|
||||
EntityManager $entityManager,
|
||||
ClassMap $classMap,
|
||||
OrmMetadataData $ormMetadataData,
|
||||
Log $log
|
||||
Log $log,
|
||||
PathProvider $pathProvider
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->metadata = $metadata;
|
||||
@@ -118,7 +117,8 @@ class Schema
|
||||
$this->fileManager,
|
||||
$this,
|
||||
$this->config,
|
||||
$this->log
|
||||
$this->log,
|
||||
$pathProvider
|
||||
);
|
||||
|
||||
$this->ormMetadataData = $ormMetadataData;
|
||||
@@ -171,30 +171,27 @@ class Schema
|
||||
|
||||
protected function initFieldTypes()
|
||||
{
|
||||
foreach ($this->fieldTypePaths as $path) {
|
||||
$typeList = $this->getFileManager()->getFileList($path, false, '\.php$');
|
||||
$typeList = $this->getFileManager()->getFileList($this->fieldTypePath, false, '\.php$');
|
||||
|
||||
if ($typeList === false) {
|
||||
continue;
|
||||
foreach ($typeList as $name) {
|
||||
$typeName = preg_replace('/Type\.php$/i', '', $name);
|
||||
$dbalTypeName = strtolower($typeName);
|
||||
|
||||
$filePath = Util::concatPath($this->fieldTypePath, $typeName . 'Type');
|
||||
$class = Util::getClassName($filePath);
|
||||
|
||||
if (!Type::hasType($dbalTypeName)) {
|
||||
Type::addType($dbalTypeName, $class);
|
||||
}
|
||||
else {
|
||||
Type::overrideType($dbalTypeName, $class);
|
||||
}
|
||||
|
||||
foreach ($typeList as $name) {
|
||||
$typeName = preg_replace('/Type\.php$/i', '', $name);
|
||||
$dbalTypeName = strtolower($typeName);
|
||||
$dbTypeName = method_exists($class, 'getDbTypeName') ? $class::getDbTypeName() : $dbalTypeName;
|
||||
|
||||
$filePath = Util::concatPath($path, $typeName . 'Type');
|
||||
$class = Util::getClassName($filePath);
|
||||
|
||||
if (! Type::hasType($dbalTypeName)) {
|
||||
Type::addType($dbalTypeName, $class);
|
||||
} else {
|
||||
Type::overrideType($dbalTypeName, $class);
|
||||
}
|
||||
|
||||
$dbTypeName = method_exists($class, 'getDbTypeName') ? $class::getDbTypeName() : $dbalTypeName;
|
||||
|
||||
$this->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping($dbTypeName, $dbalTypeName);
|
||||
}
|
||||
$this->getConnection()
|
||||
->getDatabasePlatform()
|
||||
->registerDoctrineTypeMapping($dbTypeName, $dbalTypeName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user