Added support for log stored in CMS_STORAGE.

Added support for custom value stored in CMS_STORAGE.
Added optional css classes addition to CMS_BLOCK output.
Refactored storage, to manage node from node module code only (or mostly).

TODO: improved view for a cms node, for now hardcoded.
This commit is contained in:
2015-04-15 16:39:03 +02:00
parent 2b25c23977
commit f2bb061488
59 changed files with 1693 additions and 414 deletions

View File

@@ -1,5 +1,5 @@
note
description: "Proxy on a {CMS_STORAGE_SQL} interface."
description: "Proxy on a {CMS_STORAGE_SQL_I} interface."
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
@@ -7,7 +7,7 @@ class
CMS_PROXY_STORAGE_SQL
inherit
CMS_STORAGE_SQL
CMS_STORAGE_SQL_I
create
make
@@ -19,7 +19,7 @@ feature {NONE} -- Initialization
sql_storage := a_sql_storage
end
sql_storage: CMS_STORAGE_SQL
sql_storage: CMS_STORAGE_SQL_I
feature -- Access

View File

@@ -10,9 +10,9 @@ deferred class
CMS_STORAGE
inherit
CMS_USER_STORAGE
CMS_CORE_STORAGE_I
CMS_NODE_STORAGE
CMS_USER_STORAGE_I
SHARED_LOGGER
@@ -52,21 +52,4 @@ feature -- Element change
api := a_api
end
feature -- Misc
-- set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: READABLE_STRING_8)
-- -- Save data `a_name:a_value' for type `a_type'
-- deferred
-- end
-- custom_value (a_name: READABLE_STRING_8; a_type: READABLE_STRING_8): detachable TABLE_ITERABLE [READABLE_STRING_8, STRING_8]
-- -- Data for name `a_name' and type `a_type'.
-- deferred
-- end
-- custom_value_names_where (a_where_key, a_where_value: READABLE_STRING_8; a_type: READABLE_STRING_8): detachable LIST [READABLE_STRING_8]
-- -- Names where custom value has item `a_where_key' same as `a_where_value' for type `a_type'.
-- deferred
-- end
end

View File

