Restoring database.lib.php with no Doctrine.

1.10.x
Julio Montoya 11 years ago
parent 3b1e0de7c5
commit 363212d4fe
  1. 58
      main/inc/global.inc.php
  2. 31
      main/inc/lib/database.lib.php

@ -137,12 +137,6 @@ $params = array(
'client_flags' => $dbFlags, 'client_flags' => $dbFlags,
); );
if (!($conn_return = @Database::connect($params))) {
$global_error_code = 3;
// The database server is not available or credentials are invalid.
require $includePath.'/global_error_message.inc.php';
die();
}
if (!$_configuration['db_host']) { if (!$_configuration['db_host']) {
$global_error_code = 4; $global_error_code = 4;
// A configuration option about database server is missing. // A configuration option about database server is missing.
@ -150,19 +144,18 @@ if (!$_configuration['db_host']) {
die(); die();
} }
if (!($conn_return = @Database::connect($params))) {
$global_error_code = 3;
// The database server is not available or credentials are invalid.
require $includePath.'/global_error_message.inc.php';
die();
}
// Doctrine ORM configuration // Doctrine ORM configuration
use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
$paths = array(
api_get_path(SYS_PATH).'src/Chamilo/CoreBundle/Entity',
api_get_path(SYS_PATH).'src/Chamilo/UserBundle/Entity',
api_get_path(SYS_PATH).'src/Chamilo/CourseBundle/Entity'
);
$isDevMode = true;
// the connection configuration // the connection configuration
$dbParams = array( $dbParams = array(
'driver' => 'pdo_mysql', 'driver' => 'pdo_mysql',
@ -172,17 +165,7 @@ $dbParams = array(
'dbname' => $_configuration['main_database'], 'dbname' => $_configuration['main_database'],
); );
$isSimpleMode = false; $config = Database::getDoctrineConfig();
$proxyDir = null;
$cache = null;
$config = Setup::createAnnotationMetadataConfiguration(
$paths,
$isDevMode,
$proxyDir,
$cache,
$isSimpleMode
);
$config->setEntityNamespaces( $config->setEntityNamespaces(
array( array(
@ -194,18 +177,18 @@ $config->setEntityNamespaces(
$entityManager = EntityManager::create($dbParams, $config); $entityManager = EntityManager::create($dbParams, $config);
// Registering Constraints
use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\AnnotationRegistry;
AnnotationRegistry::registerAutoloadNamespace( AnnotationRegistry::registerAutoloadNamespace(
'Symfony\Component\Validator\Constraint', 'Symfony\Component\Validator\Constraint',
api_get_path(SYS_PATH)."vendor/symfony/validator" api_get_path(SYS_PATH)."vendor/symfony/validator"
); );
AnnotationRegistry::registerFile( AnnotationRegistry::registerFile(
api_get_path(SYS_PATH)."vendor/symfony/doctrine-bridge/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php" api_get_path(SYS_PATH)."vendor/symfony/doctrine-bridge/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php"
); );
// Registering gedmo extensions
AnnotationRegistry::registerAutoloadNamespace( AnnotationRegistry::registerAutoloadNamespace(
'Gedmo\Mapping\Annotation', 'Gedmo\Mapping\Annotation',
api_get_path(SYS_PATH)."vendor/gedmo/doctrine-extensions/lib" api_get_path(SYS_PATH)."vendor/gedmo/doctrine-extensions/lib"
@ -215,6 +198,22 @@ AnnotationRegistry::registerAutoloadNamespace(
$repo = $entityManager->getRepository('ChamiloUserBundle:User'); $repo = $entityManager->getRepository('ChamiloUserBundle:User');
$repo = $entityManager->getRepository('ChamiloCoreBundle:Course');*/ $repo = $entityManager->getRepository('ChamiloCoreBundle:Course');*/
if (!($conn_return = @Database::connect($params))) {
$global_error_code = 3;
// The database server is not available or credentials are invalid.
require $includePath.'/global_error_message.inc.php';
die();
}
/*try {
$connect = $entityManager->getConnection()->connect();
} catch (Exception $e) {
$global_error_code = 3;
// The database server is not available or credentials are invalid.
require $includePath.'/global_error_message.inc.php';
die();
}*/
$database = new \Database(); $database = new \Database();
$database->setManager($entityManager); $database->setManager($entityManager);
@ -264,12 +263,12 @@ if (!empty($_configuration['multiple_access_urls'])) {
// The system has not been designed to use special SQL modes that were introduced since MySQL 5. // The system has not been designed to use special SQL modes that were introduced since MySQL 5.
Database::query("set session sql_mode='';"); Database::query("set session sql_mode='';");
if (!Database::select_db($_configuration['main_database'], $database_connection)) { /*if (!Database::select_db($_configuration['main_database'], $database_connection)) {
$global_error_code = 5; $global_error_code = 5;
// Connection to the main Chamilo database is impossible, it might be missing or restricted or its configuration option might be incorrect. // Connection to the main Chamilo database is impossible, it might be missing or restricted or its configuration option might be incorrect.
require $includePath.'/global_error_message.inc.php'; require $includePath.'/global_error_message.inc.php';
die(); die();
} }*/
/* Initialization of the default encodings */ /* Initialization of the default encodings */
// The platform's character set must be retrieved at this early moment. // The platform's character set must be retrieved at this early moment.
@ -694,3 +693,4 @@ define('DEFAULT_DOCUMENT_QUOTA', $default_quota);
// Sets the ascii_math plugin see #7134 // Sets the ascii_math plugin see #7134
$_SESSION['ascii_math_loaded'] = false; $_SESSION['ascii_math_loaded'] = false;

@ -1144,4 +1144,35 @@ class Database
public static function get_last_insert_id() { public static function get_last_insert_id() {
return mysql_insert_id(); return mysql_insert_id();
} }
/**
* @return \Doctrine\ORM\Configuration
*/
public static function getDoctrineConfig()
{
$isDevMode = true;
$isSimpleMode = false;
$proxyDir = null;
$cache = null;
$paths = array(
api_get_path(SYS_PATH).'src/Chamilo/CoreBundle/Entity',
api_get_path(SYS_PATH).'src/Chamilo/UserBundle/Entity',
api_get_path(SYS_PATH).'src/Chamilo/CourseBundle/Entity'
);
/*$doctrineCache = api_get_path(SYS_ARCHIVE_PATH).'doctrine/';
if (!is_dir($doctrineCache)) {
mkdir($doctrineCache, api_get_permissions_for_new_directories(), true);
}*/
return \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(
$paths,
$isDevMode,
$proxyDir,
$cache,
$isSimpleMode
);
}
} }

Loading…
Cancel
Save