J = encode_jid(GenKey),
{result,
case ejabberd_sql:sql_query_t(
- ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(affiliation)s "
+ ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(affiliation)s "
"from pubsub_state i, pubsub_node n where "
"i.nodeid = n.nodeid and jid=%(J)s and host=%(H)s")) of
{selected, RItems} ->
Query = case SubKey of
GenKey ->
GJLike = <<(encode_jid_like(GenKey))/binary, "/%">>,
- ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+ ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid and "
"(jid=%(GJ)s or jid like %(GJLike)s escape '^') and host=%(H)s");
_ ->
SJ = encode_jid(SubKey),
- ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+ ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid and "
"jid in (%(SJ)s, %(GJ)s) and host=%(H)s")
Query = case SubKey of
GenKey ->
GJLike = <<(encode_jid_like(GenKey))/binary, "/%">>,
- ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+ ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n, pubsub_node_option o "
"where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
"name='send_last_published_item' and val='on_sub_and_presence' and "
"(jid=%(GJ)s or jid like %(GJLike)s escape '^') and host=%(H)s");
_ ->
SJ = encode_jid(SubKey),
- ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+ ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n, pubsub_node_option o "
"where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
"name='send_last_published_item' and val='on_sub_and_presence' and "
Query = case SubKey of
GenKey ->
GJLike = <<(node_flat_sql:encode_jid_like(GenKey))/binary, "/%">>,
- ?SQL("select @(host)s, @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+ ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid and "
"(jid=%(GJ)s or jid like %(GJLike)s escape '^') and host like %(HLike)s escape '^'");
_ ->
SJ = node_flat_sql:encode_jid(SubKey),
- ?SQL("select @(host)s, @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+ ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid and "
"jid in (%(SJ)s,%(GJ)s) and host like %(HLike)s escape '^'")
Query = case SubKey of
GenKey ->
GJLike = <<(node_flat_sql:encode_jid_like(GenKey))/binary, "/%">>,
- ?SQL("select @(host)s, @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+ ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n, pubsub_node_option o "
"where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
"name='send_last_published_item' and val='on_sub_and_presence' and "
"(jid=%(GJ)s or jid like %(GJLike)s escape '^') and host like %(HLike)s escape '^'");
_ ->
SJ = node_flat_sql:encode_jid(SubKey),
- ?SQL("select @(host)s, @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+ ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
"from pubsub_state i, pubsub_node n, pubsub_node_option o "
"where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
"name='send_last_published_item' and val='on_sub_and_presence' and "
{result, OldNidx} ->
catch
ejabberd_sql:sql_query_t(
- ?SQL("delete from pubsub_node_option where "
- "nodeid=%(OldNidx)d")),
+ ?SQL("delete from pubsub_node_option "
+ "where nodeid=%(OldNidx)d")),
catch
ejabberd_sql:sql_query_t(
- ?SQL("update pubsub_node set"
- " host=%(H)s,"
- " node=%(Node)s,"
- " parent=%(Parent)s,"
- " type=%(Type)s "
- "where nodeid=%(OldNidx)d")),
+ ?SQL("update pubsub_node set"
+ " host=%(H)s, node=%(Node)s,"
+ " parent=%(Parent)s, plugin=%(Type)s "
+ "where nodeid=%(OldNidx)d")),
OldNidx;
_ ->
catch
ejabberd_sql:sql_query_t(
- ?SQL("insert into pubsub_node(host, node, "
- "parent, type) values("
- "%(H)s, %(Node)s, %(Parent)s, %(Type)s)")),
+ ?SQL("insert into pubsub_node(host, node, parent, plugin) "
+ "values(%(H)s, %(Node)s, %(Parent)s, %(Type)s)")),
case nodeidx(Host, Node) of
{result, NewNidx} -> NewNidx;
_ -> none % this should not happen
SValue = misc:term_to_expr(Value),
catch
ejabberd_sql:sql_query_t(
- ?SQL("insert into pubsub_node_option(nodeid, "
- "name, val) values ("
- "%(Nidx)d, %(SKey)s, %(SValue)s)"))
+ ?SQL("insert into pubsub_node_option(nodeid, name, val) "
+ "values (%(Nidx)d, %(SKey)s, %(SValue)s)"))
end,
Record#pubsub_node.options),
{result, Nidx}
H = node_flat_sql:encode_host(Host),
case catch
ejabberd_sql:sql_query_t(
- ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
- "pubsub_node where host=%(H)s and node=%(Node)s"))
+ ?SQL("select @(node)s, @(parent)s, @(plugin)s, @(nodeid)d from pubsub_node "
+ "where host=%(H)s and node=%(Node)s"))
of
{selected, [RItem]} ->
raw_to_node(Host, RItem);
get_node(Nidx) ->
case catch
ejabberd_sql:sql_query_t(
- ?SQL("select @(host)s, @(node)s, @(parent)s, @(type)s from "
- "pubsub_node where nodeid=%(Nidx)d"))
+ ?SQL("select @(host)s, @(node)s, @(parent)s, @(plugin)s from pubsub_node "
+ "where nodeid=%(Nidx)d"))
of
{selected, [{Host, Node, Parent, Type}]} ->
raw_to_node(Host, {Node, Parent, Type, Nidx});
H = node_flat_sql:encode_host(Host),
case catch
ejabberd_sql:sql_query_t(
- ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
- "pubsub_node where host=%(H)s"))
+ ?SQL("select @(node)s, @(parent)s, @(plugin)s, @(nodeid)d from pubsub_node "
+ "where host=%(H)s"))
of
{selected, RItems} ->
[raw_to_node(Host, Item) || Item <- RItems];
H = node_flat_sql:encode_host(Host),
case catch
ejabberd_sql:sql_query_t(
- ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
- "pubsub_node where host=%(H)s and parent=%(Node)s"))
+ ?SQL("select @(node)s, @(parent)s, @(plugin)s, @(nodeid)d from pubsub_node "
+ "where host=%(H)s and parent=%(Node)s"))
of
{selected, RItems} ->
[raw_to_node(Host, Item) || Item <- RItems];
{error, _} ->
[];
Rec ->
+ Type = Rec#pubsub_node.type,
H = node_flat_sql:encode_host(Host),
N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "/%">>,
Sub = case catch
ejabberd_sql:sql_query_t(
- ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
- "pubsub_node where host=%(H)s"
- " and node like %(N)s escape '^'"
- " and \"type\"='hometree'"))
+ ?SQL("select @(node)s, @(parent)s, @(plugin)s, @(nodeid)d from pubsub_node "
+ "where host=%(H)s and plugin=%(Type)s and"
+ " (parent=%(Node)s or parent like %(N)s escape '^')"))
of
{selected, RItems} ->
[raw_to_node(Host, Item) || Item <- RItems];
end.
delete_node(Host, Node) ->
- H = node_flat_sql:encode_host(Host),
- N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "/%">>,
- Removed = get_subnodes_tree(Host, Node),
- catch ejabberd_sql:sql_query_t(
- ?SQL("delete from pubsub_node where host=%(H)s"
- " and (node=%(Node)s"
- " or (\"type\"='hometree' and node like %(N)s escape '^'))")),
- Removed.
+ lists:map(
+ fun(Rec) ->
+ Nidx = Rec#pubsub_node.id,
+ catch ejabberd_sql:sql_query_t(
+ ?SQL("delete from pubsub_node where nodeid=%(Nidx)d")),
+ Rec
+ end, get_subnodes_tree(Host, Node)).
%% helpers
raw_to_node(Host, [Node, Parent, Type, Nidx]) ->
raw_to_node(Host, {Node, Parent, Type, Nidx}) ->
Options = case catch
ejabberd_sql:sql_query_t(
- ?SQL("select @(name)s, @(val)s from pubsub_node_option "
- "where nodeid=%(Nidx)d"))
+ ?SQL("select @(name)s, @(val)s from pubsub_node_option "
+ "where nodeid=%(Nidx)d"))
of
{selected, ROptions} ->
DbOpts = lists:map(fun ({Key, Value}) ->
<<>> -> [];
_ -> [Parent]
end,
- #pubsub_node{nodeid = {Host, Node},
- parents = Parents,
- id = Nidx, type = Type, options = Options}.
+ #pubsub_node{nodeid = {Host, Node}, id = Nidx,
+ parents = Parents, type = Type, options = Options}.
nodeidx(Host, Node) ->
H = node_flat_sql:encode_host(Host),
case catch
ejabberd_sql:sql_query_t(
- ?SQL("select @(nodeid)d from pubsub_node where "
- "host=%(H)s and node=%(Node)s"))
+ ?SQL("select @(nodeid)d from pubsub_node "
+ "where host=%(H)s and node=%(Node)s"))
of
{selected, [{Nidx}]} ->
{result, Nidx};