Browse Source

Fixes #13787: Added `yii\db\Migration::$maxSqlOutputLength` that allows limiting number of characters for outputting SQL

tags/2.0.13
Thiago Talma 8 years ago committed by Alexander Makarov
parent
commit
1d062100b6
No known key found for this signature in database
GPG Key ID: 3617B79C6A325E4A
  1. 2
      framework/CHANGELOG.md
  2. 14
      framework/db/Migration.php

2
framework/CHANGELOG.md

@ -7,7 +7,7 @@ Yii Framework 2 Change Log
- Bug #14248: `yii\console\controllers\MessageController` no longer outputs colorized filenames when console does not support text colorization (PowerGamer1)
- Bug #14264: Fixed a bug where `yii\log\Logger::calculateTimings()` was not accepting messages with array tokens (bizley)
- Chg #14201: `yii\console\controllers\MessageController::extractMessagesFromTokens()` is now protected (faenir)
- Enh #13787: Added `yii\db\Migration::$maxSqlOutputLength` that allows limiting number of characters for outputting SQL (thiagotalma)
2.0.12 June 05, 2017
--------------------

14
framework/db/Migration.php

@ -9,6 +9,7 @@ namespace yii\db;
use yii\base\Component;
use yii\di\Instance;
use yii\helpers\StringHelper;
/**
* Migration is the base class for representing a database migration.
@ -65,6 +66,12 @@ class Migration extends Component implements MigrationInterface
*/
public $db = 'db';
/**
* @var int max number of characters of the SQL outputted. Useful for reduction of long statements and making
* console output more compact.
* @since 2.0.13
*/
public $maxSqlOutputLength;
/**
* Initializes the migration.
@ -198,7 +205,12 @@ class Migration extends Component implements MigrationInterface
*/
public function execute($sql, $params = [])
{
echo " > execute SQL: $sql ...";
$sqlOutput = $sql;
if ($this->maxSqlOutputLength !== null) {
$sqlOutput = StringHelper::truncate($sql, $this->maxSqlOutputLength, '[... hidden]');
}
echo " > execute SQL: $sqlOutput ...";
$time = microtime(true);
$this->db->createCommand($sql)->bindValues($params)->execute();
echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";

Loading…
Cancel
Save