Internal: Remove code to register doctrine annotations

pull/4862/head
Angel Fernando Quiroz Campos 2 years ago
parent 9899b093ce
commit 7f554342c2
  1. 59
      public/main/inc/lib/database.lib.php
  2. 4
      public/main/install/ajax.php
  3. 16
      public/main/install/index.php
  4. 18
      public/main/install/install.lib.php

@ -2,7 +2,6 @@
/* For licensing terms, see /license.txt */
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
@ -23,7 +22,7 @@ class Database
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\DBAL\Exception
*/
public function connect(array $params = [], string $entityRootPath = '')
public static function connect(array $params = [], string $entityRootPath = ''): void
{
$config = self::getDoctrineConfig($entityRootPath);
$config->setAutoGenerateProxyClasses(true);
@ -35,7 +34,6 @@ class Database
);
$params['charset'] = 'utf8';
$sysPath = api_get_path(SYMFONY_SYS_PATH);
// standard annotation reader
$annotationReader = new Doctrine\Common\Annotations\AnnotationReader();
@ -57,54 +55,6 @@ class Database
$cachedAnnotationReader // our cached annotation reader
);
AnnotationRegistry::registerLoader(
function ($class) use ($sysPath) {
$file = str_replace("\\", DIRECTORY_SEPARATOR, $class).".php";
$file = str_replace('Symfony/Component/Validator', '', $file);
$file = str_replace('Symfony\Component\Validator', '', $file);
$file = str_replace('Symfony/Component/Serializer', '', $file);
$fileToInclude = $sysPath.'vendor/symfony/validator/'.$file;
if (file_exists($fileToInclude)) {
// file exists makes sure that the loader fails silently
require_once $fileToInclude;
return true;
}
$fileToInclude = $sysPath.'vendor/symfony/validator/Constraints/'.$file;
if (file_exists($fileToInclude)) {
// file exists makes sure that the loader fails silently
require_once $fileToInclude;
return true;
}
$fileToInclude = $sysPath.'vendor/symfony/serializer/'.$file;
if (file_exists($fileToInclude)) {
// file exists makes sure that the loader fails silently
require_once $fileToInclude;
return true;
}
}
);
AnnotationRegistry::registerFile(
$sysPath.'vendor/api-platform/core/src/Core/Annotation/ApiResource.php'
);
AnnotationRegistry::registerFile(
$sysPath.'vendor/api-platform/core/src/Core/Annotation/ApiFilter.php'
);
AnnotationRegistry::registerFile(
$sysPath.'vendor/api-platform/core/src/Core/Annotation/ApiProperty.php'
);
AnnotationRegistry::registerFile(
$sysPath.'vendor/api-platform/core/src/Core/Annotation/ApiSubresource.php'
);
$entityManager = EntityManager::create($params, $config, $evm);
if (false === Type::hasType('uuid')) {
@ -112,12 +62,9 @@ class Database
}
$connection = $entityManager->getConnection();
AnnotationRegistry::registerFile(
$sysPath.'vendor/symfony/doctrine-bridge/Validator/Constraints/UniqueEntity.php'
);
$this->setConnection($connection);
$this->setManager($entityManager);
self::setConnection($connection);
self::setManager($entityManager);
}
public static function setManager(EntityManager $em)

