Skip to content

Commit 82f3b63

Browse files
committed
Prevent constraint errors when deleting only messages without edited messages.
1 parent 2791e1d commit 82f3b63

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
1010
- Botan.io service has been discontinued.
1111
### Removed
1212
### Fixed
13+
- Constraint errors in `/cleanup` command.
1314
### Security
1415

1516
## [0.55.1] - 2019-01-06

src/Commands/AdminCommands/CleanupCommand.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,9 @@ private function getQueries($settings)
302302
if (in_array('message', $tables_to_clean, true)) {
303303
$queries[] = sprintf(
304304
'DELETE FROM `%1$s`
305-
WHERE id IN
306-
(
307-
SELECT id
308-
FROM
309-
(
305+
WHERE id IN (
306+
SELECT id
307+
FROM (
310308
SELECT id
311309
FROM `message`
312310
WHERE `date` < \'%2$s\'
@@ -320,6 +318,11 @@ private function getQueries($settings)
320318
FROM `%4$s`
321319
WHERE `message_id` = `%1$s`.`id`
322320
)
321+
AND `id` NOT IN (
322+
SELECT `message_id`
323+
FROM `%5$s`
324+
WHERE `message_id` = `%1$s`.`id`
325+
)
323326
AND `id` NOT IN (
324327
SELECT a.`reply_to_message` FROM `%1$s` a
325328
INNER JOIN `%1$s` b ON b.`id` = a.`reply_to_message` AND b.`chat_id` = a.`reply_to_chat`
@@ -330,6 +333,7 @@ private function getQueries($settings)
330333
',
331334
TB_MESSAGE,
332335
$clean_older_than['message'],
336+
TB_EDITED_MESSAGE,
333337
TB_TELEGRAM_UPDATE,
334338
TB_CALLBACK_QUERY
335339
);

0 commit comments

Comments
 (0)