mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Add SQL to Riak converter
This commit is contained in:
parent
0490c2f139
commit
e82219185b
@ -445,5 +445,7 @@ import(Server) ->
|
||||
|
||||
import(Server, mnesia, Passwd) ->
|
||||
ejabberd_auth_internal:import(Server, mnesia, Passwd);
|
||||
import(Server, riak, Passwd) ->
|
||||
ejabberd_auth_riak:import(Server, riak, Passwd);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -38,7 +38,7 @@
|
||||
get_vh_registered_users_number/1,
|
||||
get_vh_registered_users_number/2, get_password/2,
|
||||
get_password_s/2, is_user_exists/2, remove_user/2,
|
||||
remove_user/3, store_type/0, export/1,
|
||||
remove_user/3, store_type/0, export/1, import/3,
|
||||
plain_password_required/0]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
@ -283,3 +283,8 @@ export(_Server) ->
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end}].
|
||||
|
||||
import(LServer, riak, #passwd{} = Passwd) ->
|
||||
ejabberd_riak:put(Passwd, [{'2i', [{<<"host">>, LServer}]}]);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -1137,5 +1137,9 @@ import(_LServer, mnesia, #motd{} = Motd) ->
|
||||
mnesia:dirty_write(Motd);
|
||||
import(_LServer, mnesia, #motd_users{} = Users) ->
|
||||
mnesia:dirty_write(Users);
|
||||
import(_LServer, riak, #motd{} = Motd) ->
|
||||
ejabberd_riak:put(Motd);
|
||||
import(_LServer, riak, #motd_users{us = {_, S}} = Users) ->
|
||||
ejabberd_riak:put(Users, [{'2i', [{<<"server">>, S}]}]);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -622,3 +622,81 @@ is_valid_node(Node) ->
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
update_table() ->
|
||||
Fields = record_info(fields, caps_features),
|
||||
case mnesia:table_info(caps_features, attributes) of
|
||||
Fields ->
|
||||
ejabberd_config:convert_table_to_binary(
|
||||
caps_features, Fields, set,
|
||||
fun(#caps_features{node_pair = {N, _}}) -> N end,
|
||||
fun(#caps_features{node_pair = {N, P},
|
||||
features = Fs} = R) ->
|
||||
NewFs = if is_integer(Fs) ->
|
||||
Fs;
|
||||
true ->
|
||||
[iolist_to_binary(F) || F <- Fs]
|
||||
end,
|
||||
R#caps_features{node_pair = {iolist_to_binary(N),
|
||||
iolist_to_binary(P)},
|
||||
features = NewFs}
|
||||
end);
|
||||
_ ->
|
||||
?INFO_MSG("Recreating caps_features table", []),
|
||||
mnesia:transform_table(caps_features, ignore, Fields)
|
||||
end.
|
||||
|
||||
sql_write_features_t({Node, SubNode}, Features) ->
|
||||
SNode = ejabberd_odbc:escape(Node),
|
||||
SSubNode = ejabberd_odbc:escape(SubNode),
|
||||
NewFeatures = if is_integer(Features) ->
|
||||
[jlib:integer_to_binary(Features)];
|
||||
true ->
|
||||
Features
|
||||
end,
|
||||
[[<<"delete from caps_features where node='">>,
|
||||
SNode, <<"' and subnode='">>, SSubNode, <<"';">>]|
|
||||
[[<<"insert into caps_features(node, subnode, feature) ">>,
|
||||
<<"values ('">>, SNode, <<"', '">>, SSubNode, <<"', '">>,
|
||||
ejabberd_odbc:escape(F), <<"');">>] || F <- NewFeatures]].
|
||||
|
||||
export(_Server) ->
|
||||
[{caps_features,
|
||||
fun(_Host, #caps_features{node_pair = NodePair,
|
||||
features = Features}) ->
|
||||
sql_write_features_t(NodePair, Features);
|
||||
(_Host, _R) ->
|
||||
[]
|
||||
end}].
|
||||
|
||||
import(_LServer) ->
|
||||
[{<<"select node, subnode from caps_features;">>,
|
||||
fun([Node, SubNode]) ->
|
||||
SNode = ejabberd_odbc:escape(Node),
|
||||
SSubNode = ejabberd_odbc:escape(SubNode),
|
||||
{selected, _, Rows} =
|
||||
ejabberd_odbc:sql_query_t(
|
||||
[<<"select feature from caps_features "
|
||||
"where node='">>, SNode,
|
||||
<<"' and subnode='">>, SSubNode, <<"';">>]),
|
||||
Features = case Rows of
|
||||
[[Stamp]] ->
|
||||
case catch jlib:binary_to_integer(Stamp) of
|
||||
Int when is_integer(Int), Int>=0 ->
|
||||
Int;
|
||||
_ ->
|
||||
[Stamp]
|
||||
end;
|
||||
_ ->
|
||||
[Feature || [Feature] <- Rows]
|
||||
end,
|
||||
#caps_features{node_pair = {Node, SubNode},
|
||||
features = Features}
|
||||
end}].
|
||||
|
||||
import(_LServer, mnesia, #caps_features{} = Caps) ->
|
||||
mnesia:dirty_write(Caps);
|
||||
import(_LServer, riak, #caps_features{} = Caps) ->
|
||||
ejabberd_riak:put(Caps);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -1337,5 +1337,7 @@ import(_LServer) ->
|
||||
|
||||
import(_LServer, mnesia, #irc_custom{} = R) ->
|
||||
mnesia:dirty_write(R);
|
||||
import(_LServer, riak, #irc_custom{} = R) ->
|
||||
ejabberd_riak:put(R);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -330,6 +330,8 @@ import(LServer) ->
|
||||
|
||||
import(_LServer, mnesia, #last_activity{} = LA) ->
|
||||
mnesia:dirty_write(LA);
|
||||
import(_LServer, riak, #last_activity{} = LA) ->
|
||||
ejabberd_riak:put(LA);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
||||
|
@ -1268,5 +1268,10 @@ import(_LServer, mnesia, #muc_room{} = R) ->
|
||||
mnesia:dirty_write(R);
|
||||
import(_LServer, mnesia, #muc_registered{} = R) ->
|
||||
mnesia:dirty_write(R);
|
||||
import(_LServer, riak, #muc_room{} = R) ->
|
||||
ejabberd_riak:put(R);
|
||||
import(_LServer, riak,
|
||||
#muc_registered{us_host = {_, Host}, nick = Nick} = R) ->
|
||||
ejabberd_riak:put(R, [{'2i', [{<<"nick_host">>, {Nick, Host}}]}]);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -1073,5 +1073,7 @@ import(LServer) ->
|
||||
|
||||
import(_LServer, mnesia, #offline_msg{} = Msg) ->
|
||||
mnesia:dirty_write(Msg);
|
||||
import(_LServer, riak, #offline_msg{us = US, timestamp = TS} = M) ->
|
||||
ejabberd_riak:put(M, [{i, TS}, {'2i', [{<<"us">>, US}]}]);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -1241,5 +1241,7 @@ import(LServer) ->
|
||||
|
||||
import(_LServer, mnesia, #privacy{} = P) ->
|
||||
mnesia:dirty_write(P);
|
||||
import(_LServer, riak, #privacy{} = P) ->
|
||||
ejabberd_riak:put(P);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -307,5 +307,7 @@ import(LServer) ->
|
||||
|
||||
import(_LServer, mnesia, #private_storage{} = PS) ->
|
||||
mnesia:dirty_write(PS);
|
||||
import(_LServer, riak, #private_storage{usns = {LUser, LServer, _}} = PS) ->
|
||||
ejabberd_riak:put(PS, [{'2i', [{<<"us">>, {LUser, LServer}}]}]);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -1748,6 +1748,10 @@ import(_LServer, mnesia, #roster{} = R) ->
|
||||
mnesia:dirty_write(R);
|
||||
import(_LServer, mnesia, #roster_version{} = RV) ->
|
||||
mnesia:dirty_write(RV);
|
||||
import(_LServer, riak, #roster{us = {LUser, LServer}} = R) ->
|
||||
ejabberd_riak:put(R, [{'2i', [{<<"us">>, {LUser, LServer}}]}]);
|
||||
import(_LServer, riak, #roster_version{} = RV) ->
|
||||
ejabberd_riak:put(RV);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
||||
|
@ -1441,5 +1441,12 @@ import(_LServer, mnesia, #sr_group{} = G) ->
|
||||
mnesia:dirty_write(G);
|
||||
import(_LServer, mnesia, #sr_user{} = U) ->
|
||||
mnesia:dirty_write(U);
|
||||
import(_LServer, riak, #sr_group{group_host = {_, Host}} = G) ->
|
||||
ejabberd_riak:put(G, [{'2i', [{<<"host">>, Host}]}]);
|
||||
import(_LServer, riak, #sr_user{us = US, group_host = {Group, Host}} = User) ->
|
||||
ejabberd_riak:put(User,
|
||||
[{i, {US, {Group, Host}}},
|
||||
{'2i', [{<<"us">>, US},
|
||||
{<<"group_host">>, {Group, Host}}]}]);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -1081,5 +1081,72 @@ import(_LServer, mnesia, #vcard{} = VCard) ->
|
||||
mnesia:dirty_write(VCard);
|
||||
import(_LServer, mnesia, #vcard_search{} = S) ->
|
||||
mnesia:dirty_write(S);
|
||||
import(_LServer, riak, #vcard{us = {LUser, _}, vcard = El} = VCard) ->
|
||||
FN = xml:get_path_s(El, [{elem, <<"FN">>}, cdata]),
|
||||
Family = xml:get_path_s(El,
|
||||
[{elem, <<"N">>}, {elem, <<"FAMILY">>}, cdata]),
|
||||
Given = xml:get_path_s(El,
|
||||
[{elem, <<"N">>}, {elem, <<"GIVEN">>}, cdata]),
|
||||
Middle = xml:get_path_s(El,
|
||||
[{elem, <<"N">>}, {elem, <<"MIDDLE">>}, cdata]),
|
||||
Nickname = xml:get_path_s(El,
|
||||
[{elem, <<"NICKNAME">>}, cdata]),
|
||||
BDay = xml:get_path_s(El,
|
||||
[{elem, <<"BDAY">>}, cdata]),
|
||||
CTRY = xml:get_path_s(El,
|
||||
[{elem, <<"ADR">>}, {elem, <<"CTRY">>}, cdata]),
|
||||
Locality = xml:get_path_s(El,
|
||||
[{elem, <<"ADR">>}, {elem, <<"LOCALITY">>},
|
||||
cdata]),
|
||||
EMail1 = xml:get_path_s(El,
|
||||
[{elem, <<"EMAIL">>}, {elem, <<"USERID">>}, cdata]),
|
||||
EMail2 = xml:get_path_s(El,
|
||||
[{elem, <<"EMAIL">>}, cdata]),
|
||||
OrgName = xml:get_path_s(El,
|
||||
[{elem, <<"ORG">>}, {elem, <<"ORGNAME">>}, cdata]),
|
||||
OrgUnit = xml:get_path_s(El,
|
||||
[{elem, <<"ORG">>}, {elem, <<"ORGUNIT">>}, cdata]),
|
||||
EMail = case EMail1 of
|
||||
<<"">> -> EMail2;
|
||||
_ -> EMail1
|
||||
end,
|
||||
LFN = string2lower(FN),
|
||||
LFamily = string2lower(Family),
|
||||
LGiven = string2lower(Given),
|
||||
LMiddle = string2lower(Middle),
|
||||
LNickname = string2lower(Nickname),
|
||||
LBDay = string2lower(BDay),
|
||||
LCTRY = string2lower(CTRY),
|
||||
LLocality = string2lower(Locality),
|
||||
LEMail = string2lower(EMail),
|
||||
LOrgName = string2lower(OrgName),
|
||||
LOrgUnit = string2lower(OrgUnit),
|
||||
ejabberd_riak:put(VCard,
|
||||
[{'2i', [{<<"user">>, LUser},
|
||||
{<<"luser">>, LUser},
|
||||
{<<"fn">>, FN},
|
||||
{<<"lfn">>, LFN},
|
||||
{<<"family">>, Family},
|
||||
{<<"lfamily">>, LFamily},
|
||||
{<<"given">>, Given},
|
||||
{<<"lgiven">>, LGiven},
|
||||
{<<"middle">>, Middle},
|
||||
{<<"lmiddle">>, LMiddle},
|
||||
{<<"nickname">>, Nickname},
|
||||
{<<"lnickname">>, LNickname},
|
||||
{<<"bday">>, BDay},
|
||||
{<<"lbday">>, LBDay},
|
||||
{<<"ctry">>, CTRY},
|
||||
{<<"lctry">>, LCTRY},
|
||||
{<<"locality">>, Locality},
|
||||
{<<"llocality">>, LLocality},
|
||||
{<<"email">>, EMail},
|
||||
{<<"lemail">>, LEMail},
|
||||
{<<"orgname">>, OrgName},
|
||||
{<<"lorgname">>, LOrgName},
|
||||
{<<"orgunit">>, OrgUnit},
|
||||
{<<"lorgunit">>, LOrgUnit}]}]);
|
||||
import(_LServer, riak, #vcard_search{}) ->
|
||||
ok;
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
@ -222,5 +222,7 @@ import(LServer) ->
|
||||
|
||||
import(_LServer, mnesia, #vcard_xupdate{} = R) ->
|
||||
mnesia:dirty_write(R);
|
||||
import(_LServer, riak, #vcard_xupdate{} = R) ->
|
||||
ejabberd_riak:put(R);
|
||||
import(_, _, _) ->
|
||||
pass.
|
||||
|
Loading…
Reference in New Issue
Block a user