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 ...@@ -10,6 +10,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Botan.io service has been discontinued. - Botan.io service has been discontinued.
### Removed ### Removed
### Fixed ### Fixed
- Constraint errors in `/cleanup` command.
### Security ### Security
## [0.55.1] - 2019-01-06 ## [0.55.1] - 2019-01-06
......
...@@ -302,11 +302,9 @@ class CleanupCommand extends AdminCommand ...@@ -302,11 +302,9 @@ class CleanupCommand extends AdminCommand
if (in_array('message', $tables_to_clean, true)) { if (in_array('message', $tables_to_clean, true)) {
$queries[] = sprintf( $queries[] = sprintf(
'DELETE FROM `%1$s` 'DELETE FROM `%1$s`
WHERE id IN WHERE id IN (
( SELECT id
SELECT id FROM (
FROM
(
SELECT id SELECT id
FROM `message` FROM `message`
WHERE `date` < \'%2$s\' WHERE `date` < \'%2$s\'
...@@ -320,6 +318,11 @@ class CleanupCommand extends AdminCommand ...@@ -320,6 +318,11 @@ class CleanupCommand extends AdminCommand
FROM `%4$s` FROM `%4$s`
WHERE `message_id` = `%1$s`.`id` 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 ( AND `id` NOT IN (
SELECT a.`reply_to_message` FROM `%1$s` a 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` 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 ...@@ -330,6 +333,7 @@ class CleanupCommand extends AdminCommand
', ',
TB_MESSAGE, TB_MESSAGE,
$clean_older_than['message'], $clean_older_than['message'],
TB_EDITED_MESSAGE,
TB_TELEGRAM_UPDATE, TB_TELEGRAM_UPDATE,
TB_CALLBACK_QUERY 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