Fixes #14877: Disabled profiling on connection opening when profiling is disabled

This commit is contained in:
Nelson J Morais
2017-10-19 23:28:05 +01:00
committed by Alexander Makarov
parent b5e0903435
commit 980cfde0f1
2 changed files with 16 additions and 4 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.13 under development
------------------------
- Enh #14877: Disabled profiling on connection opening when profiling is disabled (njasm)
- Enh #14967: Added Armenian Translations (gevorgmansuryan)
- Enh #4479: Implemented REST filters (klimov-paul)
- Bug #14134: Fixed multiple `validateAttribute()` calls when `scenarios()` returns duplicate attributes (krukru)

View File

@ -382,7 +382,7 @@ class Connection extends Component
*/
public $enableLogging = true;
/**
* @var bool whether to enable profiling of database queries. Defaults to true.
* @var bool whether to enable profiling of opening database connection and database queries. Defaults to true.
* You may want to disable this option in a production environment to gain performance
* if you do not need the information being logged.
* @since 2.0.12
@ -574,15 +574,26 @@ class Connection extends Component
if (empty($this->dsn)) {
throw new InvalidConfigException('Connection::dsn cannot be empty.');
}
$token = 'Opening DB connection: ' . $this->dsn;
$enableProfiling = $this->enableProfiling;
try {
Yii::info($token, __METHOD__);
Yii::beginProfile($token, __METHOD__);
if ($enableProfiling) {
Yii::beginProfile($token, __METHOD__);
}
$this->pdo = $this->createPdoInstance();
$this->initConnection();
Yii::endProfile($token, __METHOD__);
if ($enableProfiling) {
Yii::endProfile($token, __METHOD__);
}
} catch (\PDOException $e) {
Yii::endProfile($token, __METHOD__);
if ($enableProfiling) {
Yii::endProfile($token, __METHOD__);
}
throw new Exception($e->getMessage(), $e->errorInfo, (int) $e->getCode(), $e);
}
}