diff options
author | Christophe Romain <christophe.romain@process-one.net> | 2015-07-24 13:44:01 +0200 |
---|---|---|
committer | Christophe Romain <christophe.romain@process-one.net> | 2015-07-24 13:44:01 +0200 |
commit | 8fedc945bfc1a470a616e7a503d1672ba1f8e6ef (patch) | |
tree | c65483e55d04bc8d31021471d0a8381ee6939724 /src/pubsub_migrate.erl | |
parent | Merge pull request #642 from weiss/pep-on-caps-update (diff) |
Allow migration of old pubsub items with xmlelement in body (#479)
Diffstat (limited to 'src/pubsub_migrate.erl')
-rw-r--r-- | src/pubsub_migrate.erl | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/pubsub_migrate.erl b/src/pubsub_migrate.erl index e48efcd4..dc01b9af 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 () -> |