diff --git a/modules/node/handler/node_form_response.e b/modules/node/handler/node_form_response.e index 4b68eca..0ce6d63 100644 --- a/modules/node/handler/node_form_response.e +++ b/modules/node/handler/node_form_response.e @@ -173,25 +173,29 @@ feature {NONE} -- Create a new node f: like new_edit_form fd: detachable WSF_FORM_DATA do - f := new_delete_form (a_node, url (location, Void), "delete-" + a_type.name, a_type) - hooks.invoke_form_alter (f, fd, Current) - if request.is_post_request_method then - f.process (Current) - fd := f.last_data - end - if a_node.has_id then - add_to_menu (node_local_link (a_node, translation ("View", Void)), primary_tabs) - add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), node_api.node_path (a_node) + "/edit"), primary_tabs) - add_to_menu (create {CMS_LOCAL_LINK}.make ("Delete", node_api.node_path (a_node) + "/delete"), primary_tabs) - end + if a_node.is_trashed then + f := new_delete_form (a_node, url (location, Void), "delete-" + a_type.name, a_type) + hooks.invoke_form_alter (f, fd, Current) + if request.is_post_request_method then + f.process (Current) + fd := f.last_data + end + if a_node.has_id then + add_to_menu (node_local_link (a_node, translation ("View", Void)), primary_tabs) + add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), node_api.node_path (a_node) + "/edit"), primary_tabs) + add_to_menu (create {CMS_LOCAL_LINK}.make ("Delete", node_api.node_path (a_node) + "/delete"), primary_tabs) + end - if attached redirection as l_location then - -- FIXME: Hack for now - set_title (a_node.title) - b.append (html_encoded (a_type.title) + " deleted") + if attached redirection as l_location then + -- FIXME: Hack for now + set_title (a_node.title) + b.append (html_encoded (a_type.title) + " deleted") + else + set_title (formatted_string (translation ("Delete $1 #$2", Void), [a_type.title, a_node.id])) + f.append_to_html (wsf_theme, b) + end else - set_title (formatted_string (translation ("Delete $1 #$2", Void), [a_type.title, a_node.id])) - f.append_to_html (wsf_theme, b) + -- end end @@ -355,6 +359,8 @@ feature -- Form new_delete_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_node_type: CMS_NODE_TYPE [CMS_NODE]): CMS_FORM -- Create a web form named `a_name' for node `a_node' (if set), using form action url `a_url', and for type of node `a_node_type'. + require + is_trashed: attached a_node as l_node and then a_node.is_trashed local f: CMS_FORM ts: WSF_FORM_SUBMIT_INPUT @@ -375,10 +381,27 @@ feature -- Form ts.set_default_value (translation ("Delete")) ]") f.extend (ts) - to_implement ("Refactor code to use the new wsf_html HTML5 support") - f.extend_html_text("" ) + create ts.make ("op") + ts.set_default_value ("Cancel") + ts.set_formaction ("/node/"+a_node.id.out) + ts.set_formmethod ("GET") + f.extend (ts) + end + f.extend_html_text ("
") + f.extend_html_text ("Do you want to restore the current node?") + if + a_node /= Void and then + a_node.id > 0 + then + create ts.make ("op") + ts.set_default_value ("Restore") + ts.set_formaction ("/node/"+a_node.id.out+"/delete") + ts.set_formmethod ("POST") + fixme ("[ + ts.set_default_value (translation ("Restore")) + ]") + f.extend (ts) end - Result := f end @@ -404,19 +427,6 @@ feature -- Form ]") f.extend (ts) end - f.extend_html_text ("
") - f.extend_html_text ("Do you want to restore the current node?") - if - a_node /= Void and then - a_node.id > 0 - then - create ts.make ("op") - ts.set_default_value ("Restore") - fixme ("[ - ts.set_default_value (translation ("Restore")) - ]") - f.extend (ts) - end Result := f end diff --git a/modules/node/handler/node_handler.e b/modules/node/handler/node_handler.e index 734cda8..516aef2 100644 --- a/modules/node/handler/node_handler.e +++ b/modules/node/handler/node_handler.e @@ -173,6 +173,11 @@ feature -- HTTP Methods l_op.value.same_string ("Delete") then do_delete (req, res) + elseif + attached {WSF_STRING} req.form_parameter ("op") as l_op and then + l_op.value.same_string ("Restore") + then + do_restore (req, res) end elseif req.percent_encoded_path_info.ends_with ("/trash") then if @@ -180,11 +185,6 @@ feature -- HTTP Methods l_op.value.same_string ("Trash") then do_trash (req, res) - elseif - attached {WSF_STRING} req.form_parameter ("op") as l_op and then - l_op.value.same_string ("Restore") - then - do_restore (req, res) end elseif req.percent_encoded_path_info.starts_with ("/node/add/") then create edit_response.make (req, res, api, node_api) @@ -242,15 +242,19 @@ feature {NONE} -- Trash:Restore do_delete (req: WSF_REQUEST; res: WSF_RESPONSE) -- Delete a node from the database. + local + l_source: STRING do if attached current_user (req) as l_user then if attached {WSF_STRING} req.path_parameter ("id") as l_id then if l_id.is_integer and then - attached node_api.node (l_id.integer_value) as l_node + attached {CMS_NODE} node_api.node (l_id.integer_value) as l_node then if node_api.has_permission_for_action_on_node ("delete", l_node, current_user (req)) then node_api.delete_node (l_node) + l_source := node_api.node_path (l_node) + api.unset_path_alias (l_source, api.location_alias (l_source)) res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url (""))) else send_access_denied (req, res) diff --git a/modules/node/persistence/cms_node_storage_sql.e b/modules/node/persistence/cms_node_storage_sql.e index 72ffff8..897d5e5 100644 --- a/modules/node/persistence/cms_node_storage_sql.e +++ b/modules/node/persistence/cms_node_storage_sql.e @@ -383,7 +383,9 @@ feature -- Change: Node local l_parameters: STRING_TABLE [ANY] l_time: DATE_TIME + l_sql_delete_node_aliases: STRING do + sql_begin_transaction create l_time.make_now_utc write_information_log (generator + ".delete_node_base {" + a_node.id.out + "}") @@ -400,6 +402,9 @@ feature -- Change: Node if not error_handler.has_error then extended_delete (a_node) + sql_commit_transaction + else + sql_rollback_transaction end end @@ -415,9 +420,9 @@ feature -- Change: Node error_handler.reset create l_parameters.make (1) l_parameters.put (l_time, "changed") - l_parameters.put ({CMS_NODE_API}.not_published, "status") + l_parameters.put ({CMS_NODE_API}.published, "status") l_parameters.put (a_id, "nid") - sql_modify (sql_restore_node, l_parameters) + sql_modify (sql_update_node_status, l_parameters) sql_finalize end @@ -560,8 +565,8 @@ feature {NONE} -- Queries sql_delete_node: STRING = "DELETE FROM nodes WHERE nid=:nid" -- Physical deletion with free metadata. - sql_restore_node: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid" - -- Restore node to {CMS_NODE_API}.not_publised. + sql_update_node_status: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid" + -- Restore node to {CMS_NODE_API}.published sql_last_insert_node_id: STRING = "SELECT MAX(nid) FROM nodes;" @@ -584,6 +589,7 @@ feature {NONE} -- Queries sql_delete_node_revisions: STRING = "DELETE FROM node_revisions WHERE nid=:nid;" + feature {NONE} -- Sql Queries: USER_ROLES collaborators, author Select_user_author: STRING = "SELECT uid, name, password, salt, email, users.status, users.created, signed FROM nodes INNER JOIN users ON nodes.author=users.uid AND nodes.nid = :nid AND nodes.revision = :revision;"