Compare commits

...

8 Commits

Author SHA1 Message Date
Jocelyn Fiat
383b0dbc47 Create book.json 2015-11-13 15:56:41 +01:00
Jocelyn Fiat
a976b1e21a Create doc/readme.md 2015-11-13 15:53:45 +01:00
04df6b85f0 Removed unused local variables. 2015-11-12 18:48:37 +01:00
79d30ee3a7 Added export of core data, such as users, path_aliases, custom_values.
Added export of node revisions.
2015-11-12 18:19:06 +01:00
a5973c9c8a Added exportation solution via CMS_HOOK_EXPORT.
Updated blocks settings for demo example project.
2015-11-10 10:30:10 +01:00
420051cd14 Redesigned hooks system (moving from CMS_RESPONSE to CMS_API).
Indeed, hooks does not require RESPONSE interface,
   and should be setup before, at the system level (i.e CMS_API)
Added exportation solution via CMS_HOOK_EXPORT.
Updated blocks settings for demo example project.
2015-11-09 21:07:02 +01:00
6b3ff6f980 Fixed list item computation for ini file, especially with included ini file. 2015-11-02 21:07:26 +01:00
360855a558 Fixed recent_changes module to allow alias of recent_changes blocks.
Factorized code in CMS_RESPONSE by reusing add_block.
2015-11-02 18:54:30 +01:00
28 changed files with 816 additions and 34 deletions

1
book.json Normal file
View File

@@ -0,0 +1 @@
{}

0
doc/readme.md Normal file
View File

View File

@@ -9,30 +9,17 @@ management.conditions[]=is_front
feed.news.weight=3 feed.news.weight=3
feed.news.region=feed_news feed.news.region=feed_news
feed.news.region=content feed.news.region=content
feed.news.condition=<none> feed.news.condition=is_front
feed.forum.weight=2 feed.forum.weight=2
feed.forum.region=feed_forum feed.forum.region=feed_forum
feed.forum.region=<none> feed.forum.region=content
feed.forum.condition=<none> feed.forum.condition=is_front
feed.forum.options[size]=15 feed.forum.options[size]=5
#Updates #Updates
recent_changes.region=content recent_changes.region=content
recent_changes.condition=is_front recent_changes.condition=is_front
recent_changes.title=Updates recent_changes.title=Updates
recent_changes.options[size]=3 recent_changes.options[size]=4
#Aliases
&aliases[foo]=management
&aliases[bar]=feed.forum
foo.region=content
foo.condition=is_front
foo.weight=-10
bar.region=content
bar.condition=is_front
bar.title=Bar

View File

@@ -442,7 +442,17 @@ feature {NONE} -- Implementation
j := k.index_of (']', i + 1) j := k.index_of (']', i + 1)
if j = i + 1 then -- ends_with "[]" if j = i + 1 then -- ends_with "[]"
k.keep_head (i - 1) k.keep_head (i - 1)
if attached {LIST [STRING_8]} items.item (k) as l_list then if
a_section_prefix /= Void and then
attached {LIST [STRING_8]} items.item (a_section_prefix + {STRING_32} "." + k) as l_list
then
lst := l_list
elseif
attached last_section_name as l_section_prefix and then
attached {LIST [STRING_8]} items.item (l_section_prefix + {STRING_32} "." + k) as l_list
then
lst := l_list
elseif attached {LIST [STRING_8]} items.item (k) as l_list then
lst := l_list lst := l_list
else else
create {ARRAYED_LIST [STRING_8]} lst.make (1) create {ARRAYED_LIST [STRING_8]} lst.make (1)

View File

@@ -54,6 +54,7 @@ feature -- Access: router
l_role_handler: CMS_ROLE_HANDLER l_role_handler: CMS_ROLE_HANDLER
l_admin_cache_handler: CMS_ADMIN_CACHE_HANDLER l_admin_cache_handler: CMS_ADMIN_CACHE_HANDLER
l_admin_export_handler: CMS_ADMIN_EXPORT_HANDLER
l_uri_mapping: WSF_URI_MAPPING l_uri_mapping: WSF_URI_MAPPING
do do
@@ -73,6 +74,10 @@ feature -- Access: router
create l_uri_mapping.make_trailing_slash_ignored ("/admin/cache", l_admin_cache_handler) create l_uri_mapping.make_trailing_slash_ignored ("/admin/cache", l_admin_cache_handler)
a_router.map (l_uri_mapping, a_router.methods_get_post) a_router.map (l_uri_mapping, a_router.methods_get_post)
create l_admin_export_handler.make (a_api)
create l_uri_mapping.make_trailing_slash_ignored ("/admin/export", l_admin_export_handler)
a_router.map (l_uri_mapping, a_router.methods_get_post)
create l_user_handler.make (a_api) create l_user_handler.make (a_api)
a_router.handle ("/admin/add/user", l_user_handler, a_router.methods_get_post) a_router.handle ("/admin/add/user", l_user_handler, a_router.methods_get_post)
a_router.handle ("/admin/user/{id}", l_user_handler, a_router.methods_get) a_router.handle ("/admin/user/{id}", l_user_handler, a_router.methods_get)
@@ -84,8 +89,6 @@ feature -- Access: router
a_router.handle ("/admin/role/{id}", l_role_handler, a_router.methods_get) a_router.handle ("/admin/role/{id}", l_role_handler, a_router.methods_get)
a_router.handle ("/admin/role/{id}/edit", l_role_handler, a_router.methods_get_post) a_router.handle ("/admin/role/{id}/edit", l_role_handler, a_router.methods_get_post)
a_router.handle ("/admin/role/{id}/delete", l_role_handler, a_router.methods_get_post) a_router.handle ("/admin/role/{id}/delete", l_role_handler, a_router.methods_get_post)
end end
feature -- Security feature -- Security
@@ -101,6 +104,8 @@ feature -- Security
Result.force ("install modules") Result.force ("install modules")
Result.force ("admin core caches") Result.force ("admin core caches")
Result.force ("clear blocks cache") Result.force ("clear blocks cache")
Result.force ("admin export")
Result.force ("export core")
end end
feature -- Hooks feature -- Hooks
@@ -132,6 +137,10 @@ feature -- Hooks
end end
-- Per module cache permission! -- Per module cache permission!
create lnk.make ("Cache", "admin/cache") create lnk.make ("Cache", "admin/cache")
a_menu_system.management_menu.extend (lnk)
-- Per module export permission!
create lnk.make ("Export", "admin/export")
a_menu_system.management_menu.extend (lnk) a_menu_system.management_menu.extend (lnk)
end end

