m_rsc (zotonic_core v1.0.0-rc.10)
Link to this section Summary
Functions
Common properties, these are used by exporter and backup routines.
Delete a resource
Duplicate a resource.
Ensure that a resource has a name, caller must have update rights.
Read a whole resource. Return 'undefined' if the resource was not found, crash on database errors. The properties are filtered by the ACL.
Get the ACL fields for the resource with the id. Will always return a valid record, even if the resource does not exist.
Get all properties of a resource for export. This adds the page urls for all languages and the language neutral uri to the resource properties. Note that normally the page_url is a single property without translation, as it is generated using the current language context. As this export is used for UIs, all language variants are added.
Get the resource from the database, do not fetch the pivot fields and do not use the cached result. The properties are NOT filtered by the ACL.
Same as get_raw/2 but also lock the resource for update. The properties are NOT filtered by the ACL.
Insert a new resource
Return the categories and the inherited categories of the resource. Returns a list with category atoms
Check if the resource is in a category.
Return the categories and the inherited categories of the resource. Returns a list with category ids
Check if the resource is exactly the category
Fetch the value for the key from a model source
Make a resource authoritative. This removes the uri from the resource and sets the resource as 'authoritative'. The uri is added to the m_rsc_gone delete log.
Merge a resource with another, delete the loser.
Merge a resource with another, delete the loser.
Return the id of the resource with a certain unique name.
Return the id of the resource with the name
Used for dereferencing object edges inside template expressions
Return the list of objects with a certain predicate
Fetch a property from a resource. When the rsc does not exist, the property does not exist or the user does not have access rights to the property then return 'undefined'.
Fetch a property from a resource, no ACL check is done.
Given a page path, return {ok, Id} with the id of the found resource. When the resource does not have the page path, but did so once, this function will return {redirect, Id} to indicate that the page path was found but is no longer the current page path for the resource.
Fetch a resource id from any input
"Touch" the rsc, incrementing the version nr and the modification date/ modifier_id. This should be called as part of another update or transaction and does not resync the caches, and does not check the ACL. After "touching" the resource will be re-pivoted.
Update a resource
Determine the non informational uri of a resource.
Return the id of the resource with a certain uri.
Link to this section Types
Link to this type
digits/0
-type digits() :: 48..57.
Link to this type
duplicate_option/0
-type duplicate_option() :: edges | {edges, boolean()} | medium | {medium, boolean()}.
Link to this type
duplicate_options/0
-type duplicate_options() :: [duplicate_option()].
Link to this type
props/0
-type props() :: map().
Link to this type
props_all/0
-type props_all() :: props() | props_legacy().
Link to this type
props_legacy/0
-type props_legacy() :: proplists:proplist().
Link to this type
resource/0
-type resource() :: resource_id() | [digits()] | resource_name() | resource_uri() | resource_uri_map() | undefined.
Link to this type
resource_id/0
-type resource_id() :: integer().
Link to this type
resource_name/0
-type resource_name() :: string() | binary() | atom().
Link to this type
resource_uri/0
-type resource_uri() :: binary().
Link to this type
resource_uri_map/0
-type resource_uri_map() :: #{binary() => term()}.
Link to this type
update_function/0
Link to this section Functions
Link to this function
common_properties(Context)
Link to this function
delete(Id, Context)
Link to this function
delete(Id, FollowUp, Context)
Link to this function
duplicate(Id, Props, Context)
-spec duplicate(resource(), props_all(), z:context()) -> {ok, NewId :: resource_id()} | {error, Reason :: term()}.
Link to this function
duplicate(Id, Props, Options, Context)
-spec duplicate(resource(), props_all(), duplicate_options(), z:context()) -> {ok, NewId :: resource_id()} | {error, Reason :: term()}.
Link to this function
ensure_name(Id, Context)
-spec ensure_name(integer(), z:context()) -> ok.
Link to this function
exists(Id, Context)
Link to this function
get(Id, Context)
Link to this function
get_acl_props(Id, Context)
Link to this function
get_export(Id, Context)
Link to this function
get_raw(Id, Context)
Link to this function
get_raw_lock(Id, Context)
Link to this function
insert(Props, Context)
-spec insert(props_all(), z:context()) -> {ok, resource_id()} | {error, term()}.
Link to this function
insert(Props, Options, Context)
-spec insert(props_all(), list(), z:context()) -> {ok, resource_id()} | {error, term()}.
Link to this function
is_a(Id, Context)
Link to this function
is_a(Id, Cat, Context)
-spec is_a(resource(), m_category:category(), z:context()) -> boolean().
Link to this function
is_a_id(Id, Context)
Link to this function
is_cat(Id, Cat, Context)
Link to this function
is_deletable(Id, Context)
Link to this function
is_editable(Id, Context)
Link to this function
is_linkable(Id, Context)
Link to this function
is_me(Id, Context)
Link to this function
is_visible(Id, Context)
Link to this function
m_delete(_, Msg, Context)
Link to this function
m_get(Rest, Msg, Context)
-spec m_get(list(), zotonic_model:opt_msg(), z:context()) -> zotonic_model:return().
Link to this function
make_authoritative(RscId, Context)
-spec make_authoritative(m_rsc:resource(), z:context()) -> {ok, resource_id()} | {error, term()}.
Link to this function
media(Id, Context)
Link to this function
merge_delete(WinnerId, LoserId, Context)
Link to this function
merge_delete(WinnerId, LoserId, Options, Context)
Link to this function
name_lookup(Name, Context)
-spec name_lookup(resource_name(), z:context()) -> resource_id() | undefined.
Link to this function
name_to_id(Name, Context)
-spec name_to_id(resource_name(), z:context()) -> {ok, resource_id()} | {error, {unknown_rsc, resource_name()}}.
Link to this function
name_to_id_cat(Name, Cat, Context)
-spec name_to_id_cat(resource(), resource_name(), z:context()) -> {ok, resource_id()} | {error, {unknown_rsc_cat, resource(), resource_name()}}.
Link to this function
o(Id, Context)
Link to this function
o(Id, Predicate, Context)
Link to this function
o(Id, Predicate, N, Context)
-spec o(resource(), atom(), pos_integer(), z:context()) -> resource_id() | undefined.
Link to this function
op(Id, Context)
Link to this function
p(Id, Property, Context)
Link to this function
p(Id, Property, DefaultValue, Context)
Link to this function
p_no_acl(Id, Predicate, Context)
Link to this function
page_path_to_id(Path, Context)
-spec page_path_to_id(binary() | string(), z:context()) -> {ok, resource_id()} | {redirect, resource_id()} | {error, {unknown_page_path, binary()}} | {error, {illegal_page_path, binary(), length | unicode}}.
Link to this function
page_url(Id, Context)
Link to this function
page_url_abs(Id, Context)
Link to this function
rid(Id, Context)
-spec rid(resource() | #trans{}, z:context()) -> resource_id() | undefined.
Link to this function
s(Id, Context)
Link to this function
s(Id, Predicate, Context)
Link to this function
s(Id, Predicate, N, Context)
-spec s(resource(), atom(), pos_integer(), z:context()) -> resource_id() | undefined.
Link to this function
sp(Id, Context)
Link to this function
touch(Id, Context)
-spec touch(resource(), z:context()) -> {ok, resource_id()} | {error, enoent}.
Link to this function
update(Id, Props, Context)
-spec update(resource(), props_all() | update_function(), z:context()) -> {ok, resource()} | {error, term()}.
Link to this function
update(Id, Props, Options, Context)
-spec update(resource(), props_all() | update_function(), list(), z:context()) -> {ok, resource()} | {error, term()}.
Link to this function
uri(Id, Context)
Link to this function
uri_lookup(Uri, Context)
-spec uri_lookup(resource_uri() | string(), z:context()) -> resource_id() | undefined.