2626 * Generates migration file based on the existing database table and previous migrations.
2727 *
2828 * @author Paweł Bizley Brzozowski
29- * @version 2.9.4
29+ * @version 2.9.5
3030 * @license Apache 2.0
3131 * https://github.com/bizley/yii2-migration
3232 */
3333class MigrationController extends Controller
3434{
35- protected $ version = '2.9.4 ' ;
35+ protected $ version = '2.9.5 ' ;
3636
3737 /**
3838 * @var string Default command action.
@@ -252,6 +252,7 @@ public function init()
252252 }
253253
254254 protected $ workingPath ;
255+ protected $ workingNamespace ;
255256
256257 /**
257258 * This method is invoked right before an action is to be executed (after all possible filters).
@@ -280,8 +281,10 @@ public function beforeAction($action)
280281 $ this ->workingPath = $ this ->preparePathDirectory (
281282 '@ ' . FileHelper::normalizePath ($ namespace , '/ ' )
282283 );
284+ $ this ->workingNamespace = $ namespace ;
283285 }
284286 }
287+ unset($ namespace );
285288 } elseif ($ this ->migrationPath !== null ) {
286289 if (!is_array ($ this ->migrationPath )) {
287290 $ this ->migrationPath = [$ this ->migrationPath ];
@@ -455,8 +458,10 @@ public function actionCreate($table)
455458 $ tables = $ arrangedTables ['order ' ];
456459 $ suppressForeignKeys = $ arrangedTables ['suppressForeignKeys ' ];
457460
458- if (count ($ suppressForeignKeys )
459- && TableStructure::identifySchema (get_class ($ this ->db ->schema )) === TableStructure::SCHEMA_SQLITE ) {
461+ if (
462+ count ($ suppressForeignKeys )
463+ && TableStructure::identifySchema (get_class ($ this ->db ->schema )) === TableStructure::SCHEMA_SQLITE
464+ ) {
460465 $ this ->stdout (
461466 "WARNING! \n > Creating provided tables in batch requires manual migration! \n" ,
462467 Console::FG_RED
@@ -523,7 +528,7 @@ public function actionCreate($table)
523528 $ this ->createMigrationHistoryTable ();
524529 }
525530
526- $ this ->addMigrationHistory ($ className , $ this ->migrationNamespace );
531+ $ this ->addMigrationHistory ($ className , $ this ->workingNamespace );
527532 }
528533
529534 $ this ->stdout ("\n" );
@@ -544,11 +549,19 @@ public function actionCreate($table)
544549 );
545550 $ file = $ this ->workingPath . DIRECTORY_SEPARATOR . $ className . '.php ' ;
546551
547- if ($ this ->generateFile ($ file , $ this ->view ->renderFile (Yii::getAlias ($ this ->templateFileForeignKey ), [
548- 'fks ' => $ postponedForeignKeys ,
549- 'className ' => $ className ,
550- 'namespace ' => $ this ->migrationNamespace
551- ])) === false ) {
552+ if (
553+ $ this ->generateFile (
554+ $ file ,
555+ $ this ->view ->renderFile (
556+ Yii::getAlias ($ this ->templateFileForeignKey ),
557+ [
558+ 'fks ' => $ postponedForeignKeys ,
559+ 'className ' => $ className ,
560+ 'namespace ' => $ this ->migrationNamespace
561+ ]
562+ )
563+ ) === false
564+ ) {
552565 $ this ->stdout (
553566 "ERROR! \n > Migration file for foreign keys can not be generated! \n\n" ,
554567 Console::FG_RED
@@ -561,7 +574,7 @@ public function actionCreate($table)
561574 $ this ->stdout (" > Saved as ' {$ file }' \n" );
562575
563576 if ($ this ->fixHistory ) {
564- $ this ->addMigrationHistory ($ className , $ this ->migrationNamespace );
577+ $ this ->addMigrationHistory ($ className , $ this ->workingNamespace );
565578 }
566579 }
567580
@@ -681,7 +694,7 @@ public function actionUpdate($table)
681694 $ this ->createMigrationHistoryTable ();
682695 }
683696
684- $ this ->addMigrationHistory ($ className , $ this ->migrationNamespace );
697+ $ this ->addMigrationHistory ($ className , $ this ->workingNamespace );
685698 }
686699 }
687700
0 commit comments