View File

@@ -0,0 +1,116 @@
note
description: "[
Administrate export functionality.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_ADMIN_EXPORT_HANDLER
inherit
CMS_HANDLER
WSF_URI_HANDLER
rename
new_mapping as new_uri_mapping
end
WSF_RESOURCE_HANDLER_HELPER
redefine
do_get,
do_post
end
REFACTORING_HELPER
create
make
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
execute_methods (req, res)
end
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
local
l_response: CMS_RESPONSE
s: STRING
f: CMS_FORM
do
create {GENERIC_VIEW_CMS_RESPONSE} l_response.make (req, res, api)
f := exportation_web_form (l_response)
create s.make_empty
f.append_to_html (create {CMS_TO_WSF_THEME}.make (l_response, l_response.theme), s)
l_response.set_main_content (s)
l_response.execute
end
do_post (req: WSF_REQUEST; res: WSF_RESPONSE)
local
l_response: CMS_RESPONSE
s: STRING
f: CMS_FORM
l_exportation_parameters: CMS_EXPORT_PARAMETERS
do
create {GENERIC_VIEW_CMS_RESPONSE} l_response.make (req, res, api)
f := exportation_web_form (l_response)
f.process (l_response)
if
attached f.last_data as fd and then
fd.is_valid
then
if attached fd.string_item ("op") as l_op and then l_op.same_string (text_export_all_data) then
if attached fd.string_item ("folder") as l_folder then
create l_exportation_parameters.make (api.site_location.extended ("export").extended (l_folder))
else
create l_exportation_parameters.make (api.site_location.extended ("export").extended ((create {DATE_TIME}.make_now_utc).formatted_out ("yyyy-[0]mm-[0]dd---hh24-[0]mi-[0]ss")))
end
l_response.hooks.invoke_export_to (Void, l_exportation_parameters, l_response)
l_response.add_notice_message ("All data exported (if allowed)!")
create s.make_empty
across
l_exportation_parameters.logs as ic
loop
s.append (ic.item)
s.append ("<br/>")
s.append_character ('%N')
end
l_response.add_notice_message (s)
else
fd.report_error ("Invalid form data!")
end
end
create s.make_empty
f.append_to_html (create {CMS_TO_WSF_THEME}.make (l_response, l_response.theme), s)
l_response.set_main_content (s)
l_response.execute
end
feature -- Widget
exportation_web_form (a_response: CMS_RESPONSE): CMS_FORM
local
f_name: WSF_FORM_TEXT_INPUT
but: WSF_FORM_SUBMIT_INPUT
do
create Result.make (a_response.url (a_response.location, Void), "export_all_data")
Result.extend_raw_text ("Export CMS data to ")
create f_name.make_with_text ("folder", (create {DATE_TIME}.make_now_utc).formatted_out ("yyyy-[0]mm-[0]dd---hh24-[0]mi-[0]ss"))
f_name.set_label ("Export folder name")
f_name.set_description ("Folder name under 'exports' folder.")
f_name.set_is_required (True)
Result.extend (f_name)
create but.make_with_text ("op", text_export_all_data)
Result.extend (but)
end
feature -- Interface text.
text_export_all_data: STRING_32 = "Export all data"
end

View File