@ -40,8 +40,8 @@ if ('new' === $installType) {
$dbPort = isset($_POST['db_port']) ? $_POST['db_port'] : 3306;
$database = connectToDatabase($dbHost, $dbUsername, $dbPass, $dbName, $dbPort);
$manager = $database->getManager();
connectToDatabase($dbHost, $dbUsername, $dbPass, $dbName, $dbPort);
$manager = Database::getManager();
$db_prefix = api_get_configuration_value('db_prefix') ? api_get_configuration_value('db_prefix') : 'chamilo_';
$db_c_prefix = api_get_configuration_value('table_prefix') ? api_get_configuration_value('table_prefix') : 'crs_';

@ -312,14 +312,14 @@ if (isset($_POST['step2'])) {
// STEP 5 : CONFIGURATION SETTINGS
if ('update' === $installType) {
$db_name = $dbNameForm;
$database = connectToDatabase(
connectToDatabase(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
$dbNameForm,
$dbPortForm
);
$manager = $database->getManager();
$manager = Database::getManager();
$tmp = get_config_param_from_db('platformLanguage');
if (!empty($tmp)) {
@ -461,14 +461,14 @@ if (isset($_POST['step2'])) {
$current_step = 7;
if ('update' === $installType) {
$database = connectToDatabase(
connectToDatabase(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
$dbNameForm,
$dbPortForm
);
$manager = $database->getManager();
$manager = Database::getManager();
//$perm = api_get_permissions_for_new_directories();
//$perm_file = api_get_permissions_for_new_files();
// @todo fix permissions.
@ -533,14 +533,14 @@ if (isset($_POST['step2'])) {
set_file_folder_permissions();
error_log("connectToDatabase as user $dbUsernameForm");
$database = connectToDatabase(
connectToDatabase(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
null,
$dbPortForm
);
$manager = $database->getManager();
$manager = Database::getManager();
$dbNameForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbNameForm);
// Drop and create the database anyways
@ -556,7 +556,7 @@ if (isset($_POST['step2'])) {
$schemaManager->createDatabase($dbNameForm);
error_log("Connect to database $dbNameForm with user $dbUsernameForm");
$database = connectToDatabase(
connectToDatabase(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
@ -564,7 +564,7 @@ if (isset($_POST['step2'])) {
$dbPortForm
);
$manager = $database->getManager();
$manager = Database::getManager();
// Create .env.local file
$envFile = api_get_path(SYMFONY_SYS_PATH).'.env.local';
$distFile = api_get_path(SYMFONY_SYS_PATH).'.env';

@ -365,7 +365,7 @@ function get_config_param_from_db($param = '')
* @param string $databaseName
* @param int $port
*
* @return \Database
* @return void
*/
function connectToDatabase(
$host,
@ -374,8 +374,7 @@ function connectToDatabase(
$databaseName,
$port = 3306
) {
$database = new \Database();
$database->connect(
Database::connect(
[
'driver' => 'pdo_mysql',
'host' => $host,
@ -385,8 +384,6 @@ function connectToDatabase(
'dbname' => $databaseName,
]
);
return $database;
}
/**
@ -982,8 +979,7 @@ function display_database_settings_form(
try {
if ('update' === $installType) {
/** @var \Database $manager */
$manager = connectToDatabase(
connectToDatabase(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
@ -991,6 +987,7 @@ function display_database_settings_form(
$dbPortForm
);
$manager = Database::getManager();
$connection = $manager->getConnection();
$connection->connect();
$schemaManager = $connection->getSchemaManager();
@ -1008,7 +1005,7 @@ function display_database_settings_form(
$tableDropWorks = false === $schemaManager->tablesExist($table);
}
} else {
$manager = connectToDatabase(
connectToDatabase(
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
@ -1016,6 +1013,7 @@ function display_database_settings_form(
$dbPortForm
);
$manager = Database::getManager();
$schemaManager = $manager->getConnection()->createSchemaManager();
$databases = $schemaManager->listDatabases();
$databaseExists = in_array($dbNameForm, $databases);
@ -1754,14 +1752,14 @@ function checkMigrationStatus(): array
$envFile = api_get_path(SYMFONY_SYS_PATH) . '.env.local';
$dotenv->loadEnv($envFile);
$database = connectToDatabase(
connectToDatabase(
$_ENV['DATABASE_HOST'],
$_ENV['DATABASE_USER'],
$_ENV['DATABASE_PASSWORD'],
$_ENV['DATABASE_NAME'],
$_ENV['DATABASE_PORT']
);
$manager = $database->getManager();
$manager = Database::getManager();
$connection = $manager->getConnection();

Loading…
Cancel
Save