Browse Source

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

tags/2.0.13
Nelson J Morais 7 years ago committed by Alexander Makarov
parent
commit
980cfde0f1
  1. 1
      framework/CHANGELOG.md
  2. 19
      framework/db/Connection.php

1
framework/CHANGELOG.md

@ -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)

19
framework/db/Connection.php

@ -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);
}
}

Loading…
Cancel
Save