@@ -97,6 +97,21 @@ feature -- Access node
Result := nodes_to_blogs (blog_storage.blogs_from_user_limited (a_user, a_limit, a_offset)) Result := nodes_to_blogs (blog_storage.blogs_from_user_limited (a_user, a_limit, a_offset))
end end
feature -- Conversion
full_blog_node (a_blog: CMS_BLOG): CMS_BLOG
-- If `a_blog' is partial, return the full blog node from `a_blog',
-- otherwise return directly `a_blog'.
require
a_blog_set: a_blog /= Void
do
if attached {CMS_BLOG} node_api.full_node (a_blog) as l_full_blog then
Result := l_full_blog
else
Result := a_blog
end
end
feature {NONE} -- Helpers feature {NONE} -- Helpers
nodes_to_blogs (a_nodes: LIST [CMS_NODE]): ARRAYED_LIST [CMS_BLOG] nodes_to_blogs (a_nodes: LIST [CMS_NODE]): ARRAYED_LIST [CMS_BLOG]

View File

@@ -14,6 +14,8 @@
<library name="cms" location="..\..\cms-safe.ecf" readonly="false"/> <library name="cms" location="..\..\cms-safe.ecf" readonly="false"/>
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/> <library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/>
<library name="cms_node_module" location="..\..\modules\node\node-safe.ecf" readonly="false"/> <library name="cms_node_module" location="..\..\modules\node\node-safe.ecf" readonly="false"/>
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/> <library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf" readonly="false"/> <library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf" readonly="false"/>
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter-safe.ecf"/> <library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter-safe.ecf"/>

View File

@@ -22,6 +22,10 @@ inherit
CMS_HOOK_RESPONSE_ALTER CMS_HOOK_RESPONSE_ALTER
CMS_HOOK_EXPORT
CMS_EXPORT_NODE_UTILITIES
create create
make make
@@ -153,6 +157,7 @@ feature -- Hooks
do do
a_response.hooks.subscribe_to_menu_system_alter_hook (Current) a_response.hooks.subscribe_to_menu_system_alter_hook (Current)
a_response.hooks.subscribe_to_response_alter_hook (Current) a_response.hooks.subscribe_to_response_alter_hook (Current)
a_response.hooks.subscribe_to_export_hook (Current)
end end
response_alter (a_response: CMS_RESPONSE) response_alter (a_response: CMS_RESPONSE)
@@ -168,4 +173,74 @@ feature -- Hooks
create lnk.make ("Blogs", "blogs/") create lnk.make ("Blogs", "blogs/")
a_menu_system.primary_menu.extend (lnk) a_menu_system.primary_menu.extend (lnk)
end end
export_to (a_export_id_list: detachable ITERABLE [READABLE_STRING_GENERAL]; a_export_parameters: CMS_EXPORT_PARAMETERS; a_response: CMS_RESPONSE)
-- Export data identified by `a_export_id_list',
-- or export all data if `a_export_id_list' is Void.
local
n: CMS_BLOG
p: PATH
d: DIRECTORY
f: PLAIN_TEXT_FILE
lst: LIST [CMS_BLOG]
do
if
a_export_id_list = Void
or else across a_export_id_list as ic some ic.item.same_string ("blog") end
then
if
a_response.has_permissions (<<"export any node", "export blog">>) and then
attached blog_api as l_blog_api
then
lst := l_blog_api.blogs_order_created_desc
a_export_parameters.log ("Exporting " + lst.count.out + " blogs")
across
lst as ic
loop
n := l_blog_api.full_blog_node (ic.item)
a_export_parameters.log (n.content_type + " #" + n.id.out)
p := a_export_parameters.location.extended ("nodes").extended (n.content_type).extended (n.id.out)
create d.make_with_path (p.parent)
if not d.exists then
d.recursive_create_dir
end
create f.make_with_path (p)
if not f.exists or else f.is_access_writable then
f.open_write
f.put_string (json_to_string (blog_node_to_json (n)))
f.close
end
-- Revisions.
if
attached node_api as l_node_api and then
attached l_node_api.node_revisions (n) as l_revisions and then l_revisions.count > 1
then
a_export_parameters.log (n.content_type + " " + l_revisions.count.out + " revisions.")
p := a_export_parameters.location.extended ("nodes").extended (n.content_type).extended (n.id.out)
create d.make_with_path (p)
if not d.exists then
d.recursive_create_dir
end
across
l_revisions as revs_ic
loop
if attached {CMS_BLOG} revs_ic.item as l_blog then
create f.make_with_path (p.extended ("rev-" + n.revision.out).appended_with_extension ("json"))
if not f.exists or else f.is_access_writable then
f.open_write
f.put_string (json_to_string (blog_node_to_json (l_blog)))
end
f.close
end
end
end
end
end
end
end
blog_node_to_json (a_blog: CMS_BLOG): JSON_OBJECT
do
Result := node_to_json (a_blog)
end
end end

View File

@@ -6,8 +6,12 @@ note
deferred class deferred class
CMS_BLOG_STORAGE_I CMS_BLOG_STORAGE_I
inherit feature -- Error Handling
CMS_NODE_STORAGE_I
error_handler: ERROR_HANDLER
-- Error handler.
deferred
end
feature -- Access feature -- Access

View File

@@ -330,6 +330,14 @@ feature -- Access: Node
end end
end end
nodes_of_type (a_node_type: CMS_CONTENT_TYPE): LIST [CMS_NODE]
-- List of nodes of type `a_node_type'.
do
Result := node_storage.nodes_of_type (a_node_type)
ensure
expected_type: across Result as ic all ic.item.content_type.same_string (a_node_type.name) end
end
feature -- Access: page/book outline feature -- Access: page/book outline
children (a_node: CMS_NODE): detachable LIST [CMS_NODE] children (a_node: CMS_NODE): detachable LIST [CMS_NODE]