@@ -12,6 +12,7 @@ deferred class
feature -- Factory
storage (a_setup: CMS_SETUP): detachable CMS_STORAGE
-- CMS Storage object based on CMS setup `a_setup'.
deferred
end

View File

@@ -120,80 +120,29 @@ feature -- Change: roles and permissions
do
end
feature -- Access: node
nodes_count: INTEGER_64
-- Count of nodes.
feature -- Logs
save_log (a_log: CMS_LOG)
-- Save `a_log'.
do
end
nodes: LIST[CMS_NODE]
-- List of nodes.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
-- List of the `a_count' most recent nodes, starting from `a_lower'.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
node_by_id (a_id: INTEGER_64): detachable CMS_NODE
-- <Precursor>
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
-- Save data `a_name:a_value' for type `a_type' (or default if none).
do
end
node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER
-- Node's author. if any.
unset_custom_value (a_name: READABLE_STRING_8; a_type: detachable READABLE_STRING_8)
-- Delete data `a_name' for type `a_type' (or default if none).
do
end
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
-- Possible list of node's collaborator.
do
create {ARRAYED_LIST [CMS_USER]} Result.make (0)
end
feature -- Node
new_node (a_node: CMS_NODE)
-- Add a new node
custom_value (a_name: READABLE_STRING_GENERAL; a_type: detachable READABLE_STRING_8): detachable READABLE_STRING_32
-- Data for name `a_name' and type `a_type' (or default if none).
do
end
delete_node_by_id (a_id: INTEGER_64)
-- <Precursor>
do
end
update_node (a_node: CMS_NODE)
-- <Precursor>
do
end
update_node_title (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- <Precursor>
do
end
update_node_summary (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- <Precursor>
do
end
update_node_content (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- <Precursor>
do
end
feature -- Helpers
fill_node (a_node: CMS_NODE)
-- Fill `a_node' with extra information from database.
-- i.e: specific to each content type data.
do
end
end

View File

@@ -0,0 +1,15 @@
note
description: "[
Objects that ...
]"
author: "$Author: jfiat $"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
deferred class
CMS_STORAGE_SQL_BUILDER
inherit
CMS_STORAGE_BUILDER
end

View File

@@ -1,11 +1,10 @@
note
description: "Summary description for {CMS_STORAGE_SQL}."
author: ""
description: "Interface used to implement CMS Storage based on SQL statement."
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
deferred class
CMS_STORAGE_SQL
CMS_STORAGE_SQL_I
feature -- Access
@@ -161,6 +160,7 @@ feature -- Helper
sql_query ("SELECT count(*) FROM :tbname ;", l_params)
Result := not has_error
-- FIXME: find better solution
reset_error
end
sql_table_items_count (a_table_name: READABLE_STRING_8): INTEGER_64
@@ -252,7 +252,7 @@ feature -- Access
elseif attached {BOOLEAN_REF} l_item as l_boolean_ref then
Result := l_boolean_ref.item.out
else
check is_string: False end
check is_string_nor_null: l_item = Void end
end
end
@@ -269,7 +269,7 @@ feature -- Access
if attached sql_read_string (a_index) as s8 then
Result := s8.to_string_32 -- FIXME: any escape?
else
check is_string_32: False end
check is_string_nor_null: l_item = Void end
end
end
end
@@ -283,7 +283,7 @@ feature -- Access
if attached {DATE_TIME} l_item as dt then
Result := dt
else
-- check is_date_time: False end
check is_date_time_nor_null: l_item = Void end
end
end

View File

@@ -0,0 +1,47 @@
note
description: "[
Objects that ...
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_CORE_STORAGE_I
inherit
SHARED_LOGGER
feature -- Error Handling
error_handler: ERROR_HANDLER
-- Error handler.
deferred
end
feature -- Logs
save_log (a_log: CMS_LOG)
-- Save `a_log'.
deferred
end
feature -- Misc
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
-- Save data `a_name:a_value' for type `a_type' (or default if none).
deferred
end
unset_custom_value (a_name: READABLE_STRING_8; a_type: detachable READABLE_STRING_8)
-- Delete data `a_name' for type `a_type' (or default if none).
deferred
end
custom_value (a_name: READABLE_STRING_GENERAL; a_type: detachable READABLE_STRING_8): detachable READABLE_STRING_32
-- Data for name `a_name' and type `a_type' (or default if none).
deferred
end
end

View File

@@ -0,0 +1,138 @@
note
description: "[
Objects that ...
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_CORE_STORAGE_SQL_I
inherit
CMS_CORE_STORAGE_I
CMS_STORAGE_SQL_I
REFACTORING_HELPER
SHARED_LOGGER
feature -- Logs
save_log (a_log: CMS_LOG)
-- Save `a_log'.
local
l_parameters: STRING_TABLE [detachable ANY]
now: DATE_TIME
s32: STRING_32
do
create now.make_now_utc
error_handler.reset
create l_parameters.make (8)
l_parameters.put (a_log.category, "category")
l_parameters.put (a_log.level, "level")
l_parameters.put (0, "uid") -- Unsupported for now
l_parameters.put (a_log.message, "message")
l_parameters.put (a_log.info, "info")
if attached a_log.link as lnk then
create s32.make_empty
s32.append_character ('[')
s32.append_string_general (lnk.location)
s32.append_character (']')
s32.append_character ('(')
s32.append (lnk.title)
s32.append_character (')')
l_parameters.put (s32, "link")
else
l_parameters.put (Void, "link")
end
l_parameters.put (now, "date")
sql_change (sql_insert_log, l_parameters)
end
sql_insert_log: STRING = "INSERT INTO logs (category, level, uid, message, info, link, date) VALUES (:category, :level, :uid, :message, :info, :link, :date);"
-- SQL Insert to add a new node.
feature -- Misc
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
-- <Precursor>
local
l_parameters: STRING_TABLE [detachable ANY]
do
error_handler.reset
create l_parameters.make (3)
if a_type /= Void then
l_parameters.put (a_type, "type")
else
l_parameters.put (a_type, "default")
end
l_parameters.put (a_name, "name")
l_parameters.put (a_value, "value")
if attached custom_value (a_name, a_type) as l_value then
if a_value.same_string (l_value) then
-- already up to date
else
sql_change (sql_update_custom_value, l_parameters)
end
else
sql_change (sql_insert_custom_value, l_parameters)
end
end
unset_custom_value (a_name: READABLE_STRING_8; a_type: detachable READABLE_STRING_8)
-- <Precursor>
local
l_parameters: STRING_TABLE [detachable ANY]
do
error_handler.reset
create l_parameters.make (3)
if a_type /= Void then
l_parameters.put (a_type, "type")
else
l_parameters.put (a_type, "default")
end
l_parameters.put (a_name, "name")
sql_change (sql_delete_custom_value, l_parameters)
end
custom_value (a_name: READABLE_STRING_GENERAL; a_type: detachable READABLE_STRING_8): detachable READABLE_STRING_32
-- <Precursor>
local
l_parameters: STRING_TABLE [detachable ANY]
do
error_handler.reset
create l_parameters.make (2)
if a_type /= Void then
l_parameters.put (a_type, "type")
else
l_parameters.put (a_type, "default")
end
l_parameters.put (a_name, "name")
sql_query (sql_select_custom_value, l_parameters)
if not has_error then
if sql_rows_count = 1 then
Result := sql_read_string_32 (1)
end
end
end
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_custom_value: STRING = "INSERT INTO custom_values (type, name, value) VALUES (:type, :name, :value);"
-- SQL Insert to add a new custom value.
sql_update_custom_value : STRING = "UPDATE custom_values SET value=:value WHERE type=:type AND name=:name;"
-- SQL Update to modify a custom value.
sql_delete_custom_value: STRING = "DELETE FROM custom_values WHERE type=:type AND name=:name;"
-- SQL delete custom value;
end

View File

@@ -1,11 +1,10 @@
note
description: "Summary description for {CMS_NODE_STORAGE}."
author: ""
description: "Summary description for {CMS_NODE_STORAGE_I}."
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
deferred class
CMS_NODE_STORAGE
CMS_NODE_STORAGE_I
inherit
SHARED_LOGGER

View File

@@ -0,0 +1,106 @@
note
description: "[
Objects that ...
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
class
CMS_NODE_STORAGE_NULL
inherit
CMS_NODE_STORAGE_I
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
create error_handler.make
end
feature -- Error Handling
error_handler: ERROR_HANDLER
-- Error handler.
feature -- Access: node
nodes_count: INTEGER_64
-- Count of nodes.
do
end
nodes: LIST[CMS_NODE]
-- List of nodes.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
-- List of the `a_count' most recent nodes, starting from `a_lower'.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
node_by_id (a_id: INTEGER_64): detachable CMS_NODE
-- <Precursor>
do
end
node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER
-- Node's author. if any.
do
end
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
-- Possible list of node's collaborator.
do
create {ARRAYED_LIST [CMS_USER]} Result.make (0)
end
feature -- Node
new_node (a_node: CMS_NODE)
-- Add a new node
do
end
delete_node_by_id (a_id: INTEGER_64)
-- <Precursor>
do
end
update_node (a_node: CMS_NODE)
-- <Precursor>
do
end
-- update_node_title (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- -- <Precursor>
-- do
-- end
-- update_node_summary (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- -- <Precursor>
-- do
-- end
-- update_node_content (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- -- <Precursor>
-- do
-- end
feature -- Helpers
fill_node (a_node: CMS_NODE)
-- Fill `a_node' with extra information from database.
-- i.e: specific to each content type data.
do
end
end

View File

@@ -5,18 +5,23 @@ note
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
deferred class
class
CMS_NODE_STORAGE_SQL
inherit
CMS_NODE_STORAGE
CMS_PROXY_STORAGE_SQL
CMS_STORAGE_SQL
CMS_NODE_STORAGE_I
CMS_STORAGE_SQL_I
REFACTORING_HELPER
SHARED_LOGGER
create
make
feature -- Access
nodes_count: INTEGER_64
@@ -146,7 +151,7 @@ feature -- Change: Node
error_handler.reset
create l_parameters.make (1)
l_parameters.put (a_id, "id")
l_parameters.put (a_id, "nid")
sql_change (sql_delete_node, l_parameters)
end
@@ -201,7 +206,6 @@ feature {NONE} -- Implementation
local
l_parameters: STRING_TABLE [detachable ANY]
now: DATE_TIME
is_new: BOOLEAN
do
create now.make_now_utc
error_handler.reset
@@ -212,6 +216,7 @@ feature {NONE} -- Implementation
l_parameters.put (a_node.title, "title")
l_parameters.put (a_node.summary, "summary")
l_parameters.put (a_node.content, "content")
l_parameters.put (a_node.format, "format")
l_parameters.put (a_node.publication_date, "publish")
l_parameters.put (now, "changed")
if attached a_node.author as l_author then
@@ -222,16 +227,14 @@ feature {NONE} -- Implementation
end
sql_begin_transaction
if a_node.has_id then
is_new := True
-- Update
l_parameters.put (a_node.id, "id")
l_parameters.put (a_node.id, "nid")
sql_change (sql_update_node, l_parameters)
if not error_handler.has_error then
a_node.set_revision (a_node.revision + 1) -- FIXME: Should be incremented by one, in same transaction...but check!
a_node.set_modification_date (now)
end
else
is_new := False
-- Store new node
l_parameters.put (a_node.creation_date, "created")
sql_change (sql_insert_node, l_parameters)
@@ -263,14 +266,14 @@ feature {NONE} -- Queries
sql_select_nodes: STRING = "SELECT * from Nodes;"
-- SQL Query to retrieve all nodes.
sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, author, publish, created, changed FROM Nodes WHERE nid =:nid ORDER BY revision desc, publish desc LIMIT 1;"
sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM Nodes WHERE nid =:nid ORDER BY revision desc, publish desc LIMIT 1;"
sql_select_recent_nodes: STRING = "SELECT nid, revision, type, title, summary, content, author, publish, created, changed FROM Nodes ORDER BY nid desc, publish desc LIMIT :rows OFFSET :offset ;"
sql_select_recent_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM Nodes ORDER BY nid desc, publish desc LIMIT :rows OFFSET :offset ;"
sql_insert_node: STRING = "INSERT INTO nodes (revision, type, title, summary, content, publish, created, changed, author) VALUES (1, :type, :title, :summary, :content, :publish, :created, :changed, :author);"
sql_insert_node: STRING = "INSERT INTO nodes (revision, type, title, summary, content, format, publish, created, changed, author) VALUES (1, :type, :title, :summary, :content, :format, :publish, :created, :changed, :author);"
-- SQL Insert to add a new node.
sql_update_node : STRING = "UPDATE nodes SET revision = revision + 1, type=:type, title=:title, summary=:summary, content=:content, publish=:publish, changed=:changed, revision = revision + 1, author=:author WHERE nid=:nid;"
sql_update_node : STRING = "UPDATE nodes SET revision = revision + 1, type=:type, title=:title, summary=:summary, content=:content, format=:format, publish=:publish, changed=:changed, revision = revision + 1, author=:author WHERE nid=:nid;"
-- SQL node.
sql_delete_node: STRING = "DELETE FROM nodes WHERE nid=:nid;"
@@ -292,7 +295,7 @@ feature {NONE} -- Sql Queries: USER_ROLES collaborators, author
Select_user_author: STRING = "SELECT uid, name, password, salt, email, status, created, signed FROM Nodes INNER JOIN users ON nodes.author=users.uid AND users.uid = :uid;"
Select_node_author: STRING = "SELECT nid, revision, type, title, summary, content, author, publish, created, changed FROM users INNER JOIN nodes ON nodes.author=users.uid AND nodes.nid =:nid;"
Select_node_author: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM users INNER JOIN nodes ON nodes.author=users.uid AND nodes.nid =:nid;"
feature {NONE} -- Implementation
@@ -316,18 +319,21 @@ feature {NONE} -- Implementation
if attached sql_read_string (6) as l_content then
Result.set_content (l_content)
end
if attached sql_read_date_time (8) as l_publication_date then
if attached sql_read_string (7) as l_format then
Result.set_format (l_format)
end
if attached sql_read_integer_64 (8) as l_author_id then
Result.set_author (create {CMS_PARTIAL_USER}.make_with_id (l_author_id))
end
if attached sql_read_date_time (9) as l_publication_date then
Result.set_publication_date (l_publication_date)
end
if attached sql_read_date_time (9) as l_creation_date then
if attached sql_read_date_time (10) as l_creation_date then
Result.set_creation_date (l_creation_date)
end
if attached sql_read_date_time (10) as l_modif_date then
if attached sql_read_date_time (11) as l_modif_date then
Result.set_modification_date (l_modif_date)
end
if attached sql_read_integer_64 (7) as l_author_id then
Result.set_author (create {CMS_PARTIAL_USER}.make_with_id (l_author_id))
end
end
end

View File

@@ -90,6 +90,7 @@ feature -- Persistence
l_parent_id /= a_node.id and then
attached node_storage.node_by_id (l_parent_id) as l_parent
then
-- FIXME: find a simple way to access the declared content types.
create ct
a_node.set_parent (ct.new_node (l_parent))
else

View File

@@ -1,11 +1,11 @@
note
description: "Summary description for {CMS_USER_STORAGE}."
description: "Summary description for {CMS_USER_STORAGE_I}."
author: ""
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
deferred class
CMS_USER_STORAGE
CMS_USER_STORAGE_I
inherit
SHARED_LOGGER

View File

@@ -1,16 +1,15 @@
note
description: "Summary description for {CMS_USER_STORAGE_SQL}."
author: ""
description: "Summary description for {CMS_USER_STORAGE_SQL_I}."
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
deferred class
CMS_USER_STORAGE_SQL
CMS_USER_STORAGE_SQL_I
inherit
CMS_USER_STORAGE
CMS_USER_STORAGE_I
CMS_STORAGE_SQL
CMS_STORAGE_SQL_I
REFACTORING_HELPER
@@ -34,6 +33,7 @@ feature -- Access: user
if sql_rows_count = 1 then
Result := sql_read_integer_32 (1)
end
error_handler.reset
end
users: LIST [CMS_USER]