Skip to content

Commit a34b71d

Browse files
authored
Merge pull request #1509 from doctrine/3.9.x-merge-up-into-3.10.x_NJQTyNuO
Merge release 3.9.1 into 3.10.x
2 parents 325b61e + 0f1e0c9 commit a34b71d

File tree

15 files changed

+140
-47
lines changed

15 files changed

+140
-47
lines changed

.doctrine-project.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@
1010
"slug": "4.0",
1111
"upcoming": true
1212
},
13+
{
14+
"name": "3.10",
15+
"branchName": "3.10.x",
16+
"slug": "3.10",
17+
"upcoming": true
18+
},
1319
{
1420
"name": "3.9",
1521
"branchName": "3.9.x",
1622
"slug": "3.9",
17-
"upcoming": true
23+
"current": true
1824
},
1925
{
2026
"name": "3.8",
2127
"branchName": "3.8.x",
2228
"slug": "3.8",
23-
"current": true
29+
"maintained": false
2430
},
2531
{
2632
"name": "3.7",

.github/workflows/coding-standards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ on:
2626
jobs:
2727
coding-standards:
2828
name: "Coding Standards"
29-
uses: "doctrine/.github/.github/workflows/coding-standards.yml@7.2.2"
29+
uses: "doctrine/.github/.github/workflows/coding-standards.yml@7.3.0"

.github/workflows/composer-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ on:
1717
jobs:
1818
composer-lint:
1919
name: "Composer Lint"
20-
uses: "doctrine/.github/.github/workflows/composer-lint.yml@7.2.2"
20+
uses: "doctrine/.github/.github/workflows/composer-lint.yml@7.3.0"

.github/workflows/release-on-milestone-closed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
release:
1010
name: "Git tag, release & create merge-up PR"
11-
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@7.2.2"
11+
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@7.3.0"
1212
secrets:
1313
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
1414
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}

.github/workflows/website-schema.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ on:
1818
jobs:
1919
json-validate:
2020
name: "Validate JSON schema"
21-
uses: "doctrine/.github/.github/workflows/website-schema.yml@7.2.2"
21+
uses: "doctrine/.github/.github/workflows/website-schema.yml@7.3.0"

phpstan.neon.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ parameters:
3838
-
3939
message: '~Doctrine\\ORM\\Tools\\Console\\Helper\\EntityManagerHelper~'
4040
path: src/Tools/Console/ConsoleRunner.php
41+
-
42+
message: '#^Usage of deprecated trait Symfony\\Component\\VarExporter\\LazyProxyTrait in class Doctrine\\Migrations\\Provider\\LazySchema\:\nsince Symfony 7\.3, use native lazy objects instead$#'
43+
path: src/Provider/LazySchema.php
4144

4245
symfony:
4346
console_application_loader: tests/doctrine-migrations-phpstan-app.php

