aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Sautret <jerome.sautret@process-one.net>2015-03-13 18:29:57 +0100
committerChristophe Romain <christophe.romain@process-one.net>2015-03-20 10:40:19 +0100
commit6b67a66a1ba33f3dc4346f8fffd1f9535ce54d17 (patch)
tree863b118f9c9f6f242d5cf350dc865d49965806b4
parentFix mod_offline termination (diff)
Added MySQL support for delete_old_messages (offline) command.
-rw-r--r--sql/mysql.sql1
-rw-r--r--src/mod_offline.erl16
2 files changed, 15 insertions, 2 deletions
diff --git a/sql/mysql.sql b/sql/mysql.sql
index 64f54ba70..8557d0804 100644
--- a/sql/mysql.sql
+++ b/sql/mysql.sql
@@ -79,6 +79,7 @@ CREATE TABLE spool (
) ENGINE=InnoDB CHARACTER SET utf8;
CREATE INDEX i_despool USING BTREE ON spool(username);
+CREATE INDEX i_spool_created_at USING BTREE ON spool(created_at);
CREATE TABLE vcard (
username varchar(250) PRIMARY KEY,
diff --git a/src/mod_offline.erl b/src/mod_offline.erl
index d345140e2..d90748255 100644
--- a/src/mod_offline.erl
+++ b/src/mod_offline.erl
@@ -236,7 +236,7 @@ store_offline_msg(Host, {User, _}, Msgs, Len, MaxOfflineMsgs,
Len + count_offline_messages(User, Host);
true -> 0
end,
- if
+ if
Count > MaxOfflineMsgs ->
discard_warn_sender(Msgs);
true ->
@@ -561,7 +561,19 @@ remove_old_messages(Days, _LServer, mnesia) ->
ok, offline_msg)
end,
mnesia:transaction(F);
-remove_old_messages(_Days, _LServer, odbc) ->
+
+remove_old_messages(Days, LServer, odbc) ->
+ case catch ejabberd_odbc:sql_query(
+ LServer,
+ [<<"DELETE FROM spool"
+ " WHERE created_at < "
+ "DATE_SUB(CURDATE(), INTERVAL ">>,
+ integer_to_list(Days), <<" DAY);">>]) of
+ {updated, N} ->
+ ?INFO_MSG("~p message(s) deleted from offline spool", [N]);
+ _Error ->
+ ?ERROR_MSG("Cannot delete message in offline spool: ~p", [_Error])
+ end,
{atomic, ok};
remove_old_messages(_Days, _LServer, riak) ->
{atomic, ok}.