View File

@@ -25,6 +25,10 @@ inherit
CMS_RECENT_CHANGES_HOOK CMS_RECENT_CHANGES_HOOK
CMS_HOOK_EXPORT
CMS_EXPORT_NODE_UTILITIES
create create
make make
@@ -147,6 +151,7 @@ feature -- Access
do do
Result := Precursor Result := Precursor
Result.force ("create any node") Result.force ("create any node")
Result.force ("export any node")
if attached node_api as l_node_api then if attached node_api as l_node_api then
across across
@@ -173,6 +178,8 @@ feature -- Access
Result.force ("view unpublished " + l_type_name) Result.force ("view unpublished " + l_type_name)
Result.force ("view revisions own " + l_type_name) Result.force ("view revisions own " + l_type_name)
Result.force ("export " + l_type_name)
end end
end end
Result.force ("view trash") Result.force ("view trash")
@@ -230,6 +237,7 @@ feature -- Hooks
a_response.hooks.subscribe_to_menu_system_alter_hook (Current) a_response.hooks.subscribe_to_menu_system_alter_hook (Current)
a_response.hooks.subscribe_to_block_hook (Current) a_response.hooks.subscribe_to_block_hook (Current)
a_response.hooks.subscribe_to_response_alter_hook (Current) a_response.hooks.subscribe_to_response_alter_hook (Current)
a_response.hooks.subscribe_to_export_hook (Current)
-- Module specific hook, if available. -- Module specific hook, if available.
a_response.hooks.subscribe_to_hook (Current, {CMS_RECENT_CHANGES_HOOK}) a_response.hooks.subscribe_to_hook (Current, {CMS_RECENT_CHANGES_HOOK})
@@ -353,4 +361,94 @@ feature -- Hooks
end end
end end
export_to (a_export_id_list: detachable ITERABLE [READABLE_STRING_GENERAL]; a_export_parameters: CMS_EXPORT_PARAMETERS; a_response: CMS_RESPONSE)
-- Export data identified by `a_export_id_list',
-- or export all data if `a_export_id_list' is Void.
local
l_node_type: CMS_CONTENT_TYPE
n: CMS_NODE
p: PATH
d: DIRECTORY
f: PLAIN_TEXT_FILE
lst: LIST [CMS_NODE]
do
if attached node_api as l_node_api then
across
l_node_api.node_types as types_ic
loop
l_node_type := types_ic.item
if
a_response.has_permissions (<<"export any node", "export " + l_node_type.name>>) and then
l_node_type.name.same_string_general ("page") and then
( a_export_id_list = Void
or else across a_export_id_list as ic some ic.item.same_string (l_node_type.name) end
)
then
-- For now, handle only page from this node module.
lst := l_node_api.nodes_of_type (l_node_type)
a_export_parameters.log ("Exporting " + lst.count.out + " nodes of type " + l_node_type.name)
p := a_export_parameters.location.extended ("nodes").extended (l_node_type.name)
create d.make_with_path (p)
if not d.exists then
d.recursive_create_dir
end
across
lst as ic
loop
n := l_node_api.full_node (ic.item)
a_export_parameters.log (l_node_type.name + " #" + n.id.out + " rev=" + n.revision.out)
create f.make_with_path (p.extended (n.id.out).appended_with_extension ("json"))
if not f.exists or else f.is_access_writable then
f.open_write
if attached {CMS_PAGE} n as l_page then
f.put_string (json_to_string (page_node_to_json (l_page)))
else
f.put_string (json_to_string (node_to_json (n)))
end
f.close
end
-- Revisions.
if attached l_node_api.node_revisions (n) as l_revisions and then l_revisions.count > 1 then
a_export_parameters.log (l_node_type.name + " " + l_revisions.count.out + " revisions.")
p := a_export_parameters.location.extended ("nodes").extended (l_node_type.name).extended (n.id.out)
create d.make_with_path (p)
if not d.exists then
d.recursive_create_dir
end
across
l_revisions as revs_ic
loop
n := revs_ic.item
create f.make_with_path (p.extended ("rev-" + n.revision.out).appended_with_extension ("json"))
if not f.exists or else f.is_access_writable then
f.open_write
if attached {CMS_PAGE} n as l_page then
f.put_string (json_to_string (page_node_to_json (l_page)))
else
f.put_string (json_to_string (node_to_json (n)))
end
f.close
end
end
end
end
end
end
end
end
page_node_to_json (a_page: CMS_PAGE): JSON_OBJECT
local
j: JSON_OBJECT
do
Result := node_to_json (a_page)
if attached a_page.parent as l_parent_page then
create j.make_empty
j.put_string (l_parent_page.content_type, "type")
j.put_integer (l_parent_page.id, "nid")
Result.put (j, "parent")
end
end
end end

View File