src/Generator/DiffGenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function generate(
4242
string $fqcn,
4343
string|null $filterExpression,
4444
bool $formatted = false,
45+
bool|null $nowdocOutput = null,
4546
int $lineLength = 120,
4647
bool $checkDbPlatform = true,
4748
bool $fromEmptySchema = false,
@@ -83,6 +84,7 @@ static function ($assetName) use ($filterExpression) {
8384
$up = $this->migrationSqlGenerator->generate(
8485
$upSql,
8586
$formatted,
87+
$nowdocOutput,
8688
$lineLength,
8789
$checkDbPlatform,
8890
);
@@ -92,6 +94,7 @@ static function ($assetName) use ($filterExpression) {
9294
$down = $this->migrationSqlGenerator->generate(
9395
$downSql,
9496
$formatted,
97+
$nowdocOutput,
9598
$lineLength,
9699
$checkDbPlatform,
97100
);

src/Generator/SqlGenerator.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use function str_repeat;
2020
use function stripos;
2121
use function strlen;
22+
use function var_export;
2223

2324
/**
2425
* The SqlGenerator class is responsible for generating the body of the up() and down() methods for a migration
@@ -40,12 +41,14 @@ public function __construct(
4041
public function generate(
4142
array $sql,
4243
bool $formatted = false,
44+
bool|null $nowdocOutput = null,
4345
int $lineLength = 120,
4446
bool $checkDbPlatform = true,
4547
): string {
4648
$code = [];
4749

4850
$storageConfiguration = $this->configuration->getMetadataStorageConfiguration();
51+
$maxLength = $lineLength - 18 - 8; // max - php code length - indentation
4952
foreach ($sql as $query) {
5053
if (
5154
$storageConfiguration instanceof TableMetadataStorageConfiguration
@@ -54,18 +57,18 @@ public function generate(
5457
continue;
5558
}
5659

57-
if ($formatted) {
58-
$maxLength = $lineLength - 18 - 8; // max - php code length - indentation
59-
60-
if (strlen($query) > $maxLength) {
61-
$query = $this->formatQuery($query);
62-
}
60+
if ($formatted && strlen($query) > $maxLength) {
61+
$query = $this->formatQuery($query);
6362
}
6463

65-
$code[] = sprintf(
66-
"\$this->addSql(<<<'SQL'\n%s\nSQL);",
67-
preg_replace('/^/m', str_repeat(' ', 4), $query),
68-
);
64+
if ($nowdocOutput === true || ($nowdocOutput !== false && $formatted && strlen($query) > $maxLength )) {
65+
$code[] = sprintf(
66+
"\$this->addSql(<<<'SQL'\n%s\nSQL);",
67+
preg_replace('/^/m', str_repeat(' ', 4), $query),
68+
);
69+
} else {
70+
$code[] = sprintf('$this->addSql(%s);', var_export($query, true));
71+
}
6972
}
7073

7174
if (count($code) !== 0 && $checkDbPlatform && $this->configuration->isDatabasePlatformChecked()) {

src/SchemaDumper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function dump(
5656
string $fqcn,
5757
array $excludedTablesRegexes = [],
5858
bool $formatted = false,
59+
bool $nowdocOutput = false,
5960
int $lineLength = 120,
6061
): string {
6162
$schema = $this->schemaManager->introspectSchema();
@@ -73,6 +74,7 @@ public function dump(
7374
$upCode = $this->migrationSqlGenerator->generate(
7475
$upSql,
7576
$formatted,
77+
$nowdocOutput,
7678
$lineLength,
7779
);
7880

@@ -85,6 +87,7 @@ public function dump(
8587
$downCode = $this->migrationSqlGenerator->generate(
8688
$downSql,
8789
$formatted,
90+
$nowdocOutput,
8891
$lineLength,
8992
);
9093

src/Tools/Console/Command/DiffCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ protected function configure(): void
6363
InputOption::VALUE_NONE,
6464
'Format the generated SQL.',
6565
)
66+
->addOption(
67+
'nowdoc',
68+
null,
69+
InputOption::VALUE_NEGATABLE,
70+
'Output the generated SQL as a nowdoc string (always active for formatted queries).',
71+
)
6672
->addOption(
6773
'line-length',
6874
null,
@@ -102,6 +108,7 @@ protected function execute(
102108
}
103109

104110
$formatted = filter_var($input->getOption('formatted'), FILTER_VALIDATE_BOOLEAN);
111+
$nowdocOutput = filter_var($input->getOption('nowdoc'), FILTER_VALIDATE_BOOLEAN);
105112
$lineLength = (int) $input->getOption('line-length');
106113
$allowEmptyDiff = $input->getOption('allow-empty-diff');
107114
$checkDbPlatform = filter_var($input->getOption('check-database-platform'), FILTER_VALIDATE_BOOLEAN);
@@ -135,6 +142,7 @@ protected function execute(
135142
$fqcn,
136143
$filterExpression,
137144
$formatted,
145+
$nowdocOutput,
138146
$lineLength,
139147
$checkDbPlatform,
140148
$fromEmptySchema,

0 commit comments

Comments
 (0)