Unverified Commit 663acfcf authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #930 from jacklul/fix_message_cleanup

Possible fix for #917
parents 0f8e0275 82f3b635
......@@ -10,6 +10,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Botan.io service has been discontinued.
### Removed
### Fixed
- Constraint errors in `/cleanup` command.
### Security
## [0.55.1] - 2019-01-06
......
......@@ -164,6 +164,7 @@ class CleanupCommand extends AdminCommand
SELECT `id`
FROM `%4$s`
WHERE `chat_id` = `%4$s`.`id`
AND `updated_at` < \'%1$s\'
)
AND (
`message_id` IS NOT NULL
......@@ -301,6 +302,11 @@ class CleanupCommand extends AdminCommand
if (in_array('message', $tables_to_clean, true)) {
$queries[] = sprintf(
'DELETE FROM `%1$s`
WHERE id IN (
SELECT id
FROM (
SELECT id
FROM `message`
WHERE `date` < \'%2$s\'
AND `id` NOT IN (
SELECT `message_id`
......@@ -312,9 +318,22 @@ class CleanupCommand extends AdminCommand
FROM `%4$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT `message_id`
FROM `%5$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT a.`reply_to_message` FROM `%1$s` a
INNER JOIN `%1$s` b ON b.`id` = a.`reply_to_message` AND b.`chat_id` = a.`reply_to_chat`
)
ORDER BY `id` DESC
) a
)
',
TB_MESSAGE,
$clean_older_than['message'],
TB_EDITED_MESSAGE,
TB_TELEGRAM_UPDATE,
TB_CALLBACK_QUERY
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment