Added notion of author (owner) and editor to allow the editing of node by non owner users.

This commit is contained in:
2017-03-03 11:12:51 +01:00
parent 4cbdfeff06
commit 6cb6dd1609
18 changed files with 248 additions and 70 deletions

View File

@@ -8,6 +8,7 @@ CREATE TABLE nodes (
`content` TEXT, `content` TEXT,
`format` VARCHAR(128), `format` VARCHAR(128),
`author` INTEGER, `author` INTEGER,
`editor` INTEGER,
`publish` DATETIME, `publish` DATETIME,
`created` DATETIME NOT NULL, `created` DATETIME NOT NULL,
`changed` DATETIME NOT NULL, `changed` DATETIME NOT NULL,
@@ -23,6 +24,7 @@ CREATE TABLE node_revisions (
`content` TEXT, `content` TEXT,
`format` VARCHAR(128), `format` VARCHAR(128),
`author` INTEGER, `author` INTEGER,
`editor` INTEGER,
`changed` DATETIME NOT NULL, `changed` DATETIME NOT NULL,
`status` INTEGER, `status` INTEGER,
CONSTRAINT Unique_nid_revision PRIMARY KEY (nid,revision) CONSTRAINT Unique_nid_revision PRIMARY KEY (nid,revision)

View File

@@ -0,0 +1,7 @@
ALTER TABLE nodes ADD editor INTEGER ;
UPDATE nodes SET editor = author;
ALTER TABLE node_revisions ADD editor INTEGER ;
UPDATE node_revisions SET editor = author;

View File

@@ -276,7 +276,11 @@ feature -- Hooks
if l_entity.is_published then if l_entity.is_published then
if l_entity.author = Void then if l_entity.author = Void then
-- FIXME!!! -- FIXME!!!
l_entity.set_author (l_blog_api.cms_api.user) if attached l_entity.editor as l_last_editor then
l_entity.set_author (l_last_editor)
else
l_entity.set_author (l_blog_api.cms_api.user)
end
a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" WARNING (Author is unknown!)") a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" WARNING (Author is unknown!)")
end end
if attached l_entity.author as l_author then if attached l_entity.author as l_author then

View File

@@ -159,16 +159,28 @@ feature {NONE} -- Queries
-- Nodes count (Published and not Published) -- Nodes count (Published and not Published)
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
sql_select_blogs_order_created_desc: STRING = "SELECT * FROM nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC;" sql_select_blogs_order_created_desc: STRING
-- SQL Query to retrieve all nodes that are from the type "blog" ordered by descending creation date. -- SQL Query to retrieve all nodes that are from the type "blog" ordered by descending creation date.
once
Result := sql_select_all_from_nodes + " WHERE status != -1 AND type = %"blog%" ORDER BY created DESC;"
end
sql_blogs_limited: STRING = "SELECT * FROM nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC LIMIT :limit OFFSET :offset ;" sql_blogs_limited: STRING
--- SQL Query to retrieve all nodes of type "blog" limited by limit and starting at offset --- SQL Query to retrieve all nodes of type "blog" limited by limit and starting at offset
once
Result := sql_select_all_from_nodes + " WHERE status != -1 AND type = %"blog%" ORDER BY created DESC LIMIT :limit OFFSET :offset ;"
end
sql_blogs_from_user_limited: STRING = "SELECT * FROM nodes WHERE status != -1 AND type = %"blog%" AND author = :user ORDER BY created DESC LIMIT :limit OFFSET :offset ;" sql_blogs_from_user_limited: STRING
--- SQL Query to retrieve all nodes of type "blog" from author with id limited by limit + offset --- SQL Query to retrieve all nodes of type "blog" from author with id limited by limit + offset
once
Result := sql_select_all_from_nodes + " WHERE status != -1 AND type = %"blog%" AND author = :user ORDER BY created DESC LIMIT :limit OFFSET :offset ;"
end
sql_blogs_from_user_with_title: STRING = "SELECT * FROM nodes WHERE status != -1 AND type = %"blog%" AND author = :user AND title = :title ORDER BY created DESC;" sql_blogs_from_user_with_title: STRING
--- SQL Query to retrieve all nodes of type "blog" from author with title . --- SQL Query to retrieve all nodes of type "blog" from author with title .
once
Result := sql_select_all_from_nodes + " WHERE status != -1 AND type = %"blog%" AND author = :user AND title = :title ORDER BY created DESC;"
end
end end

View File

@@ -243,15 +243,23 @@ feature -- Access: Node
check has_link: Result.has_id implies attached Result.link as lnk and then lnk.location.same_string (node_link (Result).location) end check has_link: Result.has_id implies attached Result.link as lnk and then lnk.location.same_string (node_link (Result).location) end
-- Update partial user if needed. -- Update partial user if needed.
if if Result /= Void then
Result /= Void and then if attached {CMS_PARTIAL_USER} Result.author as l_partial_author then
attached {CMS_PARTIAL_USER} Result.author as l_partial_author if attached cms_api.user_api.user_by_id (l_partial_author.id) as l_author then
then Result.set_author (l_author)
if attached cms_api.user_api.user_by_id (l_partial_author.id) as l_author then else
Result.set_author (l_author) check
else valid_author_id: False
check end
valid_author_id: False end
end
if attached {CMS_PARTIAL_USER} Result.editor as l_partial_editor then
if attached cms_api.user_api.user_by_id (l_partial_editor.id) as l_editor then
Result.set_editor (l_editor)
else
check
valid_author_id: False
end
end end
end end
end end

View File

@@ -37,7 +37,7 @@ feature {NONE} -- Initialization
make make
-- Create Current module, disabled by default. -- Create Current module, disabled by default.
do do
version := "1.0" version := "1.0.0.1"
description := "Service to manage content based on 'node'" description := "Service to manage content based on 'node'"
package := "core" package := "core"
-- Optional dependencies, mainly for information. -- Optional dependencies, mainly for information.
@@ -327,7 +327,7 @@ feature -- Hooks
end end
end end
ch.set_information (l_info) ch.set_information (l_info)
ch.set_author (n.author) ch.set_author (n.editor)
ch.set_summary (n.summary) ch.set_summary (n.summary)
if attached {CMS_TAXONOMY_API} l_node_api.cms_api.module_api ({CMS_TAXONOMY_MODULE}) as l_taxonomy_api then if attached {CMS_TAXONOMY_API} l_node_api.cms_api.module_api ({CMS_TAXONOMY_MODULE}) as l_taxonomy_api then
if attached l_taxonomy_api.terms_of_content (n, Void) as l_terms then if attached l_taxonomy_api.terms_of_content (n, Void) as l_terms then

View File

