diff --git a/classes/task/delete.php b/classes/task/delete.php index 6b24a3b..c5c78a8 100644 --- a/classes/task/delete.php +++ b/classes/task/delete.php @@ -105,17 +105,18 @@ public function execute() { } } } - - $sql = "SELECT c.id,count(ua.id) as usuarios_deletado,count(DISTINCT m.id) as mensagens FROM {message_conversations} c + if($configs->cleanmessage) { + $sql = "SELECT c.id,count(ua.id) as usuarios_deletado,count(DISTINCT m.id) as mensagens FROM {message_conversations} c JOIN {messages} m on m.conversationid =c.id and c.type=? JOIN {message_user_actions} ua on ua.messageid=m.id and ua.action=? GROUP BY c.id HAVING count(ua.id) >=2*count(DISTINCT m.id)"; - $deletedconversation = $DB->get_records_sql($sql, [$individualmessage, $delteaction]); - foreach ($deletedconversation as $conversation) { - \core_message\api::delete_all_conversation_data($conversation->id); + $deletedconversation = $DB->get_records_sql($sql, [$individualmessage, $delteaction]); + foreach ($deletedconversation as $conversation) { + \core_message\api::delete_all_conversation_data($conversation->id); + } } } } diff --git a/lang/en/tool_deletemessage.php b/lang/en/tool_deletemessage.php index 9ead4fb..8cab494 100644 --- a/lang/en/tool_deletemessage.php +++ b/lang/en/tool_deletemessage.php @@ -33,3 +33,5 @@ $string['privacy:metadata'] = 'The local aws plugin does not store any personal data. However, it send the IP of a user that had an error to the sentry server configured in it.'; $string['harddelete'] = "Hard Delete Messages"; $string['harddelete_desc'] = "All Deleted messages by this plugin will be deleted from database"; +$string['cleanmessage'] = "Clear Conversations"; +$string['cleanmessage_desc'] = "When Both user delete all messages between them the messages will be erased from database"; \ No newline at end of file diff --git a/settings.php b/settings.php index 4606bee..e57edfc 100644 --- a/settings.php +++ b/settings.php @@ -53,6 +53,10 @@ get_string('harddelete', 'tool_deletemessage'), get_string('harddelete_desc', 'tool_deletemessage'), $default)); + $page->add(new admin_setting_configcheckbox('tool_deletemessage/cleanmessage', + get_string('cleanmessage', 'tool_deletemessage'), + get_string('cleanmessage_desc', 'tool_deletemessage'), $default)); + $ADMIN->add('messaging', $page); }