aboutsummaryrefslogtreecommitdiff
path: root/src/mod_muc_mnesia.erl
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/mod_muc_mnesia.erl80
1 files changed, 20 insertions, 60 deletions
diff --git a/src/mod_muc_mnesia.erl b/src/mod_muc_mnesia.erl
index 8cbdfe6bd..53f31cb9f 100644
--- a/src/mod_muc_mnesia.erl
+++ b/src/mod_muc_mnesia.erl
@@ -39,6 +39,7 @@
%% gen_server callbacks
-export([start_link/2, init/1, handle_cast/2, handle_call/3, handle_info/2,
terminate/2, code_change/3]).
+-export([need_transform/1, transform/1]).
-include("mod_muc.hrl").
-include("logger.hrl").
@@ -306,14 +307,12 @@ init([Host, Opts]) ->
[{disc_copies, [node()]},
{attributes,
record_info(fields, muc_registered)},
- {index, [nick]}]),
- update_tables(MyHost);
+ {index, [nick]}]);
_ ->
ok
end,
case gen_mod:ram_db_mod(Host, Opts, mod_muc) of
?MODULE ->
- update_muc_online_table(),
ejabberd_mnesia:create(?MODULE, muc_online_room,
[{ram_copies, [node()]},
{type, ordered_set},
@@ -377,60 +376,21 @@ clean_table_from_bad_node(Node, Host) ->
end,
mnesia:async_dirty(F).
-update_tables(Host) ->
- update_muc_room_table(Host),
- update_muc_registered_table(Host).
-
-update_muc_room_table(_Host) ->
- Fields = record_info(fields, muc_room),
- case mnesia:table_info(muc_room, attributes) of
- Fields ->
- ejabberd_config:convert_table_to_binary(
- muc_room, Fields, set,
- fun(#muc_room{name_host = {N, _}}) -> N end,
- fun(#muc_room{name_host = {N, H},
- opts = Opts} = R) ->
- R#muc_room{name_host = {iolist_to_binary(N),
- iolist_to_binary(H)},
- opts = mod_muc:opts_to_binary(Opts)}
- end);
- _ ->
- ?INFO_MSG("Recreating muc_room table", []),
- mnesia:transform_table(muc_room, ignore, Fields)
- end.
-
-update_muc_registered_table(_Host) ->
- Fields = record_info(fields, muc_registered),
- case mnesia:table_info(muc_registered, attributes) of
- Fields ->
- ejabberd_config:convert_table_to_binary(
- muc_registered, Fields, set,
- fun(#muc_registered{us_host = {_, H}}) -> H end,
- fun(#muc_registered{us_host = {{U, S}, H},
- nick = Nick} = R) ->
- R#muc_registered{us_host = {{iolist_to_binary(U),
- iolist_to_binary(S)},
- iolist_to_binary(H)},
- nick = iolist_to_binary(Nick)}
- end);
- _ ->
- ?INFO_MSG("Recreating muc_registered table", []),
- mnesia:transform_table(muc_registered, ignore, Fields)
- end.
-
-update_muc_online_table() ->
- try
- case mnesia:table_info(muc_online_room, type) of
- ordered_set -> ok;
- _ ->
- case mnesia:delete_table(muc_online_room) of
- {atomic, ok} -> ok;
- Err -> erlang:error(Err)
- end
- end
- catch _:{aborted, {no_exists, muc_online_room}} -> ok;
- _:{aborted, {no_exists, muc_online_room, type}} -> ok;
- E:R ->
- ?ERROR_MSG("failed to update mnesia table '~s': ~p",
- [muc_online_room, {E, R, erlang:get_stacktrace()}])
- end.
+need_transform(#muc_room{name_host = {N, H}})
+ when is_list(N) orelse is_list(H) ->
+ ?INFO_MSG("Mnesia table 'muc_room' will be converted to binary", []),
+ true;
+need_transform(#muc_registered{us_host = {{U, S}, H}, nick = Nick})
+ when is_list(U) orelse is_list(S) orelse is_list(H) orelse is_list(Nick) ->
+ ?INFO_MSG("Mnesia table 'muc_registered' will be converted to binary", []),
+ true;
+need_transform(_) ->
+ false.
+
+transform(#muc_room{name_host = {N, H}, opts = Opts} = R) ->
+ R#muc_room{name_host = {iolist_to_binary(N), iolist_to_binary(H)},
+ opts = mod_muc:opts_to_binary(Opts)};
+transform(#muc_registered{us_host = {{U, S}, H}, nick = Nick} = R) ->
+ R#muc_registered{us_host = {{iolist_to_binary(U), iolist_to_binary(S)},
+ iolist_to_binary(H)},
+ nick = iolist_to_binary(Nick)}.