Skip to content

Commit a8af548

Browse files
authored
Merge pull request #436 from doctrine/3.1.x
Merge 3.1.x into 3.2.x
2 parents bdaad22 + 44b29c1 commit a8af548

File tree

4 files changed

+24
-87
lines changed

4 files changed

+24
-87
lines changed

Collector/MigrationsCollector.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ public function __construct(DependencyFactory $dependencyFactory, MigrationsFlat
2525

2626
public function collect(Request $request, Response $response, \Throwable $exception = null)
2727
{
28+
if (!empty($this->data)) {
29+
return;
30+
}
31+
2832
$metadataStorage = $this->dependencyFactory->getMetadataStorage();
2933
$planCalculator = $this->dependencyFactory->getMigrationPlanCalculator();
30-
$statusCalculator = $this->dependencyFactory->getMigrationStatusCalculator();
3134

3235
$executedMigrations = $metadataStorage->getExecutedMigrations();
3336
$availableMigrations = $planCalculator->getMigrations();
3437

35-
$this->data['available_migrations'] = $this->flattener->flattenAvailableMigrations($availableMigrations, $executedMigrations);
36-
$this->data['executed_migrations'] = $this->flattener->flattenExecutedMigrations($executedMigrations, $availableMigrations);
38+
$this->data['available_migrations_count'] = count($availableMigrations);
39+
$unavailableMigrations = $executedMigrations->unavailableSubset($availableMigrations);
40+
$this->data['unavailable_migrations_count'] = count($unavailableMigrations);
3741

38-
$this->data['new_migrations'] = $this->flattener->flattenAvailableMigrations($statusCalculator->getNewMigrations());
39-
$this->data['unavailable_migrations'] = $this->flattener->flattenExecutedMigrations($statusCalculator->getExecutedUnavailableMigrations());
42+
$newMigrations = $availableMigrations->newSubset($executedMigrations);
43+
$this->data['new_migrations'] = $this->flattener->flattenAvailableMigrations($newMigrations);
44+
$this->data['executed_migrations'] = $this->flattener->flattenExecutedMigrations($executedMigrations, $availableMigrations);
4045

4146
$this->data['storage'] = get_class($metadataStorage);
4247
$configuration = $this->dependencyFactory->getConfiguration();

Collector/MigrationsFlattener.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,26 @@
1111

1212
class MigrationsFlattener
1313
{
14-
public function flattenAvailableMigrations(AvailableMigrationsList $migrationsList, ?ExecutedMigrationsList $executedMigrations = null): array
14+
public function flattenAvailableMigrations(AvailableMigrationsList $migrationsList): array
1515
{
16-
return array_map(static function (AvailableMigration $migration) use ($executedMigrations) {
17-
$executedMigration = $executedMigrations && $executedMigrations->hasMigration($migration->getVersion())
18-
? $executedMigrations->getMigration($migration->getVersion())
19-
: null;
20-
16+
return array_map(static function (AvailableMigration $migration) {
2117
return [
2218
'version' => (string)$migration->getVersion(),
23-
'is_new' => !$executedMigration,
19+
'is_new' => true,
2420
'is_unavailable' => false,
2521
'description' => $migration->getMigration()->getDescription(),
26-
'executed_at' => $executedMigration ? $executedMigration->getExecutedAt() : null,
27-
'execution_time' => $executedMigration ? $executedMigration->getExecutionTime() : null,
22+
'executed_at' => null,
23+
'execution_time' => null,
2824
'file' => (new \ReflectionClass($migration->getMigration()))->getFileName(),
2925
];
3026
}, $migrationsList->getItems());
3127
}
3228

33-
public function flattenExecutedMigrations(ExecutedMigrationsList $migrationsList, ?AvailableMigrationsList $availableMigrations = null): array
29+
public function flattenExecutedMigrations(ExecutedMigrationsList $migrationsList, AvailableMigrationsList $availableMigrations): array
3430
{
3531
return array_map(static function (ExecutedMigration $migration) use ($availableMigrations) {
3632

37-
$availableMigration = $availableMigrations && $availableMigrations->hasMigration($migration->getVersion())
33+
$availableMigration = $availableMigrations->hasMigration($migration->getVersion())
3834
? $availableMigrations->getMigration($migration->getVersion())->getMigration()
3935
: null;
4036

Resources/views/Collector/migrations.html.twig

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
{% import _self as helper %}
44

55
{% block toolbar %}
6-
{% set unavailable_migrations = collector.data.unavailable_migrations|length %}
6+
{% set unavailable_migrations = collector.data.unavailable_migrations_count %}
77
{% set new_migrations = collector.data.new_migrations|length %}
88
{% if unavailable_migrations > 0 or new_migrations > 0 %}
99
{% set executed_migrations = collector.data.executed_migrations|length %}
10-
{% set available_migrations = collector.data.available_migrations|length %}
10+
{% set available_migrations = collector.data.available_migrations_count %}
1111
{% set status_color = unavailable_migrations > 0 ? 'yellow' : '' %}
1212
{% set status_color = new_migrations > 0 ? 'red' : status_color %}
1313

@@ -45,7 +45,7 @@
4545

4646

4747
{% block menu %}
48-
{% set unavailable_migrations = collector.data.unavailable_migrations|length %}
48+
{% set unavailable_migrations = collector.data.unavailable_migrations_count %}
4949
{% set new_migrations = collector.data.new_migrations|length %}
5050
{% set label = unavailable_migrations > 0 ? 'label-status-warning' : '' %}
5151
{% set label = new_migrations > 0 ? 'label-status-error' : label %}
@@ -68,11 +68,11 @@
6868
<span class="label">Executed</span>
6969
</div>
7070
<div class="metric">
71-
<span class="value">{{ collector.data.unavailable_migrations|length }}</span>
71+
<span class="value">{{ collector.data.unavailable_migrations_count }}</span>
7272
<span class="label">Executed Unavailable</span>
7373
</div>
7474
<div class="metric">
75-
<span class="value">{{ collector.data.available_migrations|length }}</span>
75+
<span class="value">{{ collector.data.available_migrations_count }}</span>
7676
<span class="label">Available</span>
7777
</div>
7878
<div class="metric">
@@ -156,7 +156,6 @@
156156
{% endblock %}
157157

158158
{% macro render_migration(migration) %}
159-
160159
<tr>
161160
<td class="font-normal">
162161
{% if migration.file %}

Tests/Collector/MigrationsFlattenerTest.php

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp(): void
2828
$this->flattener = new MigrationsFlattener();
2929
}
3030

31-
public function testFlattenAvailableMigrationsWithoutExecutedMigrations(): void
31+
public function testFlattenAvailableMigrations(): void
3232
{
3333
$expected = [
3434
[
@@ -61,73 +61,10 @@ public function testFlattenAvailableMigrationsWithoutExecutedMigrations(): void
6161
];
6262

6363
$actual = $this->flattener->flattenAvailableMigrations($this->createAvailableMigrations());
64-
self::assertSame($expected, $actual);
65-
}
66-
67-
public function testFlattenAvailableMigrationsWithExecutedMigrations(): void
68-
{
69-
$expected = [
70-
[
71-
'version' => '012345',
72-
'is_new' => false,
73-
'is_unavailable' => false,
74-
'description' => '',
75-
'executed_at' => new DateTimeImmutable('2020-12-12 20:15:00'),
76-
'execution_time' => 3.2,
77-
'file' => dirname(__DIR__) . '/Fixtures/Migrations/Migration001.php',
78-
],
79-
[
80-
'version' => '123456',
81-
'is_new' => true,
82-
'is_unavailable' => false,
83-
'description' => '',
84-
'executed_at' => null,
85-
'execution_time' => null,
86-
'file' => dirname(__DIR__) . '/Fixtures/Migrations/Migration001.php',
87-
],
88-
[
89-
'version' => '456789',
90-
'is_new' => true,
91-
'is_unavailable' => false,
92-
'description' => '',
93-
'executed_at' => null,
94-
'execution_time' => null,
95-
'file' => dirname(__DIR__) . '/Fixtures/Migrations/Migration001.php',
96-
],
97-
];
98-
99-
$actual = $this->flattener->flattenAvailableMigrations($this->createAvailableMigrations(), $this->createExecutedMigrations());
100-
self::assertEquals($expected, $actual);
101-
}
102-
103-
public function testFlattenExecutedMigrationsWithoutAvailableMigrations(): void
104-
{
105-
$expected = [
106-
[
107-
'version' => '012345',
108-
'is_new' => false,
109-
'is_unavailable' => true,
110-
'description' => '',
111-
'executed_at' => new DateTimeImmutable('2020-12-12 20:15:00'),
112-
'execution_time' => 3.2,
113-
'file' => null,
114-
],
115-
[
116-
'version' => '111111',
117-
'is_new' => false,
118-
'is_unavailable' => true,
119-
'description' => '',
120-
'executed_at' => new DateTimeImmutable('2020-12-14 20:30:00'),
121-
'execution_time' => 8.9,
122-
'file' => null,
123-
],
124-
];
125-
126-
$actual = $this->flattener->flattenExecutedMigrations($this->createExecutedMigrations());
12764
self::assertEquals($expected, $actual);
12865
}
12966

130-
public function testFlattenExecutedMigrationsWithAvailableMigrations(): void
67+
public function testFlattenExecutedMigrations(): void
13168
{
13269
$expected = [
13370
[

0 commit comments

Comments
 (0)