mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 06:11:35 +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
@ -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';
|
||||
|
Reference in New Issue
Block a user