Allow migration of old pubsub items with xmlelement in body (#479)
This commit is contained in:
parent
d481017746
commit
8fedc945bf
|
@ -29,7 +29,8 @@
|
||||||
-include("pubsub.hrl").
|
-include("pubsub.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
|
||||||
-export([update_node_database/2, update_state_database/2, update_lastitem_database/2]).
|
-export([update_node_database/2, update_state_database/2]).
|
||||||
|
-export([update_item_database/2, update_lastitem_database/2]).
|
||||||
|
|
||||||
update_item_database_binary() ->
|
update_item_database_binary() ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
|
@ -57,6 +58,27 @@ update_item_database_binary() ->
|
||||||
?INFO_MSG("Pubsub items table has been binarized: ~p", [Result])
|
?INFO_MSG("Pubsub items table has been binarized: ~p", [Result])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
update_item_database(_Host, _ServerHost) ->
|
||||||
|
F = fun() ->
|
||||||
|
?INFO_MSG("Migration of old pubsub items...", []),
|
||||||
|
lists:foreach(fun (Key) ->
|
||||||
|
[Item] = mnesia:read({pubsub_item, Key}),
|
||||||
|
Payload = [xmlelement_to_xmlel(El) || El <- Item#pubsub_item.payload],
|
||||||
|
mnesia:write(Item#pubsub_item{payload=Payload})
|
||||||
|
end,
|
||||||
|
mnesia:all_keys(pubsub_item))
|
||||||
|
end,
|
||||||
|
case mnesia:transaction(F) of
|
||||||
|
{aborted, Reason} ->
|
||||||
|
?ERROR_MSG("Failed to migrate old pubsub items to xmlel: ~p", [Reason]);
|
||||||
|
{atomic, Result} ->
|
||||||
|
?INFO_MSG("Pubsub items has been migrated: ~p", [Result])
|
||||||
|
end.
|
||||||
|
|
||||||
|
xmlelement_to_xmlel({xmlelement, A, B, C}) when is_list(C) ->
|
||||||
|
{xmlel, A, B, [xmlelement_to_xmlel(El) || El <- C]};
|
||||||
|
xmlelement_to_xmlel(El) ->
|
||||||
|
El.
|
||||||
|
|
||||||
update_node_database_binary() ->
|
update_node_database_binary() ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
|
|
Loading…
Reference in New Issue