@@ -83,11 +83,11 @@ class MysqlController extends Controller
8383 */
8484 public function options ($ actionId )
8585 {
86- switch ($ actionId ) {
86+ switch (true ) {
8787 case $ actionId == 'dump ' :
8888 $ additionalOptions = ['noDataTables ' , 'dryRun ' ];
8989 break ;
90- case $ actionId = 'import ' ;
90+ case $ actionId == 'import ' ;
9191 $ additionalOptions = ['cache ' , 'dryRun ' ];
9292 break ;
9393 case $ actionId == 'export ' :
@@ -96,6 +96,7 @@ public function options($actionId)
9696 default :
9797 $ additionalOptions = [];
9898 }
99+
99100 return array_merge (
100101 parent ::options ($ actionId ),
101102 ['verbose ' , 'db ' , 'outputPath ' ], // global options
@@ -272,7 +273,10 @@ public function actionDestroy(
272273 */
273274 public function actionExport ()
274275 {
275- $ fileName = $ this ->getFilePrefix () . "_data.sql " ;
276+ $ latestMigrationId = $ this ->getLatestMigrationId ();
277+ $ date = date ('ymd_His ' );
278+ $ fileName = "{$ latestMigrationId }x_export_at_ {$ date }.sql " ;
279+
276280 $ db = \Yii::$ app ->get ($ this ->db );
277281 $ opts = CliHelper::getMysqlOptsFromDsn ($ db );
278282
@@ -451,4 +455,16 @@ private function getFilePrefix()
451455 return 'm ' . gmdate ('ymd_His ' ) . '_ ' . \Yii::$ app ->id . $ sanitizedVersion ;
452456 }
453457
458+ /**
459+ * @return mixed return the last applied migration id (m123456_123456)
460+ */
461+ private function getLatestMigrationId (){
462+ $ command = new Command ();
463+ $ command ->setCommand ('yii migrate/history 1 ' );
464+ $ command ->execute ();
465+ $ output = $ command ->getOutput ();
466+ preg_match ('/m[0-9_]{6}_[0-9_]{6}/ ' , $ output , $ matches );
467+ $ latestMigrationId = $ matches [0 ];
468+ return $ latestMigrationId ;
469+ }
454470}
0 commit comments