When importing, do not change modification date.
Display /nodes sorted by changed date. Improved the import form, and report wrong import folder. Only import from folder inside site/import for security reason.
This commit is contained in:
@@ -9,6 +9,9 @@ ul.cms-nodes li {
|
|||||||
ul.cms-nodes li:first-child {
|
ul.cms-nodes li:first-child {
|
||||||
border-top: none;
|
border-top: none;
|
||||||
}
|
}
|
||||||
|
ul.cms-nodes li span.author, ul.cms-nodes li span.info {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
ul.cms-nodes li.cms_type_page a::before {
|
ul.cms-nodes li.cms_type_page a::before {
|
||||||
content: "[page] ";
|
content: "[page] ";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ ul.cms-nodes {
|
|||||||
&:first-child {
|
&:first-child {
|
||||||
border-top: none;
|
border-top: none;
|
||||||
}
|
}
|
||||||
|
span.author, span.info {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
li.cms_type_page a::before {
|
li.cms_type_page a::before {
|
||||||
content: "[page] ";
|
content: "[page] ";
|
||||||
|
|||||||
@@ -67,25 +67,26 @@ feature -- Execution
|
|||||||
if attached fd.string_item ("op") as l_op and then l_op.same_string (text_import_all_data) then
|
if attached fd.string_item ("op") as l_op and then l_op.same_string (text_import_all_data) then
|
||||||
if attached fd.string_item ("folder") as l_folder then
|
if attached fd.string_item ("folder") as l_folder then
|
||||||
create p.make_from_string (l_folder)
|
create p.make_from_string (l_folder)
|
||||||
if p.is_absolute then
|
create l_importation.make (api.site_location.extended (import_folder_name).extended (l_folder))
|
||||||
create l_importation.make (p)
|
if l_importation.location_exists then
|
||||||
|
l_response.add_notice_message ("Import all data (if permitted)!")
|
||||||
|
api.hooks.invoke_import_from (Void, l_importation, l_response)
|
||||||
|
create s.make_empty
|
||||||
|
across
|
||||||
|
l_importation.logs as ic
|
||||||
|
loop
|
||||||
|
s.append (ic.item)
|
||||||
|
s.append ("<br/>")
|
||||||
|
s.append_character ('%N')
|
||||||
|
end
|
||||||
|
l_response.add_notice_message (s)
|
||||||
else
|
else
|
||||||
create l_importation.make (api.site_location.extended ("import").extended (l_folder))
|
l_response.add_error_message ("Specified import folder is not found!")
|
||||||
|
fd.report_invalid_field ("folder", "Folder not found!")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
create l_importation.make (api.site_location.extended ("import").extended ("default"))
|
fd.report_error ("Invalid form data!")
|
||||||
end
|
end
|
||||||
api.hooks.invoke_import_from (Void, l_importation, l_response)
|
|
||||||
l_response.add_notice_message ("All data imported (if allowed)!")
|
|
||||||
create s.make_empty
|
|
||||||
across
|
|
||||||
l_importation.logs as ic
|
|
||||||
loop
|
|
||||||
s.append (ic.item)
|
|
||||||
s.append ("<br/>")
|
|
||||||
s.append_character ('%N')
|
|
||||||
end
|
|
||||||
l_response.add_notice_message (s)
|
|
||||||
else
|
else
|
||||||
fd.report_error ("Invalid form data!")
|
fd.report_error ("Invalid form data!")
|
||||||
end
|
end
|
||||||
@@ -107,7 +108,7 @@ feature -- Widget
|
|||||||
Result.extend_raw_text ("Import CMS data from ")
|
Result.extend_raw_text ("Import CMS data from ")
|
||||||
create f_name.make_with_text ("folder", "default")
|
create f_name.make_with_text ("folder", "default")
|
||||||
f_name.set_label ("Import folder name")
|
f_name.set_label ("Import folder name")
|
||||||
f_name.set_description ("Folder name under 'imports' folder.")
|
f_name.set_description ("Folder name under '" + a_response.html_encoded (import_folder_name) + "' folder.")
|
||||||
f_name.set_is_required (True)
|
f_name.set_is_required (True)
|
||||||
Result.extend (f_name)
|
Result.extend (f_name)
|
||||||
create but.make_with_text ("op", text_import_all_data)
|
create but.make_with_text ("op", text_import_all_data)
|
||||||
@@ -116,6 +117,8 @@ feature -- Widget
|
|||||||
|
|
||||||
feature -- Interface text.
|
feature -- Interface text.
|
||||||
|
|
||||||
|
import_folder_name: STRING_32 = "import"
|
||||||
|
|
||||||
text_import_all_data: STRING_32 = "Import all data"
|
text_import_all_data: STRING_32 = "Import all data"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -126,6 +126,12 @@ feature -- Commit
|
|||||||
node_api.save_node (a_blog)
|
node_api.save_node (a_blog)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
import_blog (a_blog: CMS_BLOG)
|
||||||
|
-- Same as `save_blog` but keep modification_date unchanged.
|
||||||
|
do
|
||||||
|
node_api.import_node (a_blog)
|
||||||
|
end
|
||||||
|
|
||||||
feature {NONE} -- Helpers
|
feature {NONE} -- Helpers
|
||||||
|
|
||||||
nodes_to_blogs (a_nodes: LIST [CMS_NODE]): ARRAYED_LIST [CMS_BLOG]
|
nodes_to_blogs (a_nodes: LIST [CMS_NODE]): ARRAYED_LIST [CMS_BLOG]
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ feature -- Hooks
|
|||||||
a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" skipped (already exists for user #" + l_author.id.out + ")!")
|
a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" skipped (already exists for user #" + l_author.id.out + ")!")
|
||||||
else
|
else
|
||||||
a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" imported for user #" + l_author.id.out + ".")
|
a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" imported for user #" + l_author.id.out + ".")
|
||||||
l_blog_api.save_blog (l_entity)
|
l_blog_api.import_blog (l_entity)
|
||||||
apply_taxonomy_to_node (j, l_entity, l_blog_api.cms_api)
|
apply_taxonomy_to_node (j, l_entity, l_blog_api.cms_api)
|
||||||
if attached {CMS_LOCAL_LINK} l_entity.link as l_link then
|
if attached {CMS_LOCAL_LINK} l_entity.link as l_link then
|
||||||
loc := l_node_api.node_path (l_entity)
|
loc := l_node_api.node_path (l_entity)
|
||||||
@@ -315,6 +315,8 @@ feature -- Hooks
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
a_import_ctx.log ("Importing [" + l_node_type.name + "] NOT ALLOWED!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -299,6 +299,18 @@ feature -- Change: Node
|
|||||||
|
|
||||||
save_node (a_node: CMS_NODE)
|
save_node (a_node: CMS_NODE)
|
||||||
-- Save `a_node'.
|
-- Save `a_node'.
|
||||||
|
local
|
||||||
|
now: DATE_TIME
|
||||||
|
do
|
||||||
|
reset_error
|
||||||
|
create now.make_now_utc
|
||||||
|
a_node.set_modification_date (now)
|
||||||
|
node_storage.save_node (a_node)
|
||||||
|
error_handler.append (node_storage.error_handler)
|
||||||
|
end
|
||||||
|
|
||||||
|
import_node (a_node: CMS_NODE)
|
||||||
|
-- Same as `save_node` but keep modification_date unchanged.
|
||||||
do
|
do
|
||||||
reset_error
|
reset_error
|
||||||
node_storage.save_node (a_node)
|
node_storage.save_node (a_node)
|
||||||
@@ -326,14 +338,6 @@ feature -- Change: Node
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node (a_node: CMS_NODE)
|
|
||||||
-- Update node `a_node' data.
|
|
||||||
do
|
|
||||||
reset_error
|
|
||||||
node_storage.update_node (a_node)
|
|
||||||
error_handler.append (node_storage.error_handler)
|
|
||||||
end
|
|
||||||
|
|
||||||
trash_node (a_node: CMS_NODE)
|
trash_node (a_node: CMS_NODE)
|
||||||
-- Trash node `a_node'.
|
-- Trash node `a_node'.
|
||||||
-- Soft delete
|
-- Soft delete
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ feature{NONE} -- Initialization
|
|||||||
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
|
||||||
l_time: DATE_TIME
|
now: DATE_TIME
|
||||||
do
|
do
|
||||||
create l_time.make_now_utc
|
create now.make_now_utc
|
||||||
set_title (a_title)
|
set_title (a_title)
|
||||||
set_creation_date (l_time)
|
set_creation_date (now)
|
||||||
set_modification_date (l_time)
|
set_modification_date (now)
|
||||||
set_publication_date (l_time)
|
set_publication_date (now)
|
||||||
mark_not_published
|
mark_not_published
|
||||||
ensure
|
ensure
|
||||||
title_set: title = a_title
|
title_set: title = a_title
|
||||||
|
|||||||
@@ -91,10 +91,13 @@ feature -- HTTP Methods
|
|||||||
s.append ("%">")
|
s.append ("%">")
|
||||||
s.append (l_response.link (lnk.title, lnk.location, Void))
|
s.append (l_response.link (lnk.title, lnk.location, Void))
|
||||||
if not n.is_published then
|
if not n.is_published then
|
||||||
s.append (" <em>(not-published)</em>")
|
s.append (" <span class=%"info%">(not-published)</span>")
|
||||||
elseif n.is_trashed then
|
elseif n.is_trashed then
|
||||||
s.append (" <em>(trashed)</em>")
|
s.append (" <span class=%"info%">(trashed)</span>")
|
||||||
end
|
end
|
||||||
|
s.append (" <span class=%"info%"> ("+ api.formatted_date_time_ago (n.modification_date) +")</span>")
|
||||||
|
s.append (" <span class=%"info%"> #"+ n.id.out +"</span>")
|
||||||
|
|
||||||
debug
|
debug
|
||||||
if attached node_api.node_type (n.content_type) as ct then
|
if attached node_api.node_type (n.content_type) as ct then
|
||||||
s.append ("<span class=%"description%">")
|
s.append ("<span class=%"description%">")
|
||||||
|
|||||||
@@ -340,10 +340,8 @@ feature -- Change: Node
|
|||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [ANY]
|
l_parameters: STRING_TABLE [ANY]
|
||||||
l_time: DATE_TIME
|
|
||||||
do
|
do
|
||||||
sql_begin_transaction
|
sql_begin_transaction
|
||||||
create l_time.make_now_utc
|
|
||||||
write_information_log (generator + ".delete_node_base {" + a_node.id.out + "}")
|
write_information_log (generator + ".delete_node_base {" + a_node.id.out + "}")
|
||||||
|
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
@@ -391,9 +389,7 @@ feature {NONE} -- Implementation
|
|||||||
l_copy_parameters: STRING_TABLE [detachable ANY]
|
l_copy_parameters: STRING_TABLE [detachable ANY]
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
l_rev: like last_inserted_node_revision
|
l_rev: like last_inserted_node_revision
|
||||||
now: DATE_TIME
|
|
||||||
do
|
do
|
||||||
create now.make_now_utc
|
|
||||||
error_handler.reset
|
error_handler.reset
|
||||||
|
|
||||||
write_information_log (generator + ".store_node")
|
write_information_log (generator + ".store_node")
|
||||||
@@ -404,7 +400,7 @@ feature {NONE} -- Implementation
|
|||||||
l_parameters.put (a_node.content, "content")
|
l_parameters.put (a_node.content, "content")
|
||||||
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 (a_node.modification_date, "changed")
|
||||||
l_parameters.put (a_node.status, "status")
|
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
|
||||||
@@ -436,10 +432,6 @@ feature {NONE} -- Implementation
|
|||||||
l_parameters.put (a_node.revision, "revision")
|
l_parameters.put (a_node.revision, "revision")
|
||||||
sql_modify (sql_update_node, l_parameters)
|
sql_modify (sql_update_node, l_parameters)
|
||||||
sql_finalize
|
sql_finalize
|
||||||
|
|
||||||
if not error_handler.has_error then
|
|
||||||
a_node.set_modification_date (now)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Store new node
|
-- Store new node
|
||||||
@@ -450,7 +442,6 @@ feature {NONE} -- Implementation
|
|||||||
sql_finalize
|
sql_finalize
|
||||||
|
|
||||||
if not error_handler.has_error then
|
if not error_handler.has_error then
|
||||||
a_node.set_modification_date (now)
|
|
||||||
a_node.set_id (last_inserted_node_id)
|
a_node.set_id (last_inserted_node_id)
|
||||||
a_node.set_revision (l_rev) -- New object.
|
a_node.set_revision (l_rev) -- New object.
|
||||||
-- check a_node.revision = last_inserted_node_revision (a_node) end
|
-- check a_node.revision = last_inserted_node_revision (a_node) end
|
||||||
@@ -510,7 +501,7 @@ feature {NONE} -- Queries
|
|||||||
|
|
||||||
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_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 = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes ORDER BY nid DESC, publish DESC LIMIT :size OFFSET :offset ;"
|
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_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 ;"
|
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 ;"
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ ul.cms-nodes li {
|
|||||||
ul.cms-nodes li:first-child {
|
ul.cms-nodes li:first-child {
|
||||||
border-top: none;
|
border-top: none;
|
||||||
}
|
}
|
||||||
|
ul.cms-nodes li span.author, ul.cms-nodes li span.info {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
ul.cms-nodes li.cms_type_page a::before {
|
ul.cms-nodes li.cms_type_page a::before {
|
||||||
content: "[page] ";
|
content: "[page] ";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ ul.cms-nodes {
|
|||||||
&:first-child {
|
&:first-child {
|
||||||
border-top: none;
|
border-top: none;
|
||||||
}
|
}
|
||||||
|
span.author, span.info {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
li.cms_type_page a::before {
|
li.cms_type_page a::before {
|
||||||
content: "[page] ";
|
content: "[page] ";
|
||||||
|
|||||||
@@ -147,6 +147,12 @@ feature -- Commit
|
|||||||
node_api.save_node (a_page)
|
node_api.save_node (a_page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
import_page (a_page: CMS_PAGE)
|
||||||
|
-- Save `a_page` without changing the modification date.
|
||||||
|
do
|
||||||
|
node_api.import_node (a_page)
|
||||||
|
end
|
||||||
|
|
||||||
feature {CMS_MODULE} -- Access nodes storage.
|
feature {CMS_MODULE} -- Access nodes storage.
|
||||||
|
|
||||||
page_storage: CMS_PAGE_STORAGE_I
|
page_storage: CMS_PAGE_STORAGE_I
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ feature -- Hooks
|
|||||||
l_parentable_list.extend ([l_entity, l_parent])
|
l_parentable_list.extend ([l_entity, l_parent])
|
||||||
l_entity.set_parent (Void)
|
l_entity.set_parent (Void)
|
||||||
end
|
end
|
||||||
l_page_api.save_page (l_entity)
|
l_page_api.import_page (l_entity)
|
||||||
apply_taxonomy_to_node (j, l_entity, l_page_api.cms_api)
|
apply_taxonomy_to_node (j, l_entity, l_page_api.cms_api)
|
||||||
l_new_pages.force (l_entity, l_node_api.node_path (l_entity))
|
l_new_pages.force (l_entity, l_node_api.node_path (l_entity))
|
||||||
a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" imported as "+ l_entity.id.out +" for user #" + l_author.id.out + ".")
|
a_import_ctx.log (l_node_type.name + " %"" + fp.utf_8_name + "%" imported as "+ l_entity.id.out +" for user #" + l_author.id.out + ".")
|
||||||
@@ -329,12 +329,14 @@ feature -- Hooks
|
|||||||
update_page_parent (l_entity, ic.item.parent, l_new_pages)
|
update_page_parent (l_entity, ic.item.parent, l_new_pages)
|
||||||
if attached l_entity.parent as l_parent then
|
if attached l_entity.parent as l_parent then
|
||||||
a_import_ctx.log (l_node_type.name + " #" + l_entity.id.out + " assigned to parent #" + l_parent.id.out)
|
a_import_ctx.log (l_node_type.name + " #" + l_entity.id.out + " assigned to parent #" + l_parent.id.out)
|
||||||
l_page_api.save_page (l_entity)
|
l_page_api.import_page (l_entity)
|
||||||
else
|
else
|
||||||
a_import_ctx.log (l_node_type.name + " #" + l_entity.id.out + " : unable to find parent!")
|
a_import_ctx.log (l_node_type.name + " #" + l_entity.id.out + " : unable to find parent!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
a_import_ctx.log ("Importing [" + l_node_type.name + "] NOT ALLOWED!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
make (a_location: PATH)
|
make (a_location: PATH)
|
||||||
do
|
do
|
||||||
location := a_location
|
location := a_location.absolute_path.canonical_path
|
||||||
create logs.make (10)
|
create logs.make (10)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -24,6 +24,14 @@ feature -- Access
|
|||||||
location: PATH
|
location: PATH
|
||||||
-- Location of import folder.
|
-- Location of import folder.
|
||||||
|
|
||||||
|
location_exists: BOOLEAN
|
||||||
|
-- Does location of import folder exist?
|
||||||
|
local
|
||||||
|
ut: FILE_UTILITIES
|
||||||
|
do
|
||||||
|
Result := ut.directory_path_exists (location)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Logs
|
feature -- Logs
|
||||||
|
|
||||||
logs: ARRAYED_LIST [READABLE_STRING_8]
|
logs: ARRAYED_LIST [READABLE_STRING_8]
|
||||||
|
|||||||
@@ -336,6 +336,16 @@ feature -- Internationalization (i18n)
|
|||||||
Result := l_formatter.formatted_string (a_text, args)
|
Result := l_formatter.formatted_string (a_text, args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
formatted_date_time_ago (dt: DATE_TIME): STRING_32
|
||||||
|
-- Output date `dt` using time ago duration.
|
||||||
|
local
|
||||||
|
ago: DATE_TIME_AGO_CONVERTER
|
||||||
|
do
|
||||||
|
create ago.make
|
||||||
|
create Result.make (10)
|
||||||
|
Result.append_string_general (ago.smart_date_duration (dt))
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user