@@ -52,6 +52,7 @@ class Connection implements ResetInterface
52
52
protected ?float $ queueEmptiedAt = null ;
53
53
54
54
private bool $ autoSetup ;
55
+ private bool $ doMysqlCleanup = false ;
55
56
56
57
/**
57
58
* Constructor.
@@ -75,6 +76,7 @@ public function __construct(
75
76
public function reset (): void
76
77
{
77
78
$ this ->queueEmptiedAt = null ;
79
+ $ this ->doMysqlCleanup = false ;
78
80
}
79
81
80
82
public function getConfiguration (): array
@@ -152,9 +154,10 @@ public function send(string $body, array $headers, int $delay = 0): string
152
154
153
155
public function get (): ?array
154
156
{
155
- if ($ this ->driverConnection ->getDatabasePlatform () instanceof AbstractMySQLPlatform) {
157
+ if ($ this ->doMysqlCleanup && $ this -> driverConnection ->getDatabasePlatform () instanceof AbstractMySQLPlatform) {
156
158
try {
157
159
$ this ->driverConnection ->delete ($ this ->configuration ['table_name ' ], ['delivered_at ' => '9999-12-31 23:59:59 ' ]);
160
+ $ this ->doMysqlCleanup = false ;
158
161
} catch (DriverException $ e ) {
159
162
// Ignore the exception
160
163
} catch (TableNotFoundException $ e ) {
@@ -252,7 +255,11 @@ public function ack(string $id): bool
252
255
{
253
256
try {
254
257
if ($ this ->driverConnection ->getDatabasePlatform () instanceof AbstractMySQLPlatform) {
255
- return $ this ->driverConnection ->update ($ this ->configuration ['table_name ' ], ['delivered_at ' => '9999-12-31 23:59:59 ' ], ['id ' => $ id ]) > 0 ;
258
+ if ($ updated = $ this ->driverConnection ->update ($ this ->configuration ['table_name ' ], ['delivered_at ' => '9999-12-31 23:59:59 ' ], ['id ' => $ id ]) > 0 ) {
259
+ $ this ->doMysqlCleanup = true ;
260
+ }
261
+
262
+ return $ updated ;
256
263
}
257
264
258
265
return $ this ->driverConnection ->delete ($ this ->configuration ['table_name ' ], ['id ' => $ id ]) > 0 ;
@@ -265,7 +272,11 @@ public function reject(string $id): bool
265
272
{
266
273
try {
267
274
if ($ this ->driverConnection ->getDatabasePlatform () instanceof AbstractMySQLPlatform) {
268
- return $ this ->driverConnection ->update ($ this ->configuration ['table_name ' ], ['delivered_at ' => '9999-12-31 23:59:59 ' ], ['id ' => $ id ]) > 0 ;
275
+ if ($ updated = $ this ->driverConnection ->update ($ this ->configuration ['table_name ' ], ['delivered_at ' => '9999-12-31 23:59:59 ' ], ['id ' => $ id ]) > 0 ) {
276
+ $ this ->doMysqlCleanup = true ;
277
+ }
278
+
279
+ return $ updated ;
269
280
}
270
281
271
282
return $ this ->driverConnection ->delete ($ this ->configuration ['table_name ' ], ['id ' => $ id ]) > 0 ;
0 commit comments