Skip to content

Commit 1d54ec0

Browse files
authored
Merge pull request #2637 from neos/dependabot/composer/doctrine/dbal-tw-3.2
!!! FEATURE: update to `doctrine/dbal` version 3
2 parents b92e00a + 11e2348 commit 1d54ec0

File tree

79 files changed

+469
-734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+469
-734
lines changed

Neos.Flow/Classes/Cache/CacheManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ public function getSimpleCache(string $identifier): CacheInterface
218218
*
219219
* @param string $identifier
220220
* @return CacheItemPoolInterface
221+
* @throws NoSuchCacheException
221222
*/
222223
public function getCacheItemPool(string $identifier): CacheItemPoolInterface
223224
{

Neos.Flow/Classes/Command/DatabaseCommandController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ protected function convertToCharacterSetAndCollation(string $characterSet, strin
124124

125125
$statements[] = 'ALTER DATABASE ' . $this->connection->quoteIdentifier($this->persistenceSettings['backendOptions']['dbname']) . ' CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
126126

127-
$tableNames = $this->connection->getSchemaManager()?->listTableNames() ?? [];
127+
$tableNames = $this->connection->createSchemaManager()->listTableNames() ?? [];
128128
foreach ($tableNames as $tableName) {
129129
$statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' DEFAULT CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
130130
$statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;

Neos.Flow/Classes/Command/DoctrineCommandController.php

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Common\Util\Debug;
1515
use Doctrine\DBAL\Exception as DBALException;
1616
use Doctrine\Migrations\Exception\MigrationException;
17+
use Doctrine\ORM\ORMException;
1718
use Doctrine\ORM\Tools\ToolsException;
1819
use Doctrine\Persistence\Mapping\ClassMetadata;
1920
use Neos\Flow\Annotations as Flow;
@@ -200,7 +201,7 @@ public function updateCommand(bool $unsafeMode = false, string $output = null):
200201
* @param boolean $dumpMappingData If set, the mapping data will be output
201202
* @param string|null $entityClassName If given, the mapping data for just this class will be output
202203
* @return void
203-
* @throws \Doctrine\ORM\ORMException
204+
* @throws ORMException
204205
* @see neos.flow:doctrine:validate
205206
*/
206207
public function entityStatusCommand(bool $dumpMappingData = false, string $entityClassName = null): void
@@ -282,22 +283,24 @@ public function dqlCommand(int $depth = 3, string $hydrationMode = 'array', int
282283
* available, executed and pending migrations.
283284
*
284285
* @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.
285287
* @return void
286-
* @throws StopCommandException
287288
* @throws DBALException
289+
* @throws StopCommandException
288290
* @see neos.flow:doctrine:migrate
289291
* @see neos.flow:doctrine:migrationexecute
290292
* @see neos.flow:doctrine:migrationgenerate
291293
* @see neos.flow:doctrine:migrationversion
292294
*/
293-
public function migrationStatusCommand(bool $showMigrations = false): void
295+
public function migrationStatusCommand(bool $showMigrations = false, ?string $migrationFolder = null): void
294296
{
295297
if (!$this->isDatabaseConfigured()) {
296298
$this->outputLine('Doctrine migration status not available, the driver and host backend options are not set in /Configuration/Settings.yaml.');
297299
$this->quit(1);
298300
}
299301

300-
$this->outputLine($this->doctrineService->getFormattedMigrationStatus($showMigrations));
302+
$this->maybeOutputMigrationFolderWarning($migrationFolder);
303+
$this->outputLine($this->doctrineService->getFormattedMigrationStatus($showMigrations, $migrationFolder));
301304
}
302305

303306
/**
@@ -310,14 +313,15 @@ public function migrationStatusCommand(bool $showMigrations = false): void
310313
* @param string|null $output A file to write SQL to, instead of executing it
311314
* @param boolean $dryRun Whether to do a dry run or not
312315
* @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.
313317
* @return void
314318
* @throws StopCommandException
315319
* @see neos.flow:doctrine:migrationstatus
316320
* @see neos.flow:doctrine:migrationexecute
317321
* @see neos.flow:doctrine:migrationgenerate
318322
* @see neos.flow:doctrine:migrationversion
319323
*/
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
321325
{
322326
if (!$this->isDatabaseConfigured()) {
323327
$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
328332
$this->outputLine(sprintf('The path "%s" is not writeable!', dirname($output)));
329333
}
330334

335+
$this->maybeOutputMigrationFolderWarning($migrationFolder);
331336
try {
332-
$result = $this->doctrineService->executeMigrations($this->normalizeVersion($version), $output, $dryRun, $quiet);
337+
$result = $this->doctrineService->executeMigrations($this->normalizeVersion($version), $output, $dryRun, $quiet, $migrationFolder);
333338
if ($result !== '' && $quiet === false) {
334339
$this->outputLine($result);
335340
}
@@ -357,14 +362,15 @@ protected function emitAfterDatabaseMigration(): void
357362
* @param string $direction Whether to execute the migration up (default) or down
358363
* @param string|null $output A file to write SQL to, instead of executing it
359364
* @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.
360366
* @return void
361367
* @throws StopCommandException
362368
* @see neos.flow:doctrine:migrate
363369
* @see neos.flow:doctrine:migrationstatus
364370
* @see neos.flow:doctrine:migrationgenerate
365371
* @see neos.flow:doctrine:migrationversion
366372
*/
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
368374
{
369375
if (!$this->isDatabaseConfigured()) {
370376
$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
375381
$this->outputLine(sprintf('The path "%s" is not writeable!', dirname($output)));
376382
}
377383

384+
$this->maybeOutputMigrationFolderWarning($migrationFolder);
378385
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));
380387
} catch (\Exception $exception) {
381388
$this->handleException($exception);
382389
}
@@ -391,15 +398,17 @@ public function migrationExecuteCommand(string $version, string $direction = 'up
391398
* @param string $version The migration to execute
392399
* @param boolean $add The migration to mark as migrated
393400
* @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.
394402
* @return void
395-
* @throws StopCommandException
396403
* @throws DBALException
404+
* @throws FilesException
405+
* @throws StopCommandException
397406
* @see neos.flow:doctrine:migrate
398407
* @see neos.flow:doctrine:migrationstatus
399408
* @see neos.flow:doctrine:migrationexecute
400409
* @see neos.flow:doctrine:migrationgenerate
401410
*/
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
403412
{
404413
if (!$this->isDatabaseConfigured()) {
405414
$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
410419
throw new \InvalidArgumentException('You must specify whether you want to --add or --delete the specified version.');
411420
}
412421

422+
$this->maybeOutputMigrationFolderWarning($migrationFolder);
413423
try {
414-
$this->doctrineService->markAsMigrated($this->normalizeVersion($version), $add ?: false);
424+
$this->doctrineService->markAsMigrated($this->normalizeVersion($version), $add ?: false, $migrationFolder);
415425
} catch (MigrationException $exception) {
416426
$this->outputLine($exception->getMessage());
417427
$this->quit(1);
@@ -440,6 +450,7 @@ public function migrationVersionCommand(string $version, bool $add = false, bool
440450
* @param boolean $diffAgainstCurrent Whether to base the migration on the current schema structure
441451
* @param string|null $filterExpression Only include tables/sequences matching the filter expression regexp
442452
* @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.
443454
* @return void
444455
* @throws DBALException
445456
* @throws StopCommandException
@@ -449,14 +460,14 @@ public function migrationVersionCommand(string $version, bool $add = false, bool
449460
* @see neos.flow:doctrine:migrationexecute
450461
* @see neos.flow:doctrine:migrationversion
451462
*/
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
453464
{
454465
if (!$this->isDatabaseConfigured()) {
455466
$this->outputLine('Doctrine migration generation has been SKIPPED, the driver and host backend options are not set in /Configuration/Settings.yaml.');
456467
$this->quit(1);
457468
}
458469

459-
$migrationStatus = $this->doctrineService->getMigrationStatus();
470+
$migrationStatus = $this->doctrineService->getMigrationStatus($migrationFolder);
460471
if ($force === false && $migrationStatus['new'] !== 0) {
461472
$this->outputLine('There are %d new migrations available. To avoid duplication those should be executed via `doctrine:migrate` before creating additional migrations.', [$migrationStatus['new']]);
462473
$this->quit(1);
@@ -474,7 +485,9 @@ public function migrationGenerateCommand(bool $diffAgainstCurrent = true, string
474485
}
475486
}
476487

477-
[$status, $migrationClassPathAndFilename] = $this->doctrineService->generateMigration($diffAgainstCurrent, $filterExpression);
488+
$this->maybeOutputMigrationFolderWarning($migrationFolder);
489+
490+
[$status, $migrationClassPathAndFilename] = $this->doctrineService->generateMigration($diffAgainstCurrent, $filterExpression, $migrationFolder);
478491

479492
$this->outputLine('<info>%s</info>', [$status]);
480493
$this->outputLine();
@@ -495,18 +508,20 @@ public function migrationGenerateCommand(bool $diffAgainstCurrent = true, string
495508
$selectedPackage = $this->output->select('Do you want to move the migration to one of these packages?', $choices, $choices[0]);
496509
$this->outputLine();
497510

511+
$migrationPlatformFolderPart = $migrationFolder ?? $this->doctrineService->getMigrationFolderName();
512+
498513
if ($selectedPackage !== $choices[0]) {
499-
/** @var Package $selectedPackage */
500514
$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)]);
502517
Files::createDirectoryRecursively(dirname($targetPathAndFilename));
503518
rename($migrationClassPathAndFilename, $targetPathAndFilename);
504519
$this->outputLine('The migration was moved to: <comment>%s</comment>', [substr($targetPathAndFilename, strlen(FLOW_PATH_ROOT))]);
505520
$this->outputLine();
506521
$this->outputLine('Next Steps:');
507522
} else {
508523
$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));
510525
}
511526
$this->outputLine('- Review and adjust the generated migration.');
512527
$this->outputLine('- (optional) execute the migration using <comment>%s doctrine:migrate</comment>', [$this->getFlowInvocationString()]);
@@ -553,4 +568,11 @@ private function normalizeVersion(string $version): string
553568
}
554569
return sprintf('Neos\Flow\Persistence\Doctrine\Migrations\Version%s', $version);
555570
}
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+
}
556578
}

Neos.Flow/Classes/Persistence/Doctrine/AllowedObjectsListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class AllowedObjectsListener
6767
* @param OnFlushEventArgs $args
6868
* @throws PersistenceException
6969
*/
70-
public function onFlush(OnFlushEventArgs $args)
70+
public function onFlush(OnFlushEventArgs $args): void
7171
{
72-
$unitOfWork = $args->getEntityManager()->getUnitOfWork();
72+
$unitOfWork = $args->getObjectManager()->getUnitOfWork();
7373
if ($unitOfWork->getScheduledEntityInsertions() === []
7474
&& $unitOfWork->getScheduledEntityUpdates() === []
7575
&& $unitOfWork->getScheduledEntityDeletions() === []
@@ -87,7 +87,7 @@ public function onFlush(OnFlushEventArgs $args)
8787
}
8888
}
8989

90-
$connection = $args->getEntityManager()->getConnection();
90+
$connection = $args->getObjectManager()->getConnection();
9191
try {
9292
if ($this->ping($connection) === false) {
9393
$this->logger->info('Reconnecting the Doctrine EntityManager to the persistence backend.', LogEnvironment::fromMethodName(__METHOD__));
@@ -120,7 +120,7 @@ protected function ping(Connection $connection): bool
120120
* @return void
121121
* @throws \Neos\Flow\Persistence\Exception
122122
*/
123-
protected function throwExceptionIfObjectIsNotAllowed($object)
123+
protected function throwExceptionIfObjectIsNotAllowed($object): void
124124
{
125125
if (!$this->allowedObjects->contains($object)) {
126126
$message = 'Detected modified or new objects (' . get_class($object) . ', uuid:' . $this->persistenceManager->getIdentifierByObject($object) . ') to be persisted which is not allowed for "safe requests"' . chr(10) .

Neos.Flow/Classes/Persistence/Doctrine/CacheAdapter.php

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)