Updated table node to use status (1:not_published, 2:published, 3:trash )instead of deleted_at to implement soft deletes.
Updated queries to use the new status field. Updated CMS_NODE with a new status attribute.
This commit is contained in:
@@ -12,7 +12,7 @@ CREATE TABLE "nodes"(
|
|||||||
"publish" DATETIME,
|
"publish" DATETIME,
|
||||||
"created" DATETIME NOT NULL,
|
"created" DATETIME NOT NULL,
|
||||||
"changed" DATETIME NOT NULL,
|
"changed" DATETIME NOT NULL,
|
||||||
"deleted_at" DATETIME NULL
|
"status" INTEGER
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE page_nodes(
|
CREATE TABLE page_nodes(
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ feature{NONE} -- Initialization
|
|||||||
set_creation_date (l_time)
|
set_creation_date (l_time)
|
||||||
set_modification_date (l_time)
|
set_modification_date (l_time)
|
||||||
set_publication_date (l_time)
|
set_publication_date (l_time)
|
||||||
|
mark_not_published
|
||||||
|
|
||||||
debug ("refactor_fixme")
|
debug ("refactor_fixme")
|
||||||
fixme ("Remove default harcoded format")
|
fixme ("Remove default harcoded format")
|
||||||
@@ -60,6 +61,7 @@ feature -- Conversion
|
|||||||
a_node.summary,
|
a_node.summary,
|
||||||
a_node.format
|
a_node.format
|
||||||
)
|
)
|
||||||
|
set_status (a_node.status)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
@@ -78,6 +80,10 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
status: INTEGER
|
||||||
|
-- Associated status for the current node
|
||||||
|
-- [{1,Not_Published}, {2, Published}, {3, Trash}]
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
title: READABLE_STRING_32
|
title: READABLE_STRING_32
|
||||||
@@ -211,6 +217,41 @@ feature -- Element change
|
|||||||
auther_set: author = u
|
auther_set: author = u
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mark_not_published
|
||||||
|
-- Set status to not_published
|
||||||
|
do
|
||||||
|
set_status ({CMS_NODE_CONSTANTS}.not_published)
|
||||||
|
ensure
|
||||||
|
status_not_published: status = {CMS_NODE_CONSTANTS}.not_published
|
||||||
|
end
|
||||||
|
|
||||||
|
mark_published
|
||||||
|
-- Set status to published
|
||||||
|
do
|
||||||
|
set_status ({CMS_NODE_CONSTANTS}.published)
|
||||||
|
ensure
|
||||||
|
status_published: status = {CMS_NODE_CONSTANTS}.published
|
||||||
|
end
|
||||||
|
|
||||||
|
mark_trash
|
||||||
|
-- Set status to published
|
||||||
|
do
|
||||||
|
set_status ({CMS_NODE_CONSTANTS}.trash)
|
||||||
|
ensure
|
||||||
|
status_trash: status = {CMS_NODE_CONSTANTS}.trash
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
|
set_status (a_status: like status)
|
||||||
|
-- Assign `status' with `a_status'
|
||||||
|
do
|
||||||
|
status := a_status
|
||||||
|
ensure
|
||||||
|
status_set: status = a_status
|
||||||
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, 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)"
|
||||||
|
|||||||
17
modules/node/content/cms_node_constants.e
Normal file
17
modules/node/content/cms_node_constants.e
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
note
|
||||||
|
description: "Node Status Not-Published, Published and Trash"
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
CMS_NODE_CONSTANTS
|
||||||
|
|
||||||
|
Feature
|
||||||
|
|
||||||
|
Not_published: INTEGER = 1
|
||||||
|
|
||||||
|
Published: INTEGER = 2
|
||||||
|
|
||||||
|
Trash: INTEGER = 3
|
||||||
|
|
||||||
|
end
|
||||||
@@ -151,8 +151,9 @@ feature -- Change: Node
|
|||||||
|
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
create l_parameters.make (1)
|
create l_parameters.make (1)
|
||||||
|
l_parameters.put (l_time, "changed")
|
||||||
|
l_parameters.put ({CMS_NODE_CONSTANTS}.trash, "status")
|
||||||
l_parameters.put (a_id, "nid")
|
l_parameters.put (a_id, "nid")
|
||||||
l_parameters.put (l_time, "deleted_at")
|
|
||||||
sql_change (sql_delete_node, l_parameters)
|
sql_change (sql_delete_node, l_parameters)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -212,7 +213,7 @@ feature {NONE} -- Implementation
|
|||||||
error_handler.reset
|
error_handler.reset
|
||||||
|
|
||||||
write_information_log (generator + ".store_node")
|
write_information_log (generator + ".store_node")
|
||||||
create l_parameters.make (8)
|
create l_parameters.make (9)
|
||||||
l_parameters.put (a_node.content_type, "type")
|
l_parameters.put (a_node.content_type, "type")
|
||||||
l_parameters.put (a_node.title, "title")
|
l_parameters.put (a_node.title, "title")
|
||||||
l_parameters.put (a_node.summary, "summary")
|
l_parameters.put (a_node.summary, "summary")
|
||||||
@@ -220,6 +221,7 @@ feature {NONE} -- Implementation
|
|||||||
l_parameters.put (a_node.format, "format")
|
l_parameters.put (a_node.format, "format")
|
||||||
l_parameters.put (a_node.publication_date, "publish")
|
l_parameters.put (a_node.publication_date, "publish")
|
||||||
l_parameters.put (now, "changed")
|
l_parameters.put (now, "changed")
|
||||||
|
l_parameters.put (a_node.status, "status")
|
||||||
if attached a_node.author as l_author then
|
if attached a_node.author as l_author then
|
||||||
check valid_author: l_author.has_id end
|
check valid_author: l_author.has_id end
|
||||||
l_parameters.put (l_author.id, "author")
|
l_parameters.put (l_author.id, "author")
|
||||||
@@ -263,24 +265,26 @@ feature -- Helpers
|
|||||||
|
|
||||||
feature {NONE} -- Queries
|
feature {NONE} -- Queries
|
||||||
|
|
||||||
sql_select_nodes_count: STRING = "SELECT count(*) from Nodes where deleted_at IS NULL;"
|
sql_select_nodes_count: STRING = "SELECT count(*) FROM Nodes WHERE status != 3;"
|
||||||
|
-- Nodes count (Published and not Published)
|
||||||
|
-- TODO: add queries to retrieve published_nodes_count, no_published_nodes_count. etc
|
||||||
|
|
||||||
sql_select_nodes: STRING = "SELECT * from Nodes where deleted_at IS NULL;"
|
sql_select_nodes: STRING = "SELECT * FROM Nodes WHERE status != 3;"
|
||||||
-- SQL Query to retrieve all nodes.
|
-- SQL Query to retrieve all nodes.
|
||||||
|
|
||||||
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_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status 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, format, 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, status FROM Nodes ORDER BY nid desc, publish desc LIMIT :rows OFFSET :offset ;"
|
||||||
|
|
||||||
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_node: STRING = "INSERT INTO nodes (revision, type, title, summary, content, format, publish, created, changed, status, author) VALUES (1, :type, :title, :summary, :content, :format, :publish, :created, :changed, :status, :author);"
|
||||||
-- SQL Insert to add a new node.
|
-- SQL Insert to add a new node.
|
||||||
|
|
||||||
sql_update_node : STRING = "UPDATE nodes SET revision = revision, type=:type, title=:title, summary=:summary, content=:content, format=:format, publish=:publish, changed=:changed, author=:author WHERE nid=:nid;"
|
sql_update_node : STRING = "UPDATE nodes SET revision = revision, type=:type, title=:title, summary=:summary, content=:content, format=:format, publish=:publish, changed=:changed, status=:status, author=:author WHERE nid=:nid;"
|
||||||
-- FIXME: for now no revision inc.!
|
-- FIXME: for now no revision inc.!
|
||||||
-- 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_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 node.
|
||||||
|
|
||||||
sql_delete_node: STRING = "UPDATE nodes SET deleted_at = :deleted_at WHERE nid=:nid"
|
sql_delete_node: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid"
|
||||||
-- Soft deletion with free metadata.
|
-- Soft deletion with free metadata.
|
||||||
|
|
||||||
-- sql_update_node_author: STRING = "UPDATE nodes SET author=:author WHERE nid=:nid;"
|
-- sql_update_node_author: STRING = "UPDATE nodes SET author=:author WHERE nid=:nid;"
|
||||||
@@ -339,6 +343,16 @@ feature {NONE} -- Implementation
|
|||||||
if attached sql_read_date_time (11) as l_modif_date then
|
if attached sql_read_date_time (11) as l_modif_date then
|
||||||
Result.set_modification_date (l_modif_date)
|
Result.set_modification_date (l_modif_date)
|
||||||
end
|
end
|
||||||
|
if attached sql_read_integer_32 (12) as l_status then
|
||||||
|
inspect l_status
|
||||||
|
when {CMS_NODE_CONSTANTS}.not_published then
|
||||||
|
Result.mark_not_published
|
||||||
|
when {CMS_NODE_CONSTANTS}.published then
|
||||||
|
Result.mark_published
|
||||||
|
when {CMS_NODE_CONSTANTS}.trash then
|
||||||
|
Result.mark_trash
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ feature -- Status report
|
|||||||
if is_admin_user (a_user) then
|
if is_admin_user (a_user) then
|
||||||
Result := True
|
Result := True
|
||||||
else
|
else
|
||||||
fixme ("Check how to handle this predefined role")
|
Result := user_role_has_permission (authenticated_user_role, a_permission)
|
||||||
-- Result := user_role_has_permission (authenticated_user_role, a_permission)
|
|
||||||
if not Result then
|
if not Result then
|
||||||
Result := across user_roles (a_user) as ic some user_role_has_permission (ic.item, a_permission) end
|
Result := across user_roles (a_user) as ic some user_role_has_permission (ic.item, a_permission) end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user