]> granicus.if.org Git - ejabberd/commitdiff
* src/mod_pubsub/mod_pubsub.erl: Fix update pubsub tables from
authorBadlop <badlop@process-one.net>
Tue, 16 Dec 2008 17:44:48 +0000 (17:44 +0000)
committerBadlop <badlop@process-one.net>
Tue, 16 Dec 2008 17:44:48 +0000 (17:44 +0000)
ejabberd 1.x to 2.x (EJAB-817)

SVN Revision: 1734

ChangeLog
src/mod_pubsub/mod_pubsub.erl

index 7315272f299cf2eda2f1e7a83dbaf28bf9f002e3..cc6587259e8250810b003af5095f9c3fa21199ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 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: Mention as optional Requirements: mysql, pgsql
index 81ed6f64e50e023a7f87322b4c03b206249638dd..5061bd4ee1bb6ec419134db65b8a2a6c81cafb07 100644 (file)
@@ -238,60 +238,66 @@ update_database(Host) ->
        [host_node, host_parent, info] ->
            ?INFO_MSG("upgrade pubsub tables",[]),
            F = fun() ->
-                       NewRecords =
-                           lists:foldl(
-                             fun({pubsub_node, NodeId, ParentId, {nodeinfo, Items, Options, Entities}}, RecList) ->
-                                     ItemsList =
-                                         lists:foldl(
-                                           fun({item, IID, Publisher, Payload}, Acc) ->
-                                                   C = {Publisher, unknown},
-                                                   M = {Publisher, now()},
-                                                   mnesia:write(
-                                                     #pubsub_item{itemid = {IID, NodeId},
-                                                                  creation = C,
-                                                                  modification = M,
-                                                                  payload = Payload}),
-                                                   [{Publisher, IID} | Acc]
-                                           end, [], Items),
-                                     Owners =
-                                         dict:fold(
-                                           fun(JID, {entity, Aff, Sub}, Acc) ->
-                                                   UsrItems =
-                                                       lists:foldl(
-                                                         fun({P, I}, IAcc) ->
-                                                                 case P of
-                                                                     JID -> [I | IAcc];
-                                                                     _ -> IAcc
-                                                                 end
-                                                         end, [], ItemsList),
-                                                   mnesia:write(
-                                                     #pubsub_state{stateid = {JID, NodeId},
-                                                                   items = UsrItems,
-                                                                   affiliation = Aff,
-                                                                   subscription = Sub}),
-                                                   case Aff of
-                                                       owner -> [JID | Acc];
-                                                       _ -> Acc
-                                                   end
-                                           end, [], Entities),
-                                     mnesia:delete({pubsub_node, NodeId}),
-                                     [#pubsub_node{nodeid = NodeId,
-                                                   parentid = ParentId,
-                                                   owners = Owners,
-                                                   options = Options} |
-                                      RecList]
-                             end, [],
-                             mnesia:match_object(
-                               {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)
+                       lists:foldl(
+                         fun({pubsub_node, NodeId, ParentId, {nodeinfo, Items, Options, Entities}}, RecList) ->
+                                 ItemsList =
+                                     lists:foldl(
+                                       fun({item, IID, Publisher, Payload}, Acc) ->
+                                               C = {Publisher, unknown},
+                                               M = {Publisher, now()},
+                                               mnesia:write(
+                                                 #pubsub_item{itemid = {IID, NodeId},
+                                                              creation = C,
+                                                              modification = M,
+                                                              payload = Payload}),
+                                               [{Publisher, IID} | Acc]
+                                       end, [], Items),
+                                 Owners =
+                                     dict:fold(
+                                       fun(JID, {entity, Aff, Sub}, Acc) ->
+                                               UsrItems =
+                                                   lists:foldl(
+                                                     fun({P, I}, IAcc) ->
+                                                             case P of
+                                                                 JID -> [I | IAcc];
+                                                                 _ -> IAcc
+                                                             end
+                                                     end, [], ItemsList),
+                                               mnesia:write(
+                                                 #pubsub_state{stateid = {JID, NodeId},
+                                                               items = UsrItems,
+                                                               affiliation = Aff,
+                                                               subscription = Sub}),
+                                               case Aff of
+                                                   owner -> [JID | Acc];
+                                                   _ -> Acc
+                                               end
+                                       end, [], Entities),
+                                 mnesia:delete({pubsub_node, NodeId}),
+                                 [#pubsub_node{nodeid = NodeId,
+                                               parentid = ParentId,
+                                               owners = Owners,
+                                               options = Options} |
+                                  RecList]
+                         end, [],
+                         mnesia:match_object(
+                           {pubsub_node, {Host, '_'}, '_', '_'}))
                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
     end.