Skip to content

Commit cfe0d15

Browse files
authored
Merge pull request #7245 from doctrine/4.4.x
Merge 4.4.x up into 4.5.x
2 parents 13edbef + c22e72f commit cfe0d15

File tree

5 files changed

+64
-8
lines changed

5 files changed

+64
-8
lines changed

src/Connection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,11 @@ public function transactional(Closure $func): mixed
964964
$res = $func($this);
965965

966966
$successful = true;
967+
} catch (ConnectionLost $connectionLost) {
968+
// Catching here only to be able to prevent a rollback attempt
969+
throw $connectionLost;
967970
} finally {
968-
if (! $successful) {
971+
if (! isset($connectionLost) && ! $successful) {
969972
$this->rollBack();
970973
}
971974
}
@@ -981,6 +984,7 @@ public function transactional(Closure $func): mixed
981984
|| $t instanceof UniqueConstraintViolationException
982985
|| $t instanceof ForeignKeyConstraintViolationException
983986
|| $t instanceof DeadlockException
987+
|| $t instanceof ConnectionLost
984988
);
985989

986990
throw $t;

src/Schema/Column.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* charset?: ?non-empty-string,
3636
* collation?: ?non-empty-string,
3737
* default_constraint_name?: non-empty-string,
38+
* enumType?: class-string,
3839
* jsonb?: bool,
3940
* version?: bool,
4041
* }
@@ -277,6 +278,16 @@ public function getMaximumValue(): mixed
277278
return $this->_platformOptions['max'] ?? null;
278279
}
279280

281+
/**
282+
* Returns the enum type used by the column.
283+
*
284+
* @return ?class-string
285+
*/
286+
public function getEnumType(): ?string
287+
{
288+
return $this->_platformOptions['enumType'] ?? null;
289+
}
290+
280291
/**
281292
* @internal Should be used only from within the {@see AbstractSchemaManager} class hierarchy.
282293
*
@@ -290,8 +301,8 @@ public function getDefaultConstraintName(): ?string
290301
}
291302

292303
/**
293-
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()} or {@see getMaximumValue()}
294-
* instead.
304+
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()}, {@see getMaximumValue()}
305+
* or {@see getEnumType()} instead.
295306
*
296307
* @return PlatformOptions
297308
*/
@@ -301,8 +312,8 @@ public function getPlatformOptions(): array
301312
}
302313

303314
/**
304-
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()} or {@see getMaximumValue()}
305-
* instead.
315+
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()}, {@see getMaximumValue()}
316+
* or {@see getEnumType()} instead.
306317
*
307318
* @param key-of<PlatformOptions> $name
308319
*/
@@ -312,8 +323,8 @@ public function hasPlatformOption(string $name): bool
312323
}
313324

314325
/**
315-
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()} or {@see getMaximumValue()}
316-
* instead.
326+
* @deprecated Use {@see getCharset()}, {@see getCollation()}, {@see getMinimumValue()}, {@see getMaximumValue()}
327+
* or {@see getEnumType()} instead.
317328
*
318329
* @param key-of<PlatformOptions> $name
319330
*/
@@ -415,6 +426,7 @@ public function edit(): ColumnEditor
415426
->setCollation($this->getCollation())
416427
->setMinimumValue($this->getMinimumValue())
417428
->setMaximumValue($this->getMaximumValue())
429+
->setEnumType($this->getEnumType())
418430
->setDefaultConstraintName($this->getDefaultConstraintName());
419431
}
420432
}

src/Schema/ColumnEditor.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ final class ColumnEditor
3434

3535
private mixed $maximumValue = null;
3636

37+
/** @var ?class-string */
38+
private ?string $enumType = null;
39+
3740
private bool $autoincrement = false;
3841

3942
private string $comment = '';
@@ -159,6 +162,14 @@ public function setMaximumValue(mixed $maximumValue): self
159162
return $this;
160163
}
161164

165+
/** @param ?class-string $enumType */
166+
public function setEnumType(?string $enumType): self
167+
{
168+
$this->enumType = $enumType;
169+
170+
return $this;
171+
}
172+
162173
public function setAutoincrement(bool $flag): self
163174
{
164175
$this->autoincrement = $flag;
@@ -245,6 +256,10 @@ public function create(): Column
245256
$platformOptions['max'] = $this->maximumValue;
246257
}
247258

259+
if ($this->enumType !== null) {
260+
$platformOptions['enumType'] = $this->enumType;
261+
}
262+
248263
if ($this->defaultConstraintName !== null) {
249264
$platformOptions[SQLServerPlatform::OPTION_DEFAULT_CONSTRAINT_NAME] = $this->defaultConstraintName;
250265
}

tests/Functional/TransactionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ public function testRollbackFailure(): void
4848
});
4949
}
5050

51+
public function testTransactionalFailureDuringCallback(): void
52+
{
53+
$this->connection->transactional(
54+
function (): void {
55+
$this->expectConnectionLoss(static function (Connection $connection): void {
56+
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
57+
});
58+
},
59+
);
60+
}
61+
62+
public function testTransactionalFailureDuringCommit(): void
63+
{
64+
$this->connection->transactional(
65+
function (): void {
66+
$this->expectConnectionLoss(static function (Connection $connection): void {
67+
});
68+
},
69+
);
70+
}
71+
5172
private function expectConnectionLoss(callable $scenario): void
5273
{
5374
$this->killCurrentSession();

tests/Schema/ColumnTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ public function testGet(): void
3737
self::assertTrue($column->getFixed());
3838
self::assertEquals('baz', $column->getDefault());
3939

40-
self::assertEquals(['charset' => 'utf8'], $column->getPlatformOptions());
40+
self::assertEquals(['charset' => 'utf8', 'enumType' => self::class], $column->getPlatformOptions());
4141
self::assertTrue($column->hasPlatformOption('charset'));
4242
self::assertEquals('utf8', $column->getPlatformOption('charset'));
4343
self::assertFalse($column->hasPlatformOption('collation'));
44+
self::assertTrue($column->hasPlatformOption('enumType'));
45+
self::assertEquals(self::class, $column->getPlatformOption('enumType'));
4446
}
4547

4648
public function testToArray(): void
@@ -60,6 +62,7 @@ public function testToArray(): void
6062
'comment' => '',
6163
'values' => [],
6264
'charset' => 'utf8',
65+
'enumType' => self::class,
6366
];
6467

6568
self::assertSame($expected, $this->createColumn()->toArray());
@@ -98,6 +101,7 @@ public function createColumn(): Column
98101
->setFixed(true)
99102
->setDefaultValue('baz')
100103
->setCharset('utf8')
104+
->setEnumType(self::class)
101105
->create();
102106
}
103107

0 commit comments

Comments
 (0)