@@ -0,0 +1,55 @@
note
description: "[
Routines usefull during node exportation (see {CMS_HOOK_EXPORT}).
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_EXPORT_NODE_UTILITIES
inherit
CMS_EXPORT_JSON_UTILITIES
feature -- Access
node_to_json (n: CMS_NODE): JSON_OBJECT
local
jo,j_author: JSON_OBJECT
do
create Result.make_empty
Result.put_string (n.content_type, "type")
Result.put_integer (n.id, "nid")
Result.put_integer (n.revision, "revision")
Result.put_string (n.title, "title")
put_date_into_json (n.creation_date, "creation_date", Result)
put_date_into_json (n.modification_date, "modification_date", Result)
put_date_into_json (n.publication_date, "publication_date", Result)
Result.put_integer (n.status, "status")
if attached n.author as u then
create j_author.make
j_author.put_integer (u.id, "uid")
j_author.put_string (u.name, "name")
Result.put (j_author, "author")
end
create jo.make_empty
if attached n.format as l_format then
jo.put_string (l_format, "format")
end
if attached n.summary as s then
jo.put_string (s, "summary")
end
if attached n.content as s then
jo.put_string (s, "content")
end
Result.put (jo, "data")
if attached n.link as lnk then
create jo.make_empty
jo.put_string (lnk.title, "title")
jo.put_string (lnk.location, "location")
jo.put_integer (lnk.weight, "weight")
Result.put (jo, "link")
end
end
end

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-14-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-14-0 http://www.eiffel.com/developers/xml/configuration-1-14-0.xsd" name="node" uuid="C7114DD4-FA92-4AE5-A209-0FFC45E44257" library_target="node"> <system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="node" uuid="C7114DD4-FA92-4AE5-A209-0FFC45E44257" library_target="node">
<target name="node"> <target name="node">
<root all_classes="true"/> <root all_classes="true"/>
<file_rule> <file_rule>
@@ -7,7 +7,7 @@
<exclude>/CVS$</exclude> <exclude>/CVS$</exclude>
<exclude>/.svn$</exclude> <exclude>/.svn$</exclude>
</file_rule> </file_rule>
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="all" syntax="transitional"> <option warning="true" full_class_checking="false" is_attached_by_default="true" is_obsolete_routine_type="true" void_safety="all" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/> <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option> </option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/> <library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
@@ -17,6 +17,7 @@
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/> <library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/> <library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\web\authentication\http_authorization\http_authorization-safe.ecf" readonly="false"/> <library name="http_authorization" location="$ISE_LIBRARY\contrib\library\web\authentication\http_authorization\http_authorization-safe.ecf" readonly="false"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter-safe.ecf"/> <library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/> <library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/> <library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>

View File

@@ -17,6 +17,7 @@
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error.ecf"/> <library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/> <library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\network\authentication\http_authorization\http_authorization.ecf" readonly="false"/> <library name="http_authorization" location="$ISE_LIBRARY\contrib\library\network\authentication\http_authorization\http_authorization.ecf" readonly="false"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf"/>
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter.ecf"/> <library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/> <library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf.ecf"/> <library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf.ecf"/>

View File

