@@ -270,6 +270,7 @@ public function init(): void
270270 }
271271
272272 protected $ workingPath ;
273+ protected $ workingNamespace ;
273274
274275 /**
275276 * This method is invoked right before an action is to be executed (after all possible filters).
@@ -297,8 +298,10 @@ public function beforeAction($action): bool // BC declaration
297298 $ this ->workingPath = $ this ->preparePathDirectory (
298299 '@ ' . FileHelper::normalizePath ($ namespace , '/ ' )
299300 );
301+ $ this ->workingNamespace = $ namespace ;
300302 }
301303 }
304+ unset($ namespace );
302305 } elseif ($ this ->migrationPath !== null ) {
303306 if (!is_array ($ this ->migrationPath )) {
304307 $ this ->migrationPath = [$ this ->migrationPath ];
@@ -472,8 +475,10 @@ public function actionCreate(string $table): int
472475 $ tables = $ arrangedTables ['order ' ];
473476 $ suppressForeignKeys = $ arrangedTables ['suppressForeignKeys ' ];
474477
475- if (count ($ suppressForeignKeys )
476- && TableStructure::identifySchema (get_class ($ this ->db ->schema )) === TableStructure::SCHEMA_SQLITE ) {
478+ if (
479+ count ($ suppressForeignKeys )
480+ && TableStructure::identifySchema (get_class ($ this ->db ->schema )) === TableStructure::SCHEMA_SQLITE
481+ ) {
477482 $ this ->stdout (
478483 "WARNING! \n > Creating provided tables in batch requires manual migration! \n" ,
479484 Console::FG_RED
@@ -541,7 +546,7 @@ public function actionCreate(string $table): int
541546 $ this ->createMigrationHistoryTable ();
542547 }
543548
544- $ this ->addMigrationHistory ($ className , $ this ->migrationNamespace );
549+ $ this ->addMigrationHistory ($ className , $ this ->workingNamespace );
545550 }
546551
547552 $ this ->stdout ("\n" );
@@ -562,11 +567,19 @@ public function actionCreate(string $table): int
562567 );
563568 $ file = $ this ->workingPath . DIRECTORY_SEPARATOR . $ className . '.php ' ;
564569
565- if ($ this ->generateFile ($ file , $ this ->view ->renderFile (Yii::getAlias ($ this ->templateFileForeignKey ), [
566- 'fks ' => $ postponedForeignKeys ,
567- 'className ' => $ className ,
568- 'namespace ' => $ this ->migrationNamespace
569- ])) === false ) {
570+ if (
571+ $ this ->generateFile (
572+ $ file ,
573+ $ this ->view ->renderFile (
574+ Yii::getAlias ($ this ->templateFileForeignKey ),
575+ [
576+ 'fks ' => $ postponedForeignKeys ,
577+ 'className ' => $ className ,
578+ 'namespace ' => $ this ->migrationNamespace
579+ ]
580+ )
581+ ) === false
582+ ) {
570583 $ this ->stdout (
571584 "ERROR! \n > Migration file for foreign keys can not be generated! \n\n" ,
572585 Console::FG_RED
@@ -579,7 +592,7 @@ public function actionCreate(string $table): int
579592 $ this ->stdout (" > Saved as ' {$ file }' \n" );
580593
581594 if ($ this ->fixHistory ) {
582- $ this ->addMigrationHistory ($ className , $ this ->migrationNamespace );
595+ $ this ->addMigrationHistory ($ className , $ this ->workingNamespace );
583596 }
584597 }
585598
@@ -697,7 +710,7 @@ public function actionUpdate(string $table): int
697710 $ this ->createMigrationHistoryTable ();
698711 }
699712
700- $ this ->addMigrationHistory ($ className , $ this ->migrationNamespace );
713+ $ this ->addMigrationHistory ($ className , $ this ->workingNamespace );
701714 }
702715 }
703716
0 commit comments