Fixes #12133: Fixed getDbTargets() function in yii\log\migrations\m141106_185632_log_init that would create a log table correctly

This commit is contained in:
Sergei Malmygin
2016-12-13 12:43:45 +05:00
committed by Alexander Makarov
parent 652d05f0b8
commit 3ea671454c
2 changed files with 12 additions and 2 deletions

View File

@ -46,6 +46,7 @@ Yii Framework 2 Change Log
- Bug #13277: Fixed invalid parsing of `--` ("End of Options" special argument) in CLI (rugabarbo)
- Bug #13309: Fixes incorrect console width/height detecting with using Stty on Mac (nowm)
- Bug #13326: Fixed wrong background color generation in `BaseConsole::renderColoredString()` (nowm, silverfire)
- Bug #12133: Fixed `getDbTargets()` function in `yii\log\migrations\m141106_185632_log_init` that would create a log table correctly (bumstik)
- Enh #475: Added Bash and Zsh completion support for the `./yii` command (cebe, silverfire)
- Enh #6242: Access to validator in inline validation (arogachev)
- Enh #6373: Introduce `yii\db\Query::emulateExecution()` to force returning an empty result for a query (klimov-paul)

View File

@ -22,7 +22,7 @@ use yii\log\DbTarget;
class m141106_185632_log_init extends Migration
{
/**
* @var DbTarget[]
* @var DbTarget[] Targets to create log table for
*/
private $dbTargets = [];
@ -35,11 +35,20 @@ class m141106_185632_log_init extends Migration
if ($this->dbTargets === []) {
$log = Yii::$app->getLog();
$usedTargets = [];
foreach ($log->targets as $target) {
if ($target instanceof DbTarget) {
$currentTarget = [
$target->db,
$target->logTable,
];
if (!in_array($currentTarget, $usedTargets, true)) {
// do not create same table twice
$usedTargets[] = $currentTarget;
$this->dbTargets[] = $target;
}
}
}
if ($this->dbTargets === []) {
throw new InvalidConfigException('You should configure "log" component to use one or more database targets before executing this migration.');