@@ -28,7 +28,7 @@ feature{NONE} -- Initialization
end end
make (a_title: READABLE_STRING_32) make (a_title: READABLE_STRING_32)
-- Create current node with `a_title'. -- Create current node with `a_title`.
local local
now: DATE_TIME now: DATE_TIME
do do
@@ -45,7 +45,7 @@ feature{NONE} -- Initialization
feature -- Conversion feature -- Conversion
import_node (a_node: CMS_NODE) import_node (a_node: CMS_NODE)
-- Import `a_node' into current node. -- Import `a_node` into current node.
do do
set_id (a_node.id) set_id (a_node.id)
set_revision (a_node.revision) set_revision (a_node.revision)
@@ -54,6 +54,7 @@ feature -- Conversion
set_modification_date (a_node.modification_date) set_modification_date (a_node.modification_date)
set_publication_date (a_node.publication_date) set_publication_date (a_node.publication_date)
set_author (a_node.author) set_author (a_node.author)
set_editor (a_node.editor)
set_content ( set_content (
a_node.content, a_node.content,
a_node.summary, a_node.summary,
@@ -144,7 +145,10 @@ feature -- Access: date
feature -- Access: author feature -- Access: author
author: detachable CMS_USER author: detachable CMS_USER
-- Author of current node. -- Author of current node (i.e creator).
editor: detachable CMS_USER
-- Last user that modified Current node.
feature -- status report feature -- status report
@@ -155,7 +159,7 @@ feature -- status report
end end
same_node (a_node: CMS_NODE): BOOLEAN same_node (a_node: CMS_NODE): BOOLEAN
-- Is `a_node' same node as Current? -- Is `a_node` same node as Current?
do do
-- FIXME: if we introduce notion of revision, update this part! -- FIXME: if we introduce notion of revision, update this part!
Result := Current = a_node or id = a_node.id Result := Current = a_node or id = a_node.id
@@ -182,8 +186,8 @@ feature -- Status report
feature -- Element change feature -- Element change
set_content (a_content: like content; a_summary: like summary; a_format: like format) set_content (a_content: like content; a_summary: like summary; a_format: like format)
-- Set `content', `summary' and `format' to `a_content', `a_summary' and `a_format'. -- Set `content`, `summary` and `format` to `a_content`, `a_summary` and `a_format`.
-- The `format' is associated with both `content' and `summary' -- The `format` is associated with both `content` and `summary`
deferred deferred
ensure ensure
content_assigned: content = a_content content_assigned: content = a_content
@@ -192,7 +196,7 @@ feature -- Element change
end end
set_title (a_title: like title) set_title (a_title: like title)
-- Assign `title' with `a_title'. -- Assign `title` with `a_title`.
do do
title := a_title title := a_title
if attached link as lnk then if attached link as lnk then
@@ -203,7 +207,7 @@ feature -- Element change
end end
set_modification_date (a_modification_date: like modification_date) set_modification_date (a_modification_date: like modification_date)
-- Assign `modification_date' with `a_modification_date'. -- Assign `modification_date` with `a_modification_date`.
do do
modification_date := a_modification_date modification_date := a_modification_date
ensure ensure
@@ -211,7 +215,7 @@ feature -- Element change
end end
set_creation_date (a_creation_date: like creation_date) set_creation_date (a_creation_date: like creation_date)
-- Assign `creation_date' with `a_creation_date'. -- Assign `creation_date` with `a_creation_date`.
do do
creation_date := a_creation_date creation_date := a_creation_date
ensure ensure
@@ -219,7 +223,7 @@ feature -- Element change
end end
set_publication_date (a_publication_date: like publication_date) set_publication_date (a_publication_date: like publication_date)
-- Assign `publication_date' with `a_publication_date'. -- Assign `publication_date` with `a_publication_date`.
do do
publication_date := a_publication_date publication_date := a_publication_date
publication_date_output := publication_date.formatted_out ("yyyy/[0]mm/[0]dd") publication_date_output := publication_date.formatted_out ("yyyy/[0]mm/[0]dd")
@@ -228,7 +232,7 @@ feature -- Element change
end end
set_id (a_id: like id) set_id (a_id: like id)
-- Assign `id' with `a_id'. -- Assign `id` with `a_id`.
do do
id := a_id id := a_id
ensure ensure
@@ -236,7 +240,7 @@ feature -- Element change
end end
set_revision (a_revision: like revision) set_revision (a_revision: like revision)
-- Assign `revision' with `a_revision'. -- Assign `revision` with `a_revision`.
do do
revision := a_revision revision := a_revision
ensure ensure
@@ -244,15 +248,23 @@ feature -- Element change
end end
set_author (u: like author) set_author (u: like author)
-- Assign 'author' with `u' -- Assign `author` with `u`
do do
author := u author := u
ensure ensure
auther_set: author = u auther_set: author = u
end end
set_editor (u: like editor)
-- Assign `last_editor` with `u`
do
editor := u
ensure
last_editor_set: editor = u
end
set_link (a_link: like link) set_link (a_link: like link)
-- Set `link' to `a_link'. -- Set `link` to `a_link`.
do do
link := a_link link := a_link
end end
@@ -286,7 +298,7 @@ feature -- Status change
feature {CMS_NODE_STORAGE_I} -- Access: status change. feature {CMS_NODE_STORAGE_I} -- Access: status change.
set_status (a_status: like status) set_status (a_status: like status)
-- Assign `status' with `a_status'. -- Assign `status` with `a_status`.
do do
status := a_status status := a_status
ensure ensure

View File

@@ -33,6 +33,9 @@ feature -- Access
if attached n.author as u then if attached n.author as u then
Result.put (user_to_json (u), "author") Result.put (user_to_json (u), "author")
end end
if attached n.editor as u then
Result.put (user_to_json (u), "editor")
end
create jo.make_empty create jo.make_empty
if attached n.format as l_format then if attached n.format as l_format then
jo.put_string (l_format, "format") jo.put_string (l_format, "format")

View File

@@ -201,9 +201,9 @@ feature -- Forms ...
s := l_summary s := l_summary
end end
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then if attached fd.string_item ("format") as s_format and then attached cms_api.format (s_format) as f_format then
f := f_format f := f_format
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then elseif a_node /= Void and then attached a_node.format as s_format and then attached cms_api.format (s_format) as f_format then
f := f_format f := f_format
else else
f := cms_api.formats.default_format f := cms_api.formats.default_format
@@ -214,8 +214,13 @@ feature -- Forms ...
a_node.set_content (b, s, f.name) a_node.set_content (b, s, f.name)
end end
-- Update author -- Update editor, author
a_node.set_author (response.user) a_node.set_editor (cms_api.user)
if a_node.author = Void then
a_node.set_author (cms_api.user)
else
-- Keep existing author as creator!
end
end end
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable CMS_NODE): G new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable CMS_NODE): G
@@ -253,7 +258,8 @@ feature -- Forms ...
l_node := content_type.new_node_with_title ("...", Void) l_node := content_type.new_node_with_title ("...", Void)
end end
end end
l_node.set_author (response.user) l_node.set_author (cms_api.user)
l_node.set_editor (cms_api.user)
--Summary --Summary
if attached fd.string_item ("summary") as l_summary then if attached fd.string_item ("summary") as l_summary then

View File

@@ -471,6 +471,7 @@ feature -- Form
Result := a_content_type.new_node (a_node) Result := a_content_type.new_node (a_node)
end end
Result.set_author (user) Result.set_author (user)
Result.set_editor (user)
end end
apply_form_data_to_node (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE) apply_form_data_to_node (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)

View File

@@ -333,11 +333,20 @@ feature {NONE} -- Trash:Restore
b.append (" #") b.append (" #")
b.append (n.revision.out) b.append (n.revision.out)
b.append (" : ") b.append (" : ")
b.append (n.modification_date.out) b.append (api.formatted_date_time_yyyy_mm_dd__hh_min_ss (n.modification_date))
b.append ("</a>") b.append ("</a>")
if attached n.author as l_author then if attached n.editor as l_editor then
b.append (" by ") if n.revision = 1 then
b.append (" created by ")
else
b.append (" edited by ")
end
b.append (r.link (r.user_profile_name (l_editor), "user/" + l_editor.id.out, Void))
end
if attached n.author as l_author and then not l_author.same_as (n.editor) then
b.append (" (owner: ")
b.append (r.link (r.user_profile_name (l_author), "user/" + l_author.id.out, Void)) b.append (r.link (r.user_profile_name (l_author), "user/" + l_author.id.out, Void))
b.append (")")
end end
if node_api.has_permission_for_action_on_node ("edit revisions", l_node, api.user) then if node_api.has_permission_for_action_on_node ("edit revisions", l_node, api.user) then
b.append (" (<a href=%"") b.append (" (<a href=%"")

View File

@@ -85,6 +85,10 @@ feature -- Conversion
if attached {JSON_OBJECT} j.item ("author") as j_author then if attached {JSON_OBJECT} j.item ("author") as j_author then
l_node.set_author (json_to_user (j_author, a_node_api)) l_node.set_author (json_to_user (j_author, a_node_api))
end end
if attached {JSON_OBJECT} j.item ("editor") as j_editor then
l_node.set_editor (json_to_user (j_editor, a_node_api))
end
if attached {JSON_OBJECT} j.item ("data") as j_data then if attached {JSON_OBJECT} j.item ("data") as j_data then
l_node.set_all_content (json_string_item (j_data, "content"), json_string_item (j_data, "summary"), json_string_8_item (j_data, "format")) l_node.set_all_content (json_string_item (j_data, "content"), json_string_item (j_data, "summary"), json_string_8_item (j_data, "format"))
end end

View File

@@ -435,7 +435,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 (9) create l_parameters.make (10)
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")
@@ -450,6 +450,13 @@ feature {NONE} -- Implementation
else else
l_parameters.put (0, "author") l_parameters.put (0, "author")
end end
if attached a_node.editor as l_editor then
check valid_editor: l_editor.has_id end
l_parameters.put (l_editor.id, "editor")
else
l_parameters.put (0, "editor")
end
sql_begin_transaction sql_begin_transaction
if a_node.has_id then if a_node.has_id then
@@ -510,7 +517,7 @@ feature -- Helpers
extended_load (a_node) extended_load (a_node)
end end
feature {NONE} -- Queries feature {NONE} -- Queries nodes
sql_select_nodes_count: STRING = "SELECT count(*) FROM nodes WHERE status != -1 ;" sql_select_nodes_count: STRING = "SELECT count(*) FROM nodes WHERE status != -1 ;"
-- Nodes count (Published and not Published) -- Nodes count (Published and not Published)
@@ -520,43 +527,86 @@ feature {NONE} -- Queries
-- Nodes of type `:node_type` count (Published and not Published) -- Nodes of type `:node_type` count (Published and not Published)
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
sql_select_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status != -1 ;" sql_select_nodes: STRING
-- SQL Query to retrieve all nodes. -- SQL Query to retrieve all nodes.
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
once
Result := sql_select_all_from_nodes + " WHERE status != -1 ;"
end
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_select_nodes_of_type: STRING
-- SQL Query to retrieve all nodes of type :node_type. -- SQL Query to retrieve all nodes of type :node_type.
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
once
Result := sql_select_all_from_nodes + " WHERE status != -1 AND type=:node_type ;"
end
sql_select_nodes_of_type_with_title: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status != -1 AND type=:node_type AND title=:title;" sql_select_nodes_of_type_with_title: STRING
-- SQL Query to retrieve all nodes of type :node_type with title :title. -- SQL Query to retrieve all nodes of type :node_type with title :title.
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
once
Result := sql_select_all_from_nodes + " WHERE status != -1 AND type=:node_type AND title=:title;"
end
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_trash_nodes: STRING
-- SQL query to get node revisions (missing the latest one).
sql_select_trash_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status = -1 ;"
-- SQL Query to retrieve all trahsed nodes. -- SQL Query to retrieve all trahsed nodes.
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
once
Result := sql_select_all_from_nodes + " WHERE status = -1 ;"
end
sql_select_trash_nodes_by_author: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status = -1 and author = :author ;" sql_select_trash_nodes_by_author: STRING
-- SQL Query to retrieve all nodes by a given author. -- SQL Query to retrieve all nodes by a given author.
--| note: {CMS_NODE_API}.trashed = -1 --| note: {CMS_NODE_API}.trashed = -1
once
Result := sql_select_all_from_nodes + " WHERE status = -1 and author = :author ;"
end
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_node_by_id: STRING
--
once
Result := sql_select_all_from_nodes + " WHERE nid =:nid ORDER BY revision DESC, publish DESC LIMIT 1;"
end
sql_select_node_by_id_and_revision: 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_recent_nodes: STRING
--
once
Result := sql_select_all_from_nodes + " ORDER BY changed DESC, publish DESC LIMIT :size OFFSET :offset ;"
end
sql_select_recent_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes ORDER BY changed DESC, publish DESC LIMIT :size OFFSET :offset ;" sql_select_recent_nodes_of_type: STRING
--
once
Result := sql_select_all_from_nodes + " WHERE type=:node_type ORDER BY changed DESC, publish DESC LIMIT :size OFFSET :offset ;"
end
sql_select_recent_nodes_of_type: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE type=:node_type ORDER BY changed DESC, publish DESC LIMIT :size OFFSET :offset ;" sql_select_recent_node_changes_before: STRING
--
once
Result := sql_select_all_from_nodes + " WHERE changed <= :date ORDER BY changed DESC, nid DESC LIMIT :size OFFSET :offset ;"
end
sql_select_recent_node_changes_before: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE changed <= :date ORDER BY changed DESC, nid DESC LIMIT :size OFFSET :offset ;" feature {NONE} -- Queries node revisions
sql_insert_node: STRING = "INSERT INTO nodes (revision, type, title, summary, content, format, publish, created, changed, status, author) VALUES (:revision, :type, :title, :summary, :content, :format, :publish, :created, :changed, :status, :author);" 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, node_revisions.editor, 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_select_node_by_id_and_revision: STRING = "SELECT nodes.nid, node_revisions.revision, nodes.type, node_revisions.title, node_revisions.summary, node_revisions.content, node_revisions.format, node_revisions.author, node_revisions.editor, node_revisions.editor, 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_copy_node_to_revision: STRING = "INSERT INTO node_revisions (nid, revision, title, summary, content, format, author, editor, changed, status) SELECT nid, revision, title, summary, content, format, author, editor, changed, status FROM nodes WHERE nid=:nid;"
Sql_last_insert_node_revision: STRING = "SELECT MAX(revision) FROM node_revisions;"
Sql_last_insert_node_revision_for_nid: STRING = "SELECT MAX(revision) FROM node_revisions WHERE nid=:nid;"
sql_delete_node_revisions: STRING = "DELETE FROM node_revisions WHERE nid=:nid;"
feature {NONE} -- Queries insert and update
sql_insert_node: STRING = "INSERT INTO nodes (revision, type, title, summary, content, format, publish, created, changed, status, author, editor) VALUES (:revision, :type, :title, :summary, :content, :format, :publish, :created, :changed, :status, :author, :editor);"
-- 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, status=:status, 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, editor=:editor WHERE nid=:nid;"
-- SQL update node. -- SQL update node.
sql_trash_node: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid" sql_trash_node: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid"
@@ -570,15 +620,10 @@ feature {NONE} -- Queries
sql_last_insert_node_id: STRING = "SELECT MAX(nid) FROM nodes;" sql_last_insert_node_id: STRING = "SELECT MAX(nid) FROM nodes;"
sql_copy_node_to_revision: STRING = "INSERT INTO node_revisions (nid, revision, title, summary, content, format, author, changed, status) SELECT nid, revision, title, summary, content, format, author, changed, status FROM nodes WHERE nid=:nid;"
Sql_last_insert_node_revision: STRING = "SELECT MAX(revision) FROM node_revisions;"
Sql_last_insert_node_revision_for_nid: STRING = "SELECT MAX(revision) FROM node_revisions WHERE nid=:nid;"
sql_delete_node_revisions: STRING = "DELETE FROM node_revisions WHERE nid=:nid;"
feature {NONE} -- Implementation feature {NONE} -- Implementation
sql_select_all_from_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, editor, publish, created, changed, status FROM nodes "
fetch_node: detachable CMS_PARTIAL_NODE fetch_node: detachable CMS_PARTIAL_NODE
do do
if attached sql_read_string (3) as l_type then if attached sql_read_string (3) as l_type then
@@ -605,16 +650,19 @@ feature {NONE} -- Implementation
if attached sql_read_integer_64 (8) as l_author_id then 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)) Result.set_author (create {CMS_PARTIAL_USER}.make_with_id (l_author_id))
end end
if attached sql_read_date_time (9) as l_publication_date then if attached sql_read_integer_64 (9) as l_editor_id then
Result.set_editor (create {CMS_PARTIAL_USER}.make_with_id (l_editor_id))
end
if attached sql_read_date_time (10) as l_publication_date then
Result.set_publication_date (l_publication_date) Result.set_publication_date (l_publication_date)
end end
if attached sql_read_date_time (10) as l_creation_date then if attached sql_read_date_time (11) as l_creation_date then
Result.set_creation_date (l_creation_date) Result.set_creation_date (l_creation_date)
end end
if attached sql_read_date_time (11) as l_modif_date then if attached sql_read_date_time (12) 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 if attached sql_read_integer_32 (13) as l_status then
Result.set_status (l_status) Result.set_status (l_status)
end end
end end

