From 8fedc945bfc1a470a616e7a503d1672ba1f8e6ef Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Fri, 24 Jul 2015 13:44:01 +0200 Subject: [PATCH] Allow migration of old pubsub items with xmlelement in body (#479) --- src/pubsub_migrate.erl | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pubsub_migrate.erl b/src/pubsub_migrate.erl index e48efcd49..dc01b9af6 100644 --- a/src/pubsub_migrate.erl +++ b/src/pubsub_migrate.erl @@ -29,7 +29,8 @@ -include("pubsub.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() -> F = fun () -> @@ -57,6 +58,27 @@ update_item_database_binary() -> ?INFO_MSG("Pubsub items table has been binarized: ~p", [Result]) 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() -> F = fun () ->