mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Fixes #14543: Throw exception when trying to create migration longer than 255 symbols
This commit is contained in:

committed by
Alexander Makarov

parent
7e7faeebd1
commit
614fb52c45
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
||||
2.0.13 under development
|
||||
------------------------
|
||||
|
||||
- Bug #14543: Throw exception when trying to create migration longer than 255 symbols (dmirogin)
|
||||
- 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)
|
||||
|
@ -31,6 +31,11 @@ abstract class BaseMigrateController extends Controller
|
||||
*/
|
||||
const BASE_MIGRATION = 'm000000_000000_base';
|
||||
|
||||
/**
|
||||
* Maximum length of migration name
|
||||
*/
|
||||
const MAX_NAME_LENGTH = 180;
|
||||
|
||||
/**
|
||||
* @var string the default command action.
|
||||
*/
|
||||
@ -191,6 +196,11 @@ abstract class BaseMigrateController extends Controller
|
||||
$applied = 0;
|
||||
if ($this->confirm('Apply the above ' . ($n === 1 ? 'migration' : 'migrations') . '?')) {
|
||||
foreach ($migrations as $migration) {
|
||||
if (strlen($migration) > static::MAX_NAME_LENGTH) {
|
||||
$this->stdout("\nThe migration name is too long. The rest of the migrations are canceled.\n", Console::FG_RED);
|
||||
return ExitCode::UNSPECIFIED_ERROR;
|
||||
}
|
||||
|
||||
if (!$this->migrateUp($migration)) {
|
||||
$this->stdout("\n$applied from $n " . ($applied === 1 ? 'migration was' : 'migrations were') . " applied.\n", Console::FG_RED);
|
||||
$this->stdout("\nMigration failed. The rest of the migrations are canceled.\n", Console::FG_RED);
|
||||
@ -622,6 +632,11 @@ abstract class BaseMigrateController extends Controller
|
||||
}
|
||||
|
||||
list($namespace, $className) = $this->generateClassName($name);
|
||||
// Abort if name is too long
|
||||
if (strlen($className) > static::MAX_NAME_LENGTH) {
|
||||
throw new Exception('The migration name is too long.');
|
||||
}
|
||||
|
||||
$migrationPath = $this->findMigrationPath($namespace);
|
||||
|
||||
$file = $migrationPath . DIRECTORY_SEPARATOR . $className . '.php';
|
||||
|
@ -144,6 +144,27 @@ class MigrateControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdatingLongNamedMigration()
|
||||
{
|
||||
$this->createMigration(str_repeat('a', 180));
|
||||
|
||||
$result = $this->runMigrateControllerAction('up');
|
||||
|
||||
$this->assertContains('The migration name is too long. The rest of the migrations are canceled.', $result);
|
||||
}
|
||||
|
||||
public function testCreateLongNamedMigration()
|
||||
{
|
||||
$migrationName = str_repeat('a', 180);
|
||||
|
||||
$this->expectException('yii\console\Exception');
|
||||
$this->expectExceptionMessage('The migration name is too long.');
|
||||
|
||||
$controller = $this->createMigrateController([]);
|
||||
$params[0] = $migrationName;
|
||||
$controller->run('create', $params);
|
||||
}
|
||||
|
||||
public function testGenerateDropMigration()
|
||||
{
|
||||
$tables = [
|
||||
|
Reference in New Issue
Block a user