View File

@@ -8,6 +8,7 @@ CREATE TABLE nodes (
`content` TEXT, `content` TEXT,
`format` VARCHAR(128), `format` VARCHAR(128),
`author` INTEGER, `author` INTEGER,
`editor` INTEGER,
`publish` DATETIME, `publish` DATETIME,
`created` DATETIME NOT NULL, `created` DATETIME NOT NULL,
`changed` DATETIME NOT NULL, `changed` DATETIME NOT NULL,
@@ -23,6 +24,7 @@ CREATE TABLE node_revisions (
`content` TEXT, `content` TEXT,
`format` VARCHAR(128), `format` VARCHAR(128),
`author` INTEGER, `author` INTEGER,
`editor` INTEGER,
`changed` DATETIME NOT NULL, `changed` DATETIME NOT NULL,
`status` INTEGER, `status` INTEGER,
CONSTRAINT Unique_nid_revision PRIMARY KEY (nid,revision) CONSTRAINT Unique_nid_revision PRIMARY KEY (nid,revision)

View File

@@ -0,0 +1,7 @@
ALTER TABLE nodes ADD editor INTEGER ;
UPDATE nodes SET editor = author;
ALTER TABLE node_revisions ADD editor INTEGER ;
UPDATE node_revisions SET editor = author;

View File

@@ -275,7 +275,11 @@ feature -- Hooks
if l_entity.is_published then if l_entity.is_published then
if l_entity.author = Void then if l_entity.author = Void then
-- FIXME!!! -- FIXME!!!
l_entity.set_author (l_page_api.cms_api.user) if attached l_entity.editor as l_editor then
l_entity.set_author (l_editor)
else
l_entity.set_author (l_page_api.cms_api.user)
end
a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" WARNING (Author is unknown!)") a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" WARNING (Author is unknown!)")
end end
if attached l_entity.author as l_author then if attached l_entity.author as l_author then

