mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Enforce pubsub node removal, revert previous commit (#1320)
This reverts commit 2976c2d921
.
and enforce node purge/removal instead
This commit is contained in:
parent
2976c2d921
commit
bcc04d93e1
@ -176,3 +176,9 @@
|
|||||||
creation ,% :: {erlang:timestamp(), jlib:ljid()},
|
creation ,% :: {erlang:timestamp(), jlib:ljid()},
|
||||||
payload % :: mod_pubsub:payload()
|
payload % :: mod_pubsub:payload()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
-record(pubsub_orphan,
|
||||||
|
{
|
||||||
|
nodeid ,% :: mod_pubsub:nodeIdx(),
|
||||||
|
items = [] % :: list()
|
||||||
|
}).
|
||||||
|
@ -58,6 +58,9 @@ init(_Host, _ServerHost, _Opts) ->
|
|||||||
ejabberd_mnesia:create(?MODULE, pubsub_item,
|
ejabberd_mnesia:create(?MODULE, pubsub_item,
|
||||||
[{disc_only_copies, [node()]},
|
[{disc_only_copies, [node()]},
|
||||||
{attributes, record_info(fields, pubsub_item)}]),
|
{attributes, record_info(fields, pubsub_item)}]),
|
||||||
|
ejabberd_mnesia:create(?MODULE, pubsub_orphan,
|
||||||
|
[{disc_copies, [node()]},
|
||||||
|
{attributes, record_info(fields, pubsub_orphan)}]),
|
||||||
ItemsFields = record_info(fields, pubsub_item),
|
ItemsFields = record_info(fields, pubsub_item),
|
||||||
case mnesia:table_info(pubsub_item, attributes) of
|
case mnesia:table_info(pubsub_item, attributes) of
|
||||||
ItemsFields -> ok;
|
ItemsFields -> ok;
|
||||||
@ -138,8 +141,10 @@ delete_node(Nodes) ->
|
|||||||
Reply = lists:map(fun (#pubsub_node{id = Nidx} = PubsubNode) ->
|
Reply = lists:map(fun (#pubsub_node{id = Nidx} = PubsubNode) ->
|
||||||
{result, States} = get_states(Nidx),
|
{result, States} = get_states(Nidx),
|
||||||
lists:foreach(fun (State) ->
|
lists:foreach(fun (State) ->
|
||||||
del_state(State)
|
del_items(Nidx, State#pubsub_state.items),
|
||||||
|
del_state(State#pubsub_state{items = []})
|
||||||
end, States),
|
end, States),
|
||||||
|
del_orphan_items(Nidx),
|
||||||
{PubsubNode, lists:flatmap(Tr, States)}
|
{PubsubNode, lists:flatmap(Tr, States)}
|
||||||
end, Nodes),
|
end, Nodes),
|
||||||
{result, {default, broadcast, Reply}}.
|
{result, {default, broadcast, Reply}}.
|
||||||
@ -472,6 +477,7 @@ purge_node(Nidx, Owner) ->
|
|||||||
set_state(S#pubsub_state{items = []})
|
set_state(S#pubsub_state{items = []})
|
||||||
end,
|
end,
|
||||||
States),
|
States),
|
||||||
|
del_orphan_items(Nidx),
|
||||||
{result, {default, broadcast}};
|
{result, {default, broadcast}};
|
||||||
_ ->
|
_ ->
|
||||||
{error, xmpp:err_forbidden()}
|
{error, xmpp:err_forbidden()}
|
||||||
@ -696,9 +702,15 @@ set_state(State) when is_record(State, pubsub_state) ->
|
|||||||
%set_state(_) -> {error, ?ERR_INTERNAL_SERVER_ERROR}.
|
%set_state(_) -> {error, ?ERR_INTERNAL_SERVER_ERROR}.
|
||||||
|
|
||||||
%% @doc <p>Delete a state from database.</p>
|
%% @doc <p>Delete a state from database.</p>
|
||||||
del_state(#pubsub_state{stateid = {LJID, Nidx}, items = Items}) ->
|
del_state(#pubsub_state{stateid = {Key, Nidx}, items = Items}) ->
|
||||||
del_items(Nidx, Items),
|
case Items of
|
||||||
mnesia:delete({pubsub_state, {LJID, Nidx}}).
|
[] ->
|
||||||
|
ok;
|
||||||
|
_ ->
|
||||||
|
Orphan = #pubsub_orphan{nodeid = Nidx, items = Items},
|
||||||
|
mnesia:write(Orphan)
|
||||||
|
end,
|
||||||
|
mnesia:delete({pubsub_state, {Key, Nidx}}).
|
||||||
|
|
||||||
%% @doc Returns the list of stored items for a given node.
|
%% @doc Returns the list of stored items for a given node.
|
||||||
%% <p>For the default PubSub module, items are stored in Mnesia database.</p>
|
%% <p>For the default PubSub module, items are stored in Mnesia database.</p>
|
||||||
@ -801,6 +813,15 @@ del_items(Nidx, ItemIds) ->
|
|||||||
end,
|
end,
|
||||||
ItemIds).
|
ItemIds).
|
||||||
|
|
||||||
|
del_orphan_items(Nidx) ->
|
||||||
|
case mnesia:read({pubsub_orphan, Nidx}) of
|
||||||
|
[#pubsub_orphan{items = ItemIds}] ->
|
||||||
|
del_items(Nidx, ItemIds),
|
||||||
|
mnesia:delete({pubsub_orphan, Nidx});
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
get_item_name(_Host, _Node, Id) ->
|
get_item_name(_Host, _Node, Id) ->
|
||||||
Id.
|
Id.
|
||||||
|
|
||||||
|
@ -641,9 +641,6 @@ set_state(Nidx, State) ->
|
|||||||
|
|
||||||
del_state(Nidx, JID) ->
|
del_state(Nidx, JID) ->
|
||||||
J = encode_jid(JID),
|
J = encode_jid(JID),
|
||||||
catch ejabberd_sql:sql_query_t(
|
|
||||||
?SQL("delete from pubsub_item where publisher=%(J)s"
|
|
||||||
" and nodeid=%(Nidx)d")),
|
|
||||||
catch ejabberd_sql:sql_query_t(
|
catch ejabberd_sql:sql_query_t(
|
||||||
?SQL("delete from pubsub_state"
|
?SQL("delete from pubsub_state"
|
||||||
" where jid=%(J)s and nodeid=%(Nidx)d")),
|
" where jid=%(J)s and nodeid=%(Nidx)d")),
|
||||||
|
Loading…
Reference in New Issue
Block a user