25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

* src/mod_pubsub/mod_pubsub.erl: Fix update pubsub tables from

ejabberd 1.x to 2.x (EJAB-817)

SVN Revision: 1734
This commit is contained in:
Badlop 2008-12-16 17:44:48 +00:00
parent 867ce5be32
commit 8f43867091
2 changed files with 62 additions and 53 deletions

View File

@ -1,5 +1,8 @@
2008-12-16 Badlop <badlop@process-one.net> 2008-12-16 Badlop <badlop@process-one.net>
* src/mod_pubsub/mod_pubsub.erl: Fix update pubsub tables from
ejabberd 1.x to 2.x (EJAB-817)
* doc/guide.tex: Fix capitalization of some section titles * doc/guide.tex: Fix capitalization of some section titles
* doc/guide.tex: Mention as optional Requirements: mysql, pgsql * doc/guide.tex: Mention as optional Requirements: mysql, pgsql

View File

@ -241,60 +241,66 @@ update_database(Host) ->
[host_node, host_parent, info] -> [host_node, host_parent, info] ->
?INFO_MSG("upgrade pubsub tables",[]), ?INFO_MSG("upgrade pubsub tables",[]),
F = fun() -> F = fun() ->
NewRecords = lists:foldl(
lists:foldl( fun({pubsub_node, NodeId, ParentId, {nodeinfo, Items, Options, Entities}}, RecList) ->
fun({pubsub_node, NodeId, ParentId, {nodeinfo, Items, Options, Entities}}, RecList) -> ItemsList =
ItemsList = lists:foldl(
lists:foldl( fun({item, IID, Publisher, Payload}, Acc) ->
fun({item, IID, Publisher, Payload}, Acc) -> C = {Publisher, unknown},
C = {Publisher, unknown}, M = {Publisher, now()},
M = {Publisher, now()}, mnesia:write(
mnesia:write( #pubsub_item{itemid = {IID, NodeId},
#pubsub_item{itemid = {IID, NodeId}, creation = C,
creation = C, modification = M,
modification = M, payload = Payload}),
payload = Payload}), [{Publisher, IID} | Acc]
[{Publisher, IID} | Acc] end, [], Items),
end, [], Items), Owners =
Owners = dict:fold(
dict:fold( fun(JID, {entity, Aff, Sub}, Acc) ->
fun(JID, {entity, Aff, Sub}, Acc) -> UsrItems =
UsrItems = lists:foldl(
lists:foldl( fun({P, I}, IAcc) ->
fun({P, I}, IAcc) -> case P of
case P of JID -> [I | IAcc];
JID -> [I | IAcc]; _ -> IAcc
_ -> IAcc end
end end, [], ItemsList),
end, [], ItemsList), mnesia:write(
mnesia:write( #pubsub_state{stateid = {JID, NodeId},
#pubsub_state{stateid = {JID, NodeId}, items = UsrItems,
items = UsrItems, affiliation = Aff,
affiliation = Aff, subscription = Sub}),
subscription = Sub}), case Aff of
case Aff of owner -> [JID | Acc];
owner -> [JID | Acc]; _ -> Acc
_ -> Acc end
end end, [], Entities),
end, [], Entities), mnesia:delete({pubsub_node, NodeId}),
mnesia:delete({pubsub_node, NodeId}), [#pubsub_node{nodeid = NodeId,
[#pubsub_node{nodeid = NodeId, parentid = ParentId,
parentid = ParentId, owners = Owners,
owners = Owners, options = Options} |
options = Options} | RecList]
RecList] end, [],
end, [], mnesia:match_object(
mnesia:match_object( {pubsub_node, {Host, '_'}, '_', '_'}))
{pubsub_node, {Host, '_'}, '_', '_'})),
mnesia:delete_table(pubsub_node),
mnesia:create_table(pubsub_node,
[{disc_copies, [node()]},
{attributes, record_info(fields, pubsub_node)}]),
lists:foreach(fun(Record) ->
mnesia:write(Record)
end, NewRecords)
end, end,
mnesia:transaction(F); {atomic, NewRecords} = mnesia:transaction(F),
{atomic, ok} = mnesia:delete_table(pubsub_node),
{atomic, ok} = mnesia:create_table(pubsub_node,
[{disc_copies, [node()]},
{attributes, record_info(fields, pubsub_node)}]),
FNew = fun() -> lists:foreach(fun(Record) ->
mnesia:write(Record)
end, NewRecords)
end,
case mnesia:transaction(FNew) of
{atomic, Result} ->
?INFO_MSG("Pubsub tables updated correctly: ~p", [Result]);
{aborted, Reason} ->
?ERROR_MSG("Problem updating Pubsub tables:~n~p", [Reason])
end;
_ -> _ ->
ok ok
end. end.