View File

@@ -72,13 +72,13 @@ feature -- Access
feature {NONE} -- Queries feature {NONE} -- Queries
sql_select_available_parents_for_node : STRING = "[ sql_select_available_parents_for_node : STRING = "[
SELECT node.nid, node.revision, node.type, title, summary, content, format, author, publish, created, changed, status SELECT node.nid, node.revision, node.type, title, summary, content, format, author, editor, publish, created, changed, status
FROM nodes node LEFT JOIN page_nodes pn ON node.nid = pn.nid AND node.nid != :nid FROM nodes node LEFT JOIN page_nodes pn ON node.nid = pn.nid AND node.nid != :nid
WHERE node.nid != :nid AND pn.parent != :nid AND node.status != -1 GROUP BY node.nid, node.revision; WHERE node.nid != :nid AND pn.parent != :nid AND node.status != -1 GROUP BY node.nid, node.revision;
]" ]"
sql_select_children_of_node: STRING = "[ sql_select_children_of_node: STRING = "[
SELECT node.nid, node.revision, node.type, title, summary, content, format, author, publish, created, changed, status SELECT node.nid, node.revision, node.type, title, summary, content, format, author, editor, publish, created, changed, status
FROM nodes node LEFT JOIN page_nodes pn ON node.nid = pn.nid FROM nodes node LEFT JOIN page_nodes pn ON node.nid = pn.nid
WHERE pn.parent = :nid AND node.status != -1 GROUP BY node.nid, node.revision; WHERE pn.parent = :nid AND node.status != -1 GROUP BY node.nid, node.revision;
]" ]"

