Skip to content

Commit 6837bb9

Browse files
authored
Merge branch 'develop' into 920-new_system_commands
2 parents 268d3ba + 663acfc commit 6837bb9

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
1212
- Most built-in System Commands will be handled by GenericmessageCommand by default in a future release and will require a custom implementation.
1313
### Removed
1414
### Fixed
15+
- Constraint errors in `/cleanup` command.
1516
### Security
1617

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

src/Commands/AdminCommands/CleanupCommand.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ private function getQueries($settings)
164164
SELECT `id`
165165
FROM `%4$s`
166166
WHERE `chat_id` = `%4$s`.`id`
167+
AND `updated_at` < \'%1$s\'
167168
)
168169
AND (
169170
`message_id` IS NOT NULL
@@ -301,20 +302,38 @@ private function getQueries($settings)
301302
if (in_array('message', $tables_to_clean, true)) {
302303
$queries[] = sprintf(
303304
'DELETE FROM `%1$s`
304-
WHERE `date` < \'%2$s\'
305-
AND `id` NOT IN (
306-
SELECT `message_id`
307-
FROM `%3$s`
308-
WHERE `message_id` = `%1$s`.`id`
309-
)
310-
AND `id` NOT IN (
311-
SELECT `message_id`
312-
FROM `%4$s`
313-
WHERE `message_id` = `%1$s`.`id`
314-
)
305+
WHERE id IN (
306+
SELECT id
307+
FROM (
308+
SELECT id
309+
FROM `message`
310+
WHERE `date` < \'%2$s\'
311+
AND `id` NOT IN (
312+
SELECT `message_id`
313+
FROM `%3$s`
314+
WHERE `message_id` = `%1$s`.`id`
315+
)
316+
AND `id` NOT IN (
317+
SELECT `message_id`
318+
FROM `%4$s`
319+
WHERE `message_id` = `%1$s`.`id`
320+
)
321+
AND `id` NOT IN (
322+
SELECT `message_id`
323+
FROM `%5$s`
324+
WHERE `message_id` = `%1$s`.`id`
325+
)
326+
AND `id` NOT IN (
327+
SELECT a.`reply_to_message` FROM `%1$s` a
328+
INNER JOIN `%1$s` b ON b.`id` = a.`reply_to_message` AND b.`chat_id` = a.`reply_to_chat`
329+
)
330+
ORDER BY `id` DESC
331+
) a
332+
)
315333
',
316334
TB_MESSAGE,
317335
$clean_older_than['message'],
336+
TB_EDITED_MESSAGE,
318337
TB_TELEGRAM_UPDATE,
319338
TB_CALLBACK_QUERY
320339
);

0 commit comments

Comments
 (0)