Skip to content

Commit

Permalink
Always has cleanup errors in logs.
Browse files Browse the repository at this point in the history
Because bot has channel functionality and cleanup of telegram_updates table didn't clean lines with links to tables messages and edited_messages by post columns.
  • Loading branch information
r3bers committed Jul 29, 2024
1 parent 7811587 commit b7847fe
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/Commands/AdminCommands/CleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CleanupCommand extends AdminCommand
*
* @var array
*/
protected static $default_tables_to_clean = [
protected static array $default_tables_to_clean = [
'callback_query',
'chosen_inline_result',
'conversation',
Expand All @@ -85,7 +85,7 @@ class CleanupCommand extends AdminCommand
*
* @var array
*/
protected static $default_clean_older_than = [
protected static array $default_clean_older_than = [
'callback_query' => '30 days',
'chat' => '365 days',
'chosen_inline_result' => '30 days',
Expand All @@ -108,7 +108,7 @@ class CleanupCommand extends AdminCommand
*
* @return array
*/
private function getSettings($custom_time = ''): array
private function getSettings(string $custom_time = ''): array
{
$tables_to_clean = self::$default_tables_to_clean;
$user_tables_to_clean = $this->getConfig('tables_to_clean');
Expand Down Expand Up @@ -179,6 +179,14 @@ private function getQueries($settings): array
WHERE `date` < \'%2$s\'
)
)
OR (
`channel_post_id` IS NOT NULL
AND `channel_post_id` IN (
SELECT `id`
FROM `%5$s`
WHERE `date` < \'%2$s\'
)
)
OR (
`edited_message_id` IS NOT NULL
AND `edited_message_id` IN (
Expand All @@ -187,6 +195,14 @@ private function getQueries($settings): array
WHERE `edit_date` < \'%2$s\'
)
)
OR (
`edited_channel_post_id` IS NOT NULL
AND `edited_channel_post_id` IN (
SELECT `id`
FROM `%6$s`
WHERE `edit_date` < \'%2$s\'
)
)
OR (
`inline_query_id` IS NOT NULL
AND `inline_query_id` IN (
Expand Down Expand Up @@ -369,7 +385,7 @@ public function execute(): ServerResponse
$text = $message->getText(true);

// Dry run?
$dry_run = strpos($text, 'dry') !== false;
$dry_run = str_contains($text, 'dry');
$text = trim(str_replace('dry', '', $text));

$settings = $this->getSettings($text);
Expand Down

0 comments on commit b7847fe

Please sign in to comment.