View File

@@ -417,6 +417,55 @@ feature -- Internationalization (i18n)
Result.append_string_general (ago.smart_date_duration (dt)) Result.append_string_general (ago.smart_date_duration (dt))
end end
formatted_date_time_yyyy_mm_dd (dt: DATE_TIME): STRING_8
-- Output date `dt` using YYYY-MM-DD
local
i: INTEGER
do
create Result.make (10)
Result.append_integer (dt.year)
Result.append_character ('-')
i := dt.month
if i <= 9 then
Result.append_character ('0')
end
Result.append_integer (i)
Result.append_character ('-')
i := dt.day
if i <= 9 then
Result.append_character ('0')
end
Result.append_integer (i)
end
formatted_date_time_yyyy_mm_dd__hh_min_ss (dt: DATE_TIME): STRING_8
-- Output date `dt` using YYYY-MM-DD h:min:sec
local
i: INTEGER
do
create Result.make (19)
Result.append (formatted_date_time_yyyy_mm_dd (dt))
Result.append_character (' ')
i := dt.hour
if i <= 9 then
Result.append_character ('0')
end
Result.append_integer (i)
Result.append_character (':')
i := dt.minute
if i <= 9 then
Result.append_character ('0')
end
Result.append_integer (i)
Result.append_character (':')
i := dt.second
if i <= 9 then
Result.append_character ('0')
end
Result.append_integer (i)
end
feature -- Emails feature -- Emails
new_email (a_to_address: READABLE_STRING_8; a_subject: READABLE_STRING_8; a_content: READABLE_STRING_8): CMS_EMAIL new_email (a_to_address: READABLE_STRING_8; a_subject: READABLE_STRING_8; a_content: READABLE_STRING_8): CMS_EMAIL