@@ -127,6 +127,26 @@ feature -- Access
deferred deferred
end end
nodes_of_type (a_node_type: CMS_CONTENT_TYPE): LIST [CMS_NODE]
-- List of nodes of type `a_node_type'.
--| Redefine to optimize!
do
Result := nodes
from
Result.start
until
Result.after
loop
if Result.item.content_type.same_string (a_node_type.name) then
Result.forth
else
Result.remove
end
end
ensure
expected_type: across Result as ic all ic.item.content_type.same_string (a_node_type.name) end
end
feature -- Access: outline feature -- Access: outline
children (a_node: CMS_NODE): detachable LIST [CMS_NODE] children (a_node: CMS_NODE): detachable LIST [CMS_NODE]

View File

@@ -12,6 +12,9 @@ inherit
CMS_PROXY_STORAGE_SQL CMS_PROXY_STORAGE_SQL
CMS_NODE_STORAGE_I CMS_NODE_STORAGE_I
redefine
nodes_of_type
end
CMS_STORAGE_SQL_I CMS_STORAGE_SQL_I
@@ -264,6 +267,33 @@ feature -- Access
-- end -- end
end end
nodes_of_type (a_node_type: CMS_CONTENT_TYPE): LIST [CMS_NODE]
-- <Precursor>
local
l_parameters: STRING_TABLE [detachable ANY]
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
error_handler.reset
write_information_log (generator + ".nodes_of_type")
create l_parameters.make (1)
l_parameters.put (a_node_type.name, "node_type")
from
sql_query (sql_select_nodes_of_type, l_parameters)
sql_start
until
sql_after
loop
if attached fetch_node as l_node then
check expected_node_type: l_node.content_type.same_string (a_node_type.name) end
Result.force (l_node)
end
sql_forth
end
sql_finalize
end
feature -- Access: outline feature -- Access: outline
children (a_node: CMS_NODE): detachable LIST [CMS_NODE] children (a_node: CMS_NODE): detachable LIST [CMS_NODE]
@@ -495,6 +525,10 @@ feature {NONE} -- Queries
-- SQL Query to retrieve all nodes. -- SQL Query to retrieve all nodes.
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
sql_select_nodes_of_type: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status != -1 AND type=:node_type ;"
-- SQL Query to retrieve all nodes of type :node_type.
--| note: {CMS_NODE_API}.trashed = -1
sql_select_node_revisions: STRING = "SELECT nodes.nid, node_revisions.revision, nodes.type, node_revisions.title, node_revisions.summary, node_revisions.content, node_revisions.format, node_revisions.author, nodes.publish, nodes.created, node_revisions.changed, node_revisions.status FROM nodes INNER JOIN node_revisions ON nodes.nid = node_revisions.nid WHERE nodes.nid = :nid AND node_revisions.revision < :revision ORDER BY node_revisions.revision DESC;" sql_select_node_revisions: STRING = "SELECT nodes.nid, node_revisions.revision, nodes.type, node_revisions.title, node_revisions.summary, node_revisions.content, node_revisions.format, node_revisions.author, nodes.publish, nodes.created, node_revisions.changed, node_revisions.status FROM nodes INNER JOIN node_revisions ON nodes.nid = node_revisions.nid WHERE nodes.nid = :nid AND node_revisions.revision < :revision ORDER BY node_revisions.revision DESC;"
-- SQL query to get node revisions (missing the latest one). -- SQL query to get node revisions (missing the latest one).

View File

@@ -94,7 +94,7 @@ feature -- Hook
recent_changes_feed (a_response, nb, Void).accept (gen) recent_changes_feed (a_response, nb, Void).accept (gen)
create b.make (a_block_id, Void, l_content, Void) create b.make (a_block_id, Void, l_content, Void)
a_response.put_block (b, Void, False) a_response.add_block (b, Void)
end end
end end

View File

@@ -223,6 +223,34 @@ feature -- Hook: cache
end end
end end
feature -- Hook: export
subscribe_to_export_hook (h: CMS_HOOK_EXPORT)
-- Add `h' as subscriber of export hooks CMS_HOOK_EXPORT.
do
subscribe_to_hook (h, {CMS_HOOK_EXPORT})
end
invoke_export_to (a_export_id_list: detachable ITERABLE [READABLE_STRING_GENERAL]; a_export_parameters: CMS_EXPORT_PARAMETERS; a_response: CMS_RESPONSE)
-- Invoke response alter hook for response `a_response'.
local
d: DIRECTORY
do
if attached subscribers ({CMS_HOOK_EXPORT}) as lst then
create d.make_with_path (a_export_parameters.location)
if not d.exists then
d.recursive_create_dir
end
across
lst as ic
loop
if attached {CMS_HOOK_EXPORT} ic.item as h then
h.export_to (a_export_id_list, a_export_parameters, a_response)
end
end
end
end
note note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -0,0 +1,42 @@
note
description: "[
Usefull routines to export to JSON.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_EXPORT_JSON_UTILITIES
feature -- Access
put_string_into_json (st: detachable READABLE_STRING_GENERAL; a_key: JSON_STRING; j: JSON_OBJECT)
do
if st /= Void then
j.put_string (st, a_key)
end
end
put_date_into_json (dt: detachable DATE_TIME; a_key: JSON_STRING; j: JSON_OBJECT)
local
hd: HTTP_DATE
do
if dt /= Void then
create hd.make_from_date_time (dt)
j.put_integer (hd.timestamp, a_key)
end
end
json_to_string (j: JSON_VALUE): STRING
local
pp: JSON_PRETTY_STRING_VISITOR
do
create Result.make_empty
create pp.make (Result)
j.accept (pp)
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -0,0 +1,43 @@
note
description: "[
Parameters used by CMS_HOOK_EXPORT subscribers.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_EXPORT_PARAMETERS
create
make
feature {NONE} -- Initialization
make (a_location: PATH)
do
location := a_location
create logs.make (10)
end
feature -- Access
location: PATH
-- Location of export folder.
feature -- Logs
logs: ARRAYED_LIST [READABLE_STRING_8]
-- Associated exportation logs.
log (m: READABLE_STRING_8)
-- Add message `m' into `logs'.
do
logs.force (m)
end
invariant
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -0,0 +1,31 @@
note
description: "[
CMS HOOK providing a way to export module data according to specific export parameters.
]"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_HOOK_EXPORT
inherit
CMS_HOOK
feature -- Hook
export_to (a_export_id_list: detachable ITERABLE [READABLE_STRING_GENERAL]; a_export_parameters: CMS_EXPORT_PARAMETERS; a_response: CMS_RESPONSE)
-- Export data identified by `a_export_id_list',
-- or export all data if `a_export_id_list' is Void.
deferred
end
-- export_identifiers: detachable ITERABLE [READABLE_STRING_32]
-- -- Optional list of exportation ids, if any.
-- do
-- -- To redefine if needed.
-- end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -80,6 +80,12 @@ feature -- URL aliases
do do
end end
path_aliases: STRING_TABLE [READABLE_STRING_8]
-- <Precursor>.
do
create Result.make (0)
end
feature -- Logs feature -- Logs
save_log (a_log: CMS_LOG) save_log (a_log: CMS_LOG)
@@ -116,5 +122,12 @@ feature -- Custom
end end
end end
custom_values: detachable LIST [TUPLE [name: READABLE_STRING_GENERAL; type: detachable READABLE_STRING_8; value: detachable READABLE_STRING_32]]
-- Values as list of [name, type, value].
do
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end

