mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 22:32:40 +08:00
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:
committed by
Alexander Makarov
parent
652d05f0b8
commit
3ea671454c
@ -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)
|
||||
|
||||
@ -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.');
|
||||
|
||||
Reference in New Issue
Block a user