14
14
use Doctrine \Common \Util \Debug ;
15
15
use Doctrine \DBAL \Exception as DBALException ;
16
16
use Doctrine \Migrations \Exception \MigrationException ;
17
+ use Doctrine \ORM \ORMException ;
17
18
use Doctrine \ORM \Tools \ToolsException ;
18
19
use Doctrine \Persistence \Mapping \ClassMetadata ;
19
20
use Neos \Flow \Annotations as Flow ;
@@ -200,7 +201,7 @@ public function updateCommand(bool $unsafeMode = false, string $output = null):
200
201
* @param boolean $dumpMappingData If set, the mapping data will be output
201
202
* @param string|null $entityClassName If given, the mapping data for just this class will be output
202
203
* @return void
203
- * @throws \Doctrine\ORM\ ORMException
204
+ * @throws ORMException
204
205
* @see neos.flow:doctrine:validate
205
206
*/
206
207
public function entityStatusCommand (bool $ dumpMappingData = false , string $ entityClassName = null ): void
@@ -282,22 +283,24 @@ public function dqlCommand(int $depth = 3, string $hydrationMode = 'array', int
282
283
* available, executed and pending migrations.
283
284
*
284
285
* @param boolean $showMigrations Output a list of all migrations and their status
286
+ * @param string|null $migrationFolder Provide alternative platform folder name (as in "Mysql"), otherwise configured connection is used.
285
287
* @return void
286
- * @throws StopCommandException
287
288
* @throws DBALException
289
+ * @throws StopCommandException
288
290
* @see neos.flow:doctrine:migrate
289
291
* @see neos.flow:doctrine:migrationexecute
290
292
* @see neos.flow:doctrine:migrationgenerate
291
293
* @see neos.flow:doctrine:migrationversion
292
294
*/
293
- public function migrationStatusCommand (bool $ showMigrations = false ): void
295
+ public function migrationStatusCommand (bool $ showMigrations = false , ? string $ migrationFolder = null ): void
294
296
{
295
297
if (!$ this ->isDatabaseConfigured ()) {
296
298
$ this ->outputLine ('Doctrine migration status not available, the driver and host backend options are not set in /Configuration/Settings.yaml. ' );
297
299
$ this ->quit (1 );
298
300
}
299
301
300
- $ this ->outputLine ($ this ->doctrineService ->getFormattedMigrationStatus ($ showMigrations ));
302
+ $ this ->maybeOutputMigrationFolderWarning ($ migrationFolder );
303
+ $ this ->outputLine ($ this ->doctrineService ->getFormattedMigrationStatus ($ showMigrations , $ migrationFolder ));
301
304
}
302
305
303
306
/**
@@ -310,14 +313,15 @@ public function migrationStatusCommand(bool $showMigrations = false): void
310
313
* @param string|null $output A file to write SQL to, instead of executing it
311
314
* @param boolean $dryRun Whether to do a dry run or not
312
315
* @param boolean $quiet If set, only the executed migration versions will be output, one per line
316
+ * @param string|null $migrationFolder Provide alternative platform folder name (as in "Mysql"), otherwise configured connection is used.
313
317
* @return void
314
318
* @throws StopCommandException
315
319
* @see neos.flow:doctrine:migrationstatus
316
320
* @see neos.flow:doctrine:migrationexecute
317
321
* @see neos.flow:doctrine:migrationgenerate
318
322
* @see neos.flow:doctrine:migrationversion
319
323
*/
320
- public function migrateCommand (string $ version = 'latest ' , string $ output = null , bool $ dryRun = false , bool $ quiet = false ): void
324
+ public function migrateCommand (string $ version = 'latest ' , string $ output = null , bool $ dryRun = false , bool $ quiet = false , ? string $ migrationFolder = null ): void
321
325
{
322
326
if (!$ this ->isDatabaseConfigured ()) {
323
327
$ this ->outputLine ('Doctrine migration not possible, the driver and host backend options are not set in /Configuration/Settings.yaml. ' );
@@ -328,8 +332,9 @@ public function migrateCommand(string $version = 'latest', string $output = null
328
332
$ this ->outputLine (sprintf ('The path "%s" is not writeable! ' , dirname ($ output )));
329
333
}
330
334
335
+ $ this ->maybeOutputMigrationFolderWarning ($ migrationFolder );
331
336
try {
332
- $ result = $ this ->doctrineService ->executeMigrations ($ this ->normalizeVersion ($ version ), $ output , $ dryRun , $ quiet );
337
+ $ result = $ this ->doctrineService ->executeMigrations ($ this ->normalizeVersion ($ version ), $ output , $ dryRun , $ quiet, $ migrationFolder );
333
338
if ($ result !== '' && $ quiet === false ) {
334
339
$ this ->outputLine ($ result );
335
340
}
@@ -357,14 +362,15 @@ protected function emitAfterDatabaseMigration(): void
357
362
* @param string $direction Whether to execute the migration up (default) or down
358
363
* @param string|null $output A file to write SQL to, instead of executing it
359
364
* @param boolean $dryRun Whether to do a dry run or not
365
+ * @param string|null $migrationFolder Provide alternative platform folder name (as in "Mysql"), otherwise configured connection is used.
360
366
* @return void
361
367
* @throws StopCommandException
362
368
* @see neos.flow:doctrine:migrate
363
369
* @see neos.flow:doctrine:migrationstatus
364
370
* @see neos.flow:doctrine:migrationgenerate
365
371
* @see neos.flow:doctrine:migrationversion
366
372
*/
367
- public function migrationExecuteCommand (string $ version , string $ direction = 'up ' , string $ output = null , bool $ dryRun = false ): void
373
+ public function migrationExecuteCommand (string $ version , string $ direction = 'up ' , string $ output = null , bool $ dryRun = false , ? string $ migrationFolder = null ): void
368
374
{
369
375
if (!$ this ->isDatabaseConfigured ()) {
370
376
$ this ->outputLine ('Doctrine migration not possible, the driver and host backend options are not set in /Configuration/Settings.yaml. ' );
@@ -375,8 +381,9 @@ public function migrationExecuteCommand(string $version, string $direction = 'up
375
381
$ this ->outputLine (sprintf ('The path "%s" is not writeable! ' , dirname ($ output )));
376
382
}
377
383
384
+ $ this ->maybeOutputMigrationFolderWarning ($ migrationFolder );
378
385
try {
379
- $ this ->outputLine ($ this ->doctrineService ->executeMigration ($ this ->normalizeVersion ($ version ), $ direction , $ output , $ dryRun ));
386
+ $ this ->outputLine ($ this ->doctrineService ->executeMigration ($ this ->normalizeVersion ($ version ), $ direction , $ output , $ dryRun, $ migrationFolder ));
380
387
} catch (\Exception $ exception ) {
381
388
$ this ->handleException ($ exception );
382
389
}
@@ -391,15 +398,17 @@ public function migrationExecuteCommand(string $version, string $direction = 'up
391
398
* @param string $version The migration to execute
392
399
* @param boolean $add The migration to mark as migrated
393
400
* @param boolean $delete The migration to mark as not migrated
401
+ * @param string|null $migrationFolder Provide alternative platform folder name (as in "Mysql"), otherwise configured connection is used.
394
402
* @return void
395
- * @throws StopCommandException
396
403
* @throws DBALException
404
+ * @throws FilesException
405
+ * @throws StopCommandException
397
406
* @see neos.flow:doctrine:migrate
398
407
* @see neos.flow:doctrine:migrationstatus
399
408
* @see neos.flow:doctrine:migrationexecute
400
409
* @see neos.flow:doctrine:migrationgenerate
401
410
*/
402
- public function migrationVersionCommand (string $ version , bool $ add = false , bool $ delete = false ): void
411
+ public function migrationVersionCommand (string $ version , bool $ add = false , bool $ delete = false , ? string $ migrationFolder = null ): void
403
412
{
404
413
if (!$ this ->isDatabaseConfigured ()) {
405
414
$ this ->outputLine ('Doctrine migration not possible, the driver and host backend options are not set in /Configuration/Settings.yaml. ' );
@@ -410,8 +419,9 @@ public function migrationVersionCommand(string $version, bool $add = false, bool
410
419
throw new \InvalidArgumentException ('You must specify whether you want to --add or --delete the specified version. ' );
411
420
}
412
421
422
+ $ this ->maybeOutputMigrationFolderWarning ($ migrationFolder );
413
423
try {
414
- $ this ->doctrineService ->markAsMigrated ($ this ->normalizeVersion ($ version ), $ add ?: false );
424
+ $ this ->doctrineService ->markAsMigrated ($ this ->normalizeVersion ($ version ), $ add ?: false , $ migrationFolder );
415
425
} catch (MigrationException $ exception ) {
416
426
$ this ->outputLine ($ exception ->getMessage ());
417
427
$ this ->quit (1 );
@@ -440,6 +450,7 @@ public function migrationVersionCommand(string $version, bool $add = false, bool
440
450
* @param boolean $diffAgainstCurrent Whether to base the migration on the current schema structure
441
451
* @param string|null $filterExpression Only include tables/sequences matching the filter expression regexp
442
452
* @param boolean $force Generate migrations even if there are migrations left to execute
453
+ * @param string|null $migrationFolder Provide alternative platform folder name (as in "Mysql"), otherwise configured connection is used.
443
454
* @return void
444
455
* @throws DBALException
445
456
* @throws StopCommandException
@@ -449,14 +460,14 @@ public function migrationVersionCommand(string $version, bool $add = false, bool
449
460
* @see neos.flow:doctrine:migrationexecute
450
461
* @see neos.flow:doctrine:migrationversion
451
462
*/
452
- public function migrationGenerateCommand (bool $ diffAgainstCurrent = true , string $ filterExpression = null , bool $ force = false ): void
463
+ public function migrationGenerateCommand (bool $ diffAgainstCurrent = true , string $ filterExpression = null , bool $ force = false , ? string $ migrationFolder = null ): void
453
464
{
454
465
if (!$ this ->isDatabaseConfigured ()) {
455
466
$ this ->outputLine ('Doctrine migration generation has been SKIPPED, the driver and host backend options are not set in /Configuration/Settings.yaml. ' );
456
467
$ this ->quit (1 );
457
468
}
458
469
459
- $ migrationStatus = $ this ->doctrineService ->getMigrationStatus ();
470
+ $ migrationStatus = $ this ->doctrineService ->getMigrationStatus ($ migrationFolder );
460
471
if ($ force === false && $ migrationStatus ['new ' ] !== 0 ) {
461
472
$ this ->outputLine ('There are %d new migrations available. To avoid duplication those should be executed via `doctrine:migrate` before creating additional migrations. ' , [$ migrationStatus ['new ' ]]);
462
473
$ this ->quit (1 );
@@ -474,7 +485,9 @@ public function migrationGenerateCommand(bool $diffAgainstCurrent = true, string
474
485
}
475
486
}
476
487
477
- [$ status , $ migrationClassPathAndFilename ] = $ this ->doctrineService ->generateMigration ($ diffAgainstCurrent , $ filterExpression );
488
+ $ this ->maybeOutputMigrationFolderWarning ($ migrationFolder );
489
+
490
+ [$ status , $ migrationClassPathAndFilename ] = $ this ->doctrineService ->generateMigration ($ diffAgainstCurrent , $ filterExpression , $ migrationFolder );
478
491
479
492
$ this ->outputLine ('<info>%s</info> ' , [$ status ]);
480
493
$ this ->outputLine ();
@@ -495,18 +508,20 @@ public function migrationGenerateCommand(bool $diffAgainstCurrent = true, string
495
508
$ selectedPackage = $ this ->output ->select ('Do you want to move the migration to one of these packages? ' , $ choices , $ choices [0 ]);
496
509
$ this ->outputLine ();
497
510
511
+ $ migrationPlatformFolderPart = $ migrationFolder ?? $ this ->doctrineService ->getMigrationFolderName ();
512
+
498
513
if ($ selectedPackage !== $ choices [0 ]) {
499
- /** @var Package $selectedPackage */
500
514
$ selectedPackage = $ packages [$ selectedPackage ];
501
- $ targetPathAndFilename = Files::concatenatePaths ([$ selectedPackage ->getPackagePath (), 'Migrations ' , $ this ->doctrineService ->getDatabasePlatformName (), basename ($ migrationClassPathAndFilename )]);
515
+ /** @var Package $selectedPackage */
516
+ $ targetPathAndFilename = Files::concatenatePaths ([$ selectedPackage ->getPackagePath (), 'Migrations ' , $ migrationPlatformFolderPart , basename ($ migrationClassPathAndFilename )]);
502
517
Files::createDirectoryRecursively (dirname ($ targetPathAndFilename ));
503
518
rename ($ migrationClassPathAndFilename , $ targetPathAndFilename );
504
519
$ this ->outputLine ('The migration was moved to: <comment>%s</comment> ' , [substr ($ targetPathAndFilename , strlen (FLOW_PATH_ROOT ))]);
505
520
$ this ->outputLine ();
506
521
$ this ->outputLine ('Next Steps: ' );
507
522
} else {
508
523
$ this ->outputLine ('Next Steps: ' );
509
- $ this ->outputLine (sprintf ('- Move <comment>%s</comment> to YourPackage/<comment>Migrations/%s/</comment> ' , $ migrationClassPathAndFilename , $ this -> doctrineService -> getDatabasePlatformName () ));
524
+ $ this ->outputLine (sprintf ('- Move <comment>%s</comment> to YourPackage/<comment>Migrations/%s/</comment> ' , $ migrationClassPathAndFilename , $ migrationPlatformFolderPart ));
510
525
}
511
526
$ this ->outputLine ('- Review and adjust the generated migration. ' );
512
527
$ this ->outputLine ('- (optional) execute the migration using <comment>%s doctrine:migrate</comment> ' , [$ this ->getFlowInvocationString ()]);
@@ -553,4 +568,11 @@ private function normalizeVersion(string $version): string
553
568
}
554
569
return sprintf ('Neos\Flow\Persistence\Doctrine\Migrations\Version%s ' , $ version );
555
570
}
571
+
572
+ private function maybeOutputMigrationFolderWarning (?string $ migrationFolder = null )
573
+ {
574
+ if ($ migrationFolder !== null ) {
575
+ $ this ->outputLine ('<comment>Migration folder override is in effect, migration files are not searched in folder matching the configured connection but in ...Migrations/%s/</comment> ' , [$ migrationFolder ]);
576
+ }
577
+ }
556
578
}
0 commit comments