View File

@@ -47,6 +47,11 @@ feature -- URL aliases
deferred deferred
end end
path_aliases: STRING_TABLE [READABLE_STRING_8]
-- All path aliases as a table containing sources indexed by alias.
deferred
end
feature -- Logs feature -- Logs
save_log (a_log: CMS_LOG) save_log (a_log: CMS_LOG)
@@ -71,5 +76,12 @@ feature -- Misc
deferred deferred
end end
custom_values: detachable LIST [TUPLE [name: READABLE_STRING_GENERAL; type: detachable READABLE_STRING_8; value: detachable READABLE_STRING_32]]
-- Values as list of [name, type, value].
deferred
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end end

View File

@@ -127,6 +127,35 @@ feature -- URL aliases
sql_finalize sql_finalize
end end
path_aliases: STRING_TABLE [READABLE_STRING_8]
-- All path aliases as a table containing sources indexed by alias.
local
l_source: READABLE_STRING_8
do
error_handler.reset
create Result.make (5)
sql_query (sql_select_all_path_alias, Void)
if not has_error then
from
sql_start
until
sql_after or has_error
loop
if attached sql_read_string (1) as s_src then
l_source := s_src
if attached sql_read_string (2) as s_alias then
Result.force (l_source, s_alias)
end
end
sql_forth
end
end
sql_finalize
end
sql_select_all_path_alias: STRING = "SELECT source, alias, lang FROM path_aliases;"
-- SQL select all path aliases.
sql_select_path_alias: STRING = "SELECT source FROM path_aliases WHERE alias=:alias ;" sql_select_path_alias: STRING = "SELECT source FROM path_aliases WHERE alias=:alias ;"
-- SQL select path aliases. -- SQL select path aliases.
@@ -251,6 +280,38 @@ feature -- Misc
sql_finalize sql_finalize
end end
custom_values: detachable LIST [TUPLE [name: READABLE_STRING_GENERAL; type: detachable READABLE_STRING_8; value: detachable READABLE_STRING_32]]
-- Values as list of [name, type, value].
local
l_type, l_name: READABLE_STRING_8
do
error_handler.reset
create {ARRAYED_LIST [TUPLE [name: READABLE_STRING_GENERAL; type: detachable READABLE_STRING_8; value: detachable READABLE_STRING_32]]} Result.make (5)
sql_query (sql_select_all_custom_values, Void)
if not has_error then
from
sql_start
until
sql_after or has_error
loop
if attached sql_read_string (1) as s_type then
l_type := s_type
if attached sql_read_string (2) as s_name then
l_name := s_name
if attached sql_read_string_32 (3) as s_value then
Result.force ([l_name, l_type, s_value])
end
end
end
sql_forth
end
end
sql_finalize
end
sql_select_all_custom_values: STRING = "SELECT type, name, value FROM custom_values;"
-- SQL Insert to add a new custom value.
sql_select_custom_value: STRING = "SELECT value FROM custom_values WHERE type=:type AND name=:name;" sql_select_custom_value: STRING = "SELECT value FROM custom_values WHERE type=:type AND name=:name;"
-- SQL Insert to add a new custom value. -- SQL Insert to add a new custom value.

View File

@@ -829,6 +829,7 @@ feature {NONE} -- Implementation: User
end end
fetch_user: detachable CMS_USER fetch_user: detachable CMS_USER
-- Fetch user from fields: 1:uid, 2:name, 3:password, 4:salt, 5:email, 6:status, 7:created, 8:signed.
local local
l_id: INTEGER_64 l_id: INTEGER_64
l_name: detachable READABLE_STRING_32 l_name: detachable READABLE_STRING_32
@@ -919,10 +920,10 @@ feature {NONE} -- Sql Queries: USER
Select_user_by_name: STRING = "SELECT * FROM users WHERE name =:name;" Select_user_by_name: STRING = "SELECT * FROM users WHERE name =:name;"
-- Retrieve user by name if exists. -- Retrieve user by name if exists.
Sql_select_recent_users: STRING = "SELECT * FROM users ORDER BY uid DESC, created DESC LIMIT :rows OFFSET :offset ;" Sql_select_recent_users: STRING = "SELECT uid, name, password, salt, email, status, created, signed FROM users ORDER BY uid DESC, created DESC LIMIT :rows OFFSET :offset ;"
-- Retrieve recent users -- Retrieve recent users
Select_user_by_email: STRING = "SELECT * FROM users WHERE email =:email;" Select_user_by_email: STRING = "SELECT uid, name, password, salt, email, status, created, signed FROM users WHERE email =:email;"
-- Retrieve user by email if exists. -- Retrieve user by email if exists.
Select_salt_by_username: STRING = "SELECT salt FROM users WHERE name =:name;" Select_salt_by_username: STRING = "SELECT salt FROM users WHERE name =:name;"

View File

