Prevent constraint errors when deleting only messages without edited messages.

parent 2791e1d6
......@@ -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
......
......@@ -302,11 +302,9 @@ class CleanupCommand extends AdminCommand
if (in_array('message', $tables_to_clean, true)) {
$queries[] = sprintf(
'DELETE FROM `%1$s`
WHERE id IN
(
SELECT id
FROM
(
WHERE id IN (
SELECT id
FROM (
SELECT id
FROM `message`
WHERE `date` < \'%2$s\'
......@@ -320,6 +318,11 @@ 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`
......@@ -330,6 +333,7 @@ class CleanupCommand extends AdminCommand
',
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