Added export of core data, such as users, path_aliases, custom_values.
Added export of node revisions.
This commit is contained in:
@@ -10,6 +10,13 @@ class
|
||||
|
||||
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
|
||||
@@ -20,7 +27,7 @@ feature -- Access
|
||||
end
|
||||
end
|
||||
|
||||
json_to_string (j: JSON_OBJECT): STRING
|
||||
json_to_string (j: JSON_VALUE): STRING
|
||||
local
|
||||
pp: JSON_PRETTY_STRING_VISITOR
|
||||
do
|
||||
|
||||
@@ -80,6 +80,12 @@ feature -- URL aliases
|
||||
do
|
||||
end
|
||||
|
||||
path_aliases: STRING_TABLE [READABLE_STRING_8]
|
||||
-- <Precursor>.
|
||||
do
|
||||
create Result.make (0)
|
||||
end
|
||||
|
||||
feature -- Logs
|
||||
|
||||
save_log (a_log: CMS_LOG)
|
||||
@@ -116,5 +122,12 @@ feature -- Custom
|
||||
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
|
||||
|
||||
@@ -47,6 +47,11 @@ feature -- URL aliases
|
||||
deferred
|
||||
end
|
||||
|
||||
path_aliases: STRING_TABLE [READABLE_STRING_8]
|
||||
-- All path aliases as a table containing sources indexed by alias.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Logs
|
||||
|
||||
save_log (a_log: CMS_LOG)
|
||||
@@ -71,5 +76,12 @@ feature -- Misc
|
||||
deferred
|
||||
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
|
||||
|
||||
@@ -127,6 +127,35 @@ feature -- URL aliases
|
||||
sql_finalize
|
||||
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 aliases.
|
||||
|
||||
@@ -251,6 +280,39 @@ feature -- Misc
|
||||
sql_finalize
|
||||
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
|
||||
l_value: READABLE_STRING_32
|
||||
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 Insert to add a new custom value.
|
||||
|
||||
|
||||
@@ -829,6 +829,7 @@ feature {NONE} -- Implementation: User
|
||||
end
|
||||
|
||||
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
|
||||
l_id: INTEGER_64
|
||||
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;"
|
||||
-- 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
|
||||
|
||||
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.
|
||||
|
||||
Select_salt_by_username: STRING = "SELECT salt FROM users WHERE name =:name;"
|
||||
|
||||
@@ -9,6 +9,10 @@ class
|
||||
inherit
|
||||
ANY
|
||||
|
||||
CMS_HOOK_EXPORT
|
||||
|
||||
CMS_EXPORT_JSON_UTILITIES
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
CMS_ENCODERS
|
||||
@@ -316,6 +320,14 @@ feature -- Query: API
|
||||
Result := l_api
|
||||
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
|
||||
|
||||
is_valid_path_alias (a_alias: READABLE_STRING_8): BOOLEAN
|
||||
@@ -581,6 +593,113 @@ feature -- Environment/ modules and theme
|
||||
Result := module_configuration_by_name (a_module.name, a_name)
|
||||
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
|
||||
s: STRING_32
|
||||
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
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -71,6 +71,7 @@ feature {NONE} -- Initialization
|
||||
l_module: CMS_MODULE
|
||||
l_enabled_modules: CMS_MODULE_COLLECTION
|
||||
do
|
||||
api.register_hooks (hooks)
|
||||
l_enabled_modules := api.enabled_modules
|
||||
across
|
||||
l_enabled_modules as ic
|
||||
|
||||
Reference in New Issue
Block a user