@@ -9,6 +9,10 @@ class
inherit inherit
ANY ANY
CMS_HOOK_EXPORT
CMS_EXPORT_JSON_UTILITIES
REFACTORING_HELPER REFACTORING_HELPER
CMS_ENCODERS CMS_ENCODERS
@@ -316,6 +320,14 @@ feature -- Query: API
Result := l_api Result := l_api
end end
feature -- Hooks
register_hooks (a_hooks: CMS_HOOK_CORE_MANAGER)
-- Register hooks associated with the cms core.
do
a_hooks.subscribe_to_export_hook (Current)
end
feature -- Path aliases feature -- Path aliases
is_valid_path_alias (a_alias: READABLE_STRING_8): BOOLEAN is_valid_path_alias (a_alias: READABLE_STRING_8): BOOLEAN
@@ -581,6 +593,112 @@ feature -- Environment/ modules and theme
Result := module_configuration_by_name (a_module.name, a_name) Result := module_configuration_by_name (a_module.name, a_name)
end end
feature -- Hook
export_to (a_export_id_list: detachable ITERABLE [READABLE_STRING_GENERAL]; a_export_parameters: CMS_EXPORT_PARAMETERS; a_response: CMS_RESPONSE)
-- <Precursor>.
local
p: PATH
d: DIRECTORY
ja: JSON_ARRAY
jobj,jo,j: JSON_OBJECT
f: PLAIN_TEXT_FILE
u: CMS_USER
do
if attached a_response.has_permissions (<<"admin export", "export core">>) then
if a_export_id_list = Void then -- Include everything
p := a_export_parameters.location.extended ("core")
create d.make_with_path (p)
if not d.exists then
d.recursive_create_dir
end
-- path_aliases export.
a_export_parameters.log ("Exporting path_aliases")
create jo.make_empty
across storage.path_aliases as ic loop
jo.put_string (ic.item, ic.key)
end
create f.make_with_path (p.extended ("path_aliases.json"))
f.create_read_write
f.put_string (json_to_string (jo))
f.close
-- custom_values export.
if attached storage.custom_values as lst then
a_export_parameters.log ("Exporting custom_values")
create ja.make_empty
across
lst as ic
loop
create j.make_empty
if attached ic.item.type as l_type then
j.put_string (l_type, "type")
end
j.put_string (ic.item.name, "name")
if attached ic.item.type as l_value then
j.put_string (l_value, "value")
end
ja.extend (j)
end
create f.make_with_path (p.extended ("custom_values.json"))
f.create_read_write
f.put_string (json_to_string (ja))
f.close
end
-- users export.
a_export_parameters.log ("Exporting users")
create jo.make_empty
create jobj.make_empty
across user_api.recent_users (create {CMS_DATA_QUERY_PARAMETERS}.make (0, user_api.users_count.as_natural_32)) as ic loop
u := ic.item
create j.make_empty
j.put_string (u.name, "name")
j.put_integer (u.status, "status")
put_string_into_json (u.email, "email", j)
put_string_into_json (u.password, "password", j)
put_string_into_json (u.hashed_password, "hashed_password", j)
put_date_into_json (u.creation_date, "creation_date", j)
put_date_into_json (u.last_login_date, "last_login_date", j)
if attached u.roles as l_roles then
create ja.make (l_roles.count)
across
l_roles as roles_ic
loop
ja.extend (create {JSON_STRING}.make_from_string_32 ({STRING_32} " %"" + roles_ic.item.name + {STRING_32} "%" #" + roles_ic.item.id.out))
end
j.put (ja, "roles")
end
jobj.put (j, u.id.out)
end
jo.put (jobj, "users")
create jobj.make_empty
across user_api.roles as ic loop
create j.make_empty
j.put_string (ic.item.name, "name")
if attached ic.item.permissions as l_perms then
create ja.make (l_perms.count)
across
l_perms as perms_ic
loop
ja.extend (create {JSON_STRING}.make_from_string (perms_ic.item))
end
j.put (ja, "permissions")
end
jobj.put (j, ic.item.id.out)
end
jo.put (jobj, "roles")
create f.make_with_path (p.extended ("users.json"))
f.create_read_write
f.put_string (json_to_string (jo))
f.close
end
end
end
note note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -71,6 +71,7 @@ feature {NONE} -- Initialization
l_module: CMS_MODULE l_module: CMS_MODULE
l_enabled_modules: CMS_MODULE_COLLECTION l_enabled_modules: CMS_MODULE_COLLECTION
do do
api.register_hooks (hooks)
l_enabled_modules := api.enabled_modules l_enabled_modules := api.enabled_modules
across across
l_enabled_modules as ic l_enabled_modules as ic
@@ -653,13 +654,9 @@ feature -- Blocks
-- and check optional associated condition. -- and check optional associated condition.
-- If no condition then use `is_block_included_by_default' to -- If no condition then use `is_block_included_by_default' to
-- decide if block is included or not. -- decide if block is included or not.
local
l_region: detachable like block_region
do do
if is_block_included (b.name, is_block_included_by_default) then if is_block_included (b.name, is_block_included_by_default) then
l_region := block_region (b, a_default_region) add_block (b, a_default_region)
l_region.extend (b)
blocks.force (b, b.name)
end end
end end