Skip to content

Commit

Permalink
Internal: Only autogenerate Doctrine proxies if they don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Mar 22, 2023
1 parent f99329d commit ada61aa
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions main/inc/lib/database.lib.php
Expand Up @@ -3,10 +3,12 @@
/* For licensing terms, see /license.txt */

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Proxy\AbstractProxyFactory;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use Symfony\Component\Debug\ExceptionHandler;

/**
Expand Down Expand Up @@ -148,22 +150,6 @@ public function connect(
$returnManager = false
) {
$config = self::getDoctrineConfig($entityRootPath);
$autoGenerate = Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_NEVER;
if (api_get_setting('server_type') == 'test') {
$autoGenerate = Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_ALWAYS;
}
$config->setAutoGenerateProxyClasses($autoGenerate);

$config->setEntityNamespaces(
[
'ChamiloUserBundle' => 'Chamilo\UserBundle\Entity',
'ChamiloCoreBundle' => 'Chamilo\CoreBundle\Entity',
'ChamiloCourseBundle' => 'Chamilo\CourseBundle\Entity',
'ChamiloSkillBundle' => 'Chamilo\SkillBundle\Entity',
'ChamiloTicketBundle' => 'Chamilo\TicketBundle\Entity',
'ChamiloPluginBundle' => 'Chamilo\PluginBundle\Entity',
]
);

$params['charset'] = 'utf8';
$entityManager = EntityManager::create($params, $config);
Expand Down Expand Up @@ -783,7 +769,7 @@ public static function delete($table_name, $where_conditions, $show_query = fals
*/
public static function getDoctrineConfig($path)
{
$isDevMode = api_get_setting('server_type') == 'test'; // Forces doctrine to use ArrayCache instead of apc/xcache/memcache/redis
$isDevMode = true; // Forces doctrine to use ArrayCache instead of apc/xcache/memcache/redis
$isSimpleMode = false; // related to annotations @Entity
$cache = null;
$path = !empty($path) ? $path : api_get_path(SYS_PATH);
Expand All @@ -805,14 +791,27 @@ public static function getDoctrineConfig($path)

$proxyDir = $path.'app/cache/';

$config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(
$config = Setup::createAnnotationMetadataConfiguration(
$paths,
$isDevMode,
$proxyDir,
$cache,
$isSimpleMode
);

$config->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS);

$config->setEntityNamespaces(
[
'ChamiloUserBundle' => 'Chamilo\UserBundle\Entity',
'ChamiloCoreBundle' => 'Chamilo\CoreBundle\Entity',
'ChamiloCourseBundle' => 'Chamilo\CourseBundle\Entity',
'ChamiloSkillBundle' => 'Chamilo\SkillBundle\Entity',
'ChamiloTicketBundle' => 'Chamilo\TicketBundle\Entity',
'ChamiloPluginBundle' => 'Chamilo\PluginBundle\Entity',
]
);

return $config;
}

Expand Down

0 comments on commit ada61aa

Please sign in to comment.