Added revisions support to node management.

Updated node extension implementation.
Updated known permissions for node module.
Improved code for node storage extension , in preparation to code factorization.
Ensured that author is updated when saved.
This commit is contained in:
2015-08-07 19:17:25 +02:00
parent 44ada4b6b1
commit cd0c2acd87
15 changed files with 464 additions and 132 deletions

View File

@@ -49,12 +49,12 @@ feature {CMS_API} -- Module Initialization
Precursor (api)
if attached {CMS_NODE_API} api.module_api ({CMS_NODE_MODULE}) as l_node_api then
create ct
create blog_api.make (api, l_node_api)
node_api := l_node_api
-- Depends on {CMS_NODE_MODULE}
create ct
--| For now, add all available formats to content type `ct'.
across
api.formats as ic
@@ -67,7 +67,7 @@ feature {CMS_API} -- Module Initialization
-- Add support for CMS_BLOG, which requires a storage extension to store the optional "tags" value
-- For now, we only have extension based on SQL statement.
if attached {CMS_NODE_STORAGE_SQL} l_node_api.node_storage as l_sql_node_storage then
l_sql_node_storage.register_node_storage_extension (create {CMS_NODE_STORAGE_SQL_BLOG_EXTENSION}.make (l_sql_node_storage))
l_sql_node_storage.register_node_storage_extension (create {CMS_NODE_STORAGE_SQL_BLOG_EXTENSION}.make (l_node_api, l_sql_node_storage))
end
end
end
@@ -83,9 +83,10 @@ feature {CMS_API} -- Module management
if not l_sql_storage.sql_table_exists ("blog_post_nodes") then
sql := "[
CREATE TABLE blog_post_nodes(
`nid` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL CHECK("nid">=0),
`revision` INTEGER,
`tags` VARCHAR(255)
`nid` INTEGER NOT NULL CHECK("nid">=0),
`revision` INTEGER NOT NULL,
`tags` VARCHAR(255),
CONSTRAINT PK_nid_revision PRIMARY KEY (nid,revision)
);
]"
l_sql_storage.sql_execute_script (sql, Void)

View File

@@ -11,6 +11,7 @@ inherit
CMS_PROXY_STORAGE_SQL
rename
make as make_proxy,
sql_storage as node_storage
redefine
node_storage
@@ -21,6 +22,12 @@ create
feature {NONE} -- Initialization
make (a_node_api: CMS_NODE_API; a_sql_storage: CMS_NODE_STORAGE_SQL)
do
set_node_api (a_node_api)
make_proxy (a_sql_storage)
end
node_storage: CMS_NODE_STORAGE_SQL
-- <Precursor>
@@ -39,22 +46,19 @@ feature -- Persistence
l_new_tags: detachable STRING_32
l_previous_tags: detachable STRING_32
l_update: BOOLEAN
l_has_modif: BOOLEAN
do
error_handler.reset
if attached api as l_api then
l_api.logger.put_information (generator + ".store", Void)
end
create l_parameters.make (2)
l_parameters.put (a_node.id, "nid")
l_parameters.put (a_node.revision, "revision")
sql_query (sql_select_blog_data, l_parameters)
error_handler.reset
-- Check existing record, if any.
if attached node_data (a_node) as d then
l_update := d.revision = a_node.revision
l_previous_tags := d.tags
end
if not has_error then
if sql_rows_count = 1 then
l_previous_tags := sql_read_string_32 (3)
l_update := True
end
if attached a_node.tags as l_tags and then not l_tags.is_empty then
create l_new_tags.make (0)
across
@@ -68,37 +72,60 @@ feature -- Persistence
else
l_new_tags := Void
end
l_parameters.put (l_new_tags, "tags")
if l_update and l_new_tags /~ l_previous_tags then
sql_change (sql_update_blog_data, l_parameters)
elseif l_new_tags /= Void then
sql_change (sql_insert_blog_data, l_parameters)
l_has_modif := l_has_modif or (l_new_tags /~ l_previous_tags)
create l_parameters.make (3)
l_parameters.put (a_node.id, "nid")
l_parameters.put (a_node.revision, "revision")
l_parameters.force (l_new_tags, "tags")
if l_update then
if l_has_modif then
sql_change (sql_update_node_data, l_parameters)
end
else
-- no blog data, means everything is empty.
if l_has_modif then
sql_change (sql_insert_node_data, l_parameters)
else
-- no page data, means everything is empty.
-- FOR NOW: always record row
-- sql_change (sql_insert_node_data, l_parameters)
end
end
end
end
load (a_node: CMS_BLOG)
local
l_tags: READABLE_STRING_32
do
if attached node_data (a_node) as d then
l_tags := d.tags
a_node.set_tags_from_string (l_tags)
end
end
node_data (a_node: CMS_NODE): detachable TUPLE [revision: INTEGER_64; tags: READABLE_STRING_32]
local
l_parameters: STRING_TABLE [ANY]
l_rev: INTEGER_64
l_tags: detachable READABLE_STRING_32
n: INTEGER
do
error_handler.reset
create l_parameters.make (2)
l_parameters.put (a_node.id, "nid")
l_parameters.put (a_node.revision, "revision")
sql_query (sql_select_blog_data, l_parameters)
sql_query (sql_select_node_data, l_parameters)
if not has_error then
n := sql_rows_count
if n = 1 then
-- nid, revision, parent
if
attached sql_read_string_32 (3) as l_tags and then
not l_tags.is_whitespace
then
-- FIXME: find a simple way to access the declared content types.
a_node.set_tags_from_string (l_tags)
-- nid, revision, tags
l_rev := sql_read_integer_64 (2)
l_tags := sql_read_string_32 (3)
if l_tags /= Void then
Result := [l_rev, l_tags]
end
else
check unique_data: n = 0 end
@@ -108,8 +135,8 @@ feature -- Persistence
feature -- SQL
sql_select_blog_data: STRING = "SELECT nid, revision, tags FROM blog_post_nodes WHERE nid =:nid AND revision=:revision;"
sql_insert_blog_data: STRING = "INSERT INTO blog_post_nodes (nid, revision, tags) VALUES (:nid, :revision, :tags);"
sql_update_blog_data: STRING = "UPDATE blog_post_nodes SET nid=:nid, revision=:revision, tags=:tags WHERE nid=:nid AND revision=:revision;"
sql_select_node_data: STRING = "SELECT nid, revision, tags FROM blog_post_nodes WHERE nid =:nid AND revision<=:revision ORDER BY revision DESC LIMIT 1;"
sql_insert_node_data: STRING = "INSERT INTO blog_post_nodes (nid, revision, tags) VALUES (:nid, :revision, :tags);"
sql_update_node_data: STRING = "UPDATE blog_post_nodes SET nid=:nid, revision=:revision, tags=:tags WHERE nid=:nid AND revision=:revision;"
end