diff --git a/library/persistence/implementation/mysql/src/cms_storage_mysql.e b/library/persistence/implementation/mysql/src/cms_storage_mysql.e index d78db04..feaafae 100644 --- a/library/persistence/implementation/mysql/src/cms_storage_mysql.e +++ b/library/persistence/implementation/mysql/src/cms_storage_mysql.e @@ -32,6 +32,7 @@ feature {NONE} -- Initialization create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) create error_handler.make +-- error_handler.add_synchronization (db_handler.database_error_handler) end db_handler: DATABASE_HANDLER @@ -44,7 +45,7 @@ feature -- Query sql_post_execution -- Post database execution. do --- error_handler.add_synchronization (db_handler.database_error_handler) + error_handler.append (db_handler.database_error_handler) if error_handler.has_error then log.write_critical (generator + ".post_execution " + error_handler.as_string_representation) end diff --git a/library/persistence/implementation/mysql/tests/tests.ecf b/library/persistence/implementation/mysql/tests/tests.ecf index c526aeb..6a3ccf2 100644 --- a/library/persistence/implementation/mysql/tests/tests.ecf +++ b/library/persistence/implementation/mysql/tests/tests.ecf @@ -7,6 +7,7 @@ + diff --git a/library/persistence/implementation/sqlite/src/cms_storage_sqlite.e b/library/persistence/implementation/sqlite/src/cms_storage_sqlite.e index 1dacee9..74fc099 100644 --- a/library/persistence/implementation/sqlite/src/cms_storage_sqlite.e +++ b/library/persistence/implementation/sqlite/src/cms_storage_sqlite.e @@ -31,6 +31,7 @@ feature {NONE} -- Initialization create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) create error_handler.make +-- error_handler.add_synchronization (db_handler.database_error_handler) end db_handler: DATABASE_HANDLER @@ -43,7 +44,7 @@ feature -- Access: user sql_post_execution -- Post database execution. do --- error_handler.add_synchronization (db_handler.database_error_handler) + error_handler.append (db_handler.database_error_handler) if error_handler.has_error then log.write_critical (generator + ".post_execution " + error_handler.as_string_representation) end diff --git a/library/src/modules/node/handler/node_content_handler.e b/library/src/modules/node/handler/node_content_handler.e index 9355765..17f0c0d 100644 --- a/library/src/modules/node/handler/node_content_handler.e +++ b/library/src/modules/node/handler/node_content_handler.e @@ -120,7 +120,7 @@ feature -- HTTP Methods if attached {WSF_STRING} req.path_parameter ("id") as l_id then if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then u_node := extract_data_form (req) - u_node.set_id (l_id.integer_value) + u_node.set_id (l_id.value.to_integer_64) api.update_node_content (l_user.id, u_node.id, u_node.content) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) else diff --git a/library/src/modules/node/handler/node_handler.e b/library/src/modules/node/handler/node_handler.e index 0e42283..715fbb3 100644 --- a/library/src/modules/node/handler/node_handler.e +++ b/library/src/modules/node/handler/node_handler.e @@ -124,7 +124,7 @@ feature -- HTTP Methods if attached {WSF_STRING} req.path_parameter ("id") as l_id then if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then u_node := extract_data_form (req) - u_node.set_id (l_id.integer_value) + u_node.set_id (l_id.value.to_integer_64) api.update_node (l_user.id,u_node) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) else diff --git a/library/src/modules/node/handler/node_summary_handler.e b/library/src/modules/node/handler/node_summary_handler.e index 8846379..11cd43a 100644 --- a/library/src/modules/node/handler/node_summary_handler.e +++ b/library/src/modules/node/handler/node_summary_handler.e @@ -118,7 +118,7 @@ feature -- HTTP Methods if attached {WSF_STRING} req.path_parameter ("id") as l_id then if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then u_node := extract_data_form (req) - u_node.set_id (l_id.integer_value) + u_node.set_id (l_id.value.to_integer_64) api.update_node_summary (l_user.id,u_node.id, u_node.summary) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) else diff --git a/library/src/modules/node/handler/node_title_handler.e b/library/src/modules/node/handler/node_title_handler.e index cab8841..a3dbaa8 100644 --- a/library/src/modules/node/handler/node_title_handler.e +++ b/library/src/modules/node/handler/node_title_handler.e @@ -118,7 +118,7 @@ feature -- HTTP Methods if attached {WSF_STRING} req.path_parameter ("id") as l_id then if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then u_node := extract_data_form (req) - u_node.set_id (l_id.integer_value) + u_node.set_id (l_id.value.to_integer_64) api.update_node_title (l_user.id,u_node.id, u_node.title) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) else diff --git a/library/src/modules/node/node_module.e b/library/src/modules/node/node_module.e index 3e85a4d..a1b3c4c 100644 --- a/library/src/modules/node/node_module.e +++ b/library/src/modules/node/node_module.e @@ -159,10 +159,22 @@ feature -- Handler local r: CMS_RESPONSE s: STRING + l_user: CMS_USER + l_node: CMS_NODE do create {NOT_IMPLEMENTED_ERROR_CMS_RESPONSE} r.make (req, res, a_api) - a_api.new_node (create {CMS_NODE}.make ("This is a body", "summary this node", "Oh a node")) + if attached a_api.user_by_name ("foo") as u then + l_user := u + else + create l_user.make ("foo") + l_user.set_password ("foobar#") + l_user.set_email ("jfiat@eiffel.com") + a_api.new_user (l_user) + end + create l_node.make ({STRING_32} "This is a content", {STRING_32} "And a summary", {STRING_32} "Nice title") + l_node.set_author (l_user) + a_api.new_node (l_node) create s.make_from_string ("

Sorry: listing the CMS nodes is not yet implemented.

") if attached a_api.nodes as lst then diff --git a/library/src/persistence/cms_storage_sql.e b/library/src/persistence/cms_storage_sql.e index c9e9372..b0266f1 100644 --- a/library/src/persistence/cms_storage_sql.e +++ b/library/src/persistence/cms_storage_sql.e @@ -95,7 +95,7 @@ feature -- Access l_item: like sql_item do l_item := sql_item (a_index) - if attached {READABLE_STRING_32} l_item as l_string then + if attached {READABLE_STRING_8} l_item as l_string then Result := l_string elseif attached {BOOLEAN} l_item as l_boolean then Result := l_boolean.out diff --git a/library/src/persistence/node/cms_node_storage_sql.e b/library/src/persistence/node/cms_node_storage_sql.e index 52f5268..c87fa78 100644 --- a/library/src/persistence/node/cms_node_storage_sql.e +++ b/library/src/persistence/node/cms_node_storage_sql.e @@ -111,14 +111,14 @@ feature -- Access sql_post_execution end - last_inserted_node_id: INTEGER + last_inserted_node_id: INTEGER_64 -- Last insert node id. do error_handler.reset log.write_information (generator + ".last_inserted_node_id") sql_query (Sql_last_insert_node_id, Void) if sql_rows_count = 1 then - Result := sql_read_integer_32 (1) + Result := sql_read_integer_64 (1) end sql_post_execution end @@ -133,6 +133,7 @@ feature -- Change: Node if a_node.has_id and attached a_node.author as l_author and then l_author.has_id then update_node (l_author.id, a_node) else + -- New node error_handler.reset log.write_information (generator + ".save_node") create l_parameters.make (7) @@ -151,8 +152,11 @@ feature -- Change: Node l_parameters.put (0, "author_id") end sql_change (sql_insert_node, l_parameters) - a_node.set_id (last_inserted_node_id) sql_post_execution + if not error_handler.has_error then + a_node.set_id (last_inserted_node_id) + sql_post_execution + end end end @@ -298,7 +302,7 @@ feature {NONE} -- Implementation fetch_node: CMS_NODE do create Result.make ("", "", "") - if attached sql_read_integer_32 (1) as l_id then + if attached sql_read_integer_64 (1) as l_id then Result.set_id (l_id) end if attached sql_read_date_time (2) as l_publication_date then diff --git a/library/src/persistence/user/cms_user_storage_sql.e b/library/src/persistence/user/cms_user_storage_sql.e index b0ab971..a00d978 100644 --- a/library/src/persistence/user/cms_user_storage_sql.e +++ b/library/src/persistence/user/cms_user_storage_sql.e @@ -195,6 +195,8 @@ feature {NONE} -- Implementation new_user (a_user: CMS_USER) -- Add a new user `a_user'. + require + no_id: not a_user.has_id local l_parameters: STRING_TABLE [detachable ANY] l_password_salt, l_password_hash: STRING @@ -217,6 +219,11 @@ feature {NONE} -- Implementation l_parameters.put (l_email, "email") sql_change (sql_insert_user, l_parameters) + sql_post_execution + if not error_handler.has_error then + a_user.set_id (last_inserted_user_id) + sql_post_execution + end else -- set error error_handler.add_custom_error (-1, "bad request" , "Missing password or email") @@ -258,11 +265,25 @@ feature {NONE} -- Implementation end end + last_inserted_user_id: INTEGER_64 + -- Last insert user id. + do + error_handler.reset + log.write_information (generator + ".last_inserted_user_id") + sql_query (Sql_last_insert_user_id, Void) + if sql_rows_count = 1 then + Result := sql_read_integer_64 (1) + end + sql_post_execution + end + feature {NONE} -- Sql Queries: USER Select_users_count: STRING = "select count(*) from Users;" -- Number of users. + Sql_last_insert_user_id: STRING = "SELECT MAX(id) from Users;" + Select_users: STRING = "select * from Users;" -- List of users. @@ -279,7 +300,7 @@ feature {NONE} -- Sql Queries: USER -- Retrieve salt by username if exists. SQL_Insert_user: STRING = "insert into users (username, password, salt, email) values (:username, :password, :salt, :email);" - -- SQL Insert to add a new node. + -- SQL Insert to add a new node. end