Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes for backup restore.

  • Loading branch information...
commit 429479cf2b64ba111e56553c5a6b6341fe37ba03 1 parent d36ceb7
@mworrell mworrell authored
View
5 modules/mod_rest/controllers/controller_rest_rsc.erl
@@ -185,8 +185,11 @@ get_id(Context) ->
get_rsc(Id, Context) ->
Props = m_rsc:get(Id, Context),
Filtered = lists:filter(fun({K,_}) -> z_acl:rsc_prop_visible(Id, K, Context) end, Props),
- Complete = [
+ IsA = m_rsc:is_a(Id, Context),
+ Complete = [
+ {category, hd(IsA)},
{page_url, z_convert:to_binary(z_context:abs_url(m_rsc:p(Id, page_url, Context), Context))},
+ {computed_category, IsA},
{computed_site_name, z_context:site(Context)},
{computed_address_country, m_l10n:country_name(proplists:get_value(address_country, Props), Context)},
{computed_mail_country, m_l10n:country_name(proplists:get_value(mail_country, Props), Context)},
View
66 modules/mod_rest/mod_rest.erl
@@ -46,43 +46,53 @@ observe_content_types_dispatch(#content_types_dispatch{}, Acc, _Context) ->
observe_rsc_upload(#rsc_upload{id=Id, format=bert, data=Data}, Context) ->
case catch bert:decode(Data) of
Props when is_list(Props) ->
- rsc_upload(proplists:get_value(id, Props), Props, Context);
+ rsc_upload(Id, Props, Context);
_ ->
{error, badarg}
end.
rsc_upload(undefined, Props, Context) ->
- UpdateProps = lists:filter(fun is_updateable/1, Props),
- m_rsc_update:insert(UpdateProps, [is_import], Context);
+ m_rsc_update:insert(update_props(Props, Context), [is_import], Context);
rsc_upload(Id, Props, Context) when is_integer(Id) ->
- UpdateProps = lists:filter(fun is_updateable/1, Props),
- Site = z_context:site(Context),
- case proplists:lookup(computed_site, Props) of
- {site, Site} ->
- % Import into our own site, keep the id
- m_rsc_update:update(Id, Props, [is_import], Context);
- _ ->
- % Import of an id from another site
- case m_rsc:exists(Id, Context) of
- true ->
- m_rsc_update:insert(UpdateProps, [is_import], Context);
- false ->
- m_rsc_update:update(Id, Props, [is_import], Context)
+ m_rsc_update:update(Id, update_props(Props, Context), [is_import], Context).
+
+update_props(Props, Context) ->
+ UpdateProps = lists:filter(fun({K,_}) ->
+ is_updateable(z_convert:to_binary(K))
+ end,
+ Props),
+ [{category, map_category(Props, Context)} | UpdateProps ].
+
+map_category(Props, Context) ->
+ case proplists:get_value(computed_category, Props) of
+ undefined ->
+ other;
+ List ->
+ case lists:dropwhile(fun(Name) ->
+ case m_category:name_to_id(Name, Context) of
+ {ok, _} -> false;
+ {error, _} -> true
+ end
+ end,
+ List) of
+ [] -> other;
+ [N|_] -> N
end
end.
-
-is_updateable({<<"id">>, _}) -> false;
-is_updateable({<<"version">>, _}) -> false;
-is_updateable({<<"medium">>, _}) -> false;
-is_updateable({<<"created">>, _}) -> false;
-is_updateable({<<"creator_id">>, _}) -> false;
-is_updateable({<<"modified">>, _}) -> false;
-is_updateable({<<"modifier_id">>, _}) -> false;
-is_updateable({<<"page_url">>, _}) -> false;
-is_updateable({<<"props">>, _}) -> false;
-is_updateable({<<"computed_", _/binary>>, _}) -> false;
-is_updateable({<<"pivot_", _/binary>>, _}) -> false;
+is_updateable(<<"id">>) -> false;
+is_updateable(<<"category_id">>) -> false;
+is_updateable(<<"category">>) -> false;
+is_updateable(<<"version">>) -> false;
+is_updateable(<<"medium">>) -> false;
+is_updateable(<<"created">>) -> false;
+is_updateable(<<"creator_id">>) -> false;
+is_updateable(<<"modified">>) -> false;
+is_updateable(<<"modifier_id">>) -> false;
+is_updateable(<<"page_url">>) -> false;
+is_updateable(<<"props">>) -> false;
+is_updateable(<<"computed_", _/binary>>) -> false;
+is_updateable(<<"pivot_", _/binary>>) -> false;
is_updateable(_) -> true.
Please sign in to comment.
Something went wrong with that request. Please try again.