Use module site files system for the (un)install SQL scripts.
Changed CMS_TERM.id type to INTEGER_64 . Removed CMS_TERM.parent_id . Implemented CMS_TERM saving.
This commit is contained in:
@@ -53,30 +53,12 @@ feature {CMS_API} -- Module Initialization
|
||||
feature {CMS_API} -- Module management
|
||||
|
||||
install (api: CMS_API)
|
||||
local
|
||||
sql: STRING
|
||||
do
|
||||
-- Schema
|
||||
if attached {CMS_STORAGE_SQL_I} api.storage as l_sql_storage then
|
||||
if not l_sql_storage.sql_table_exists ("taxonomy_term") then
|
||||
sql := "[
|
||||
CREATE TABLE taxonomy_term (
|
||||
`tid` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT UNIQUE,
|
||||
`text` VARCHAR(255) NOT NULL,
|
||||
`weight` INTEGER,
|
||||
`description` TEXT,
|
||||
`langcode` VARCHAR(12)
|
||||
);
|
||||
CREATE TABLE taxonomy_hierarchy (
|
||||
`tid` INTEGER NOT NULL,
|
||||
`parent` INTEGER,
|
||||
CONSTRAINT PK_tid_parent PRIMARY KEY (tid,parent)
|
||||
);
|
||||
]"
|
||||
l_sql_storage.sql_execute_script (sql, Void)
|
||||
if l_sql_storage.has_error then
|
||||
api.logger.put_error ("Could not initialize database for taxonomy module", generating_type)
|
||||
end
|
||||
l_sql_storage.sql_execute_file_script (api.module_resource_location (Current, (create {PATH}.make_from_string ("scripts")).extended ("install").appended_with_extension ("sql")), Void)
|
||||
if l_sql_storage.has_error then
|
||||
api.logger.put_error ("Could not install database for taxonomy module", generating_type)
|
||||
end
|
||||
Precursor (api)
|
||||
end
|
||||
@@ -84,15 +66,9 @@ CREATE TABLE taxonomy_hierarchy (
|
||||
|
||||
uninstall (api: CMS_API)
|
||||
-- (export status {CMS_API})
|
||||
local
|
||||
sql: STRING
|
||||
do
|
||||
if attached {CMS_STORAGE_SQL_I} api.storage as l_sql_storage then
|
||||
sql := "[
|
||||
DROP TABLE IF EXISTS taxonomy_term;
|
||||
DROP TABLE IF EXISTS taxonomy_hierarchy;
|
||||
]"
|
||||
l_sql_storage.sql_execute_script (sql, Void)
|
||||
l_sql_storage.sql_execute_file_script (api.module_resource_location (Current, (create {PATH}.make_from_string ("scripts")).extended ("uninstall").appended_with_extension ("sql")), Void)
|
||||
if l_sql_storage.has_error then
|
||||
api.logger.put_error ("Could not remove database for taxonomy module", generating_type)
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_id: INTEGER; a_text: READABLE_STRING_GENERAL)
|
||||
make (a_id: INTEGER_64; a_text: READABLE_STRING_GENERAL)
|
||||
do
|
||||
id := a_id
|
||||
set_text (a_text)
|
||||
@@ -24,7 +24,7 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Access
|
||||
|
||||
id: INTEGER
|
||||
id: INTEGER_64
|
||||
-- Associated term id.
|
||||
|
||||
text: IMMUTABLE_STRING_32
|
||||
@@ -33,9 +33,6 @@ feature -- Access
|
||||
description: detachable IMMUTABLE_STRING_32
|
||||
-- Optional description.
|
||||
|
||||
parent_id: INTEGER
|
||||
-- Optional parent term id.
|
||||
|
||||
weight: INTEGER
|
||||
-- Associated weight for ordering.
|
||||
|
||||
@@ -65,7 +62,7 @@ feature -- Comparison
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_id (a_id: INTEGER)
|
||||
set_id (a_id: INTEGER_64)
|
||||
do
|
||||
id := a_id
|
||||
end
|
||||
@@ -85,15 +82,5 @@ feature -- Element change
|
||||
create description.make_from_string_general (a_description)
|
||||
end
|
||||
|
||||
set_parent (a_parent: CMS_TERM)
|
||||
do
|
||||
parent_id := a_parent.id
|
||||
end
|
||||
|
||||
set_parent_id (a_parent_id: INTEGER)
|
||||
do
|
||||
parent_id := a_parent_id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_tid: INTEGER; a_name: READABLE_STRING_GENERAL)
|
||||
make (a_tid: INTEGER_64; a_name: READABLE_STRING_GENERAL)
|
||||
do
|
||||
id := a_tid
|
||||
set_name (a_name)
|
||||
@@ -29,7 +29,7 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Access
|
||||
|
||||
id: INTEGER
|
||||
id: INTEGER_64
|
||||
|
||||
name: IMMUTABLE_STRING_32
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ feature -- Access
|
||||
deferred
|
||||
end
|
||||
|
||||
vocabulary (a_id: INTEGER): detachable CMS_VOCABULARY
|
||||
vocabulary (a_id: INTEGER_64): detachable CMS_VOCABULARY
|
||||
-- Vocabulary by id `a_id'.
|
||||
require
|
||||
valid_id: a_id > 0
|
||||
@@ -39,7 +39,7 @@ feature -- Access
|
||||
deferred
|
||||
end
|
||||
|
||||
term_by_id (tid: INTEGER): detachable CMS_TERM
|
||||
term_by_id (tid: INTEGER_64): detachable CMS_TERM
|
||||
-- Term associated with id `tid'.
|
||||
deferred
|
||||
ensure
|
||||
@@ -60,5 +60,13 @@ feature -- Access
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Store
|
||||
|
||||
save_term (t: CMS_TERM)
|
||||
-- Insert or update term `t'.
|
||||
deferred
|
||||
ensure
|
||||
not error_handler.has_error implies t.has_id and then term_by_id (t.id) /= Void
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -43,7 +43,7 @@ feature -- Access
|
||||
create {ARRAYED_LIST [CMS_VOCABULARY]} Result.make (0)
|
||||
end
|
||||
|
||||
vocabulary (a_id: INTEGER): detachable CMS_VOCABULARY
|
||||
vocabulary (a_id: INTEGER_64): detachable CMS_VOCABULARY
|
||||
-- Vocabulary by id `a_id'.
|
||||
do
|
||||
end
|
||||
@@ -53,7 +53,7 @@ feature -- Access
|
||||
do
|
||||
end
|
||||
|
||||
term_by_id (tid: INTEGER): detachable CMS_TERM
|
||||
term_by_id (tid: INTEGER_64): detachable CMS_TERM
|
||||
-- Term associated with id `tid'.
|
||||
do
|
||||
end
|
||||
@@ -64,4 +64,12 @@ feature -- Access
|
||||
create {ARRAYED_LIST [CMS_TERM]} Result.make (0)
|
||||
end
|
||||
|
||||
feature -- Store
|
||||
|
||||
save_term (t: CMS_TERM)
|
||||
-- Insert or update term `t'.
|
||||
do
|
||||
error_handler.add_custom_error (-1, "not implemented", "")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ feature -- Access
|
||||
create {ARRAYED_LIST [CMS_VOCABULARY]} Result.make (0)
|
||||
end
|
||||
|
||||
vocabulary (a_tid: INTEGER): detachable CMS_VOCABULARY
|
||||
vocabulary (a_tid: INTEGER_64): detachable CMS_VOCABULARY
|
||||
-- Vocabulary by id `a_tid'.
|
||||
do
|
||||
if attached term_by_id (a_tid) as t then
|
||||
@@ -93,7 +93,7 @@ feature -- Access
|
||||
sql_finalize
|
||||
end
|
||||
|
||||
term_by_id (a_tid: INTEGER): detachable CMS_TERM
|
||||
term_by_id (a_tid: INTEGER_64): detachable CMS_TERM
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
@@ -112,122 +112,51 @@ feature -- Access
|
||||
feature -- Store
|
||||
|
||||
save_term (t: CMS_TERM)
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
error_handler.reset
|
||||
|
||||
create l_parameters.make (5)
|
||||
l_parameters.put (t.text, "text")
|
||||
l_parameters.put (t.description, "description")
|
||||
l_parameters.put (t.weight, "weight")
|
||||
|
||||
sql_begin_transaction
|
||||
if t.has_id then
|
||||
l_parameters.put (t.id, "tid")
|
||||
sql_modify (sql_update_term, l_parameters)
|
||||
else
|
||||
sql_insert (sql_insert_term, l_parameters)
|
||||
t.set_id (last_inserted_term_id)
|
||||
end
|
||||
if has_error then
|
||||
sql_rollback_transaction
|
||||
else
|
||||
sql_commit_transaction
|
||||
end
|
||||
sql_finalize
|
||||
end
|
||||
|
||||
-- blogs_count: INTEGER_64
|
||||
-- -- <Precursor>
|
||||
-- do
|
||||
-- error_handler.reset
|
||||
-- write_information_log (generator + ".blogs_count")
|
||||
-- sql_query (sql_select_blog_count, Void)
|
||||
-- if not has_error and not sql_after then
|
||||
-- Result := sql_read_integer_64 (1)
|
||||
-- end
|
||||
-- sql_finalize
|
||||
-- end
|
||||
|
||||
-- blogs_count_from_user (a_user: CMS_USER) : INTEGER_64
|
||||
-- -- <Precursor>
|
||||
-- local
|
||||
-- l_parameters: STRING_TABLE [detachable ANY]
|
||||
-- do
|
||||
-- error_handler.reset
|
||||
-- write_information_log (generator + ".blogs_count_from_user")
|
||||
-- create l_parameters.make (2)
|
||||
-- l_parameters.put (a_user.id, "user")
|
||||
-- sql_query (sql_select_blog_count_from_user, l_parameters)
|
||||
-- if not has_error and not sql_after then
|
||||
-- Result := sql_read_integer_64 (1)
|
||||
-- end
|
||||
-- sql_finalize
|
||||
-- end
|
||||
|
||||
-- blogs: LIST [CMS_NODE]
|
||||
-- -- <Precursor>
|
||||
-- do
|
||||
-- create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
|
||||
-- error_handler.reset
|
||||
-- write_information_log (generator + ".blogs")
|
||||
|
||||
-- from
|
||||
-- sql_query (sql_select_blogs_order_created_desc, Void)
|
||||
-- sql_start
|
||||
-- until
|
||||
-- sql_after
|
||||
-- loop
|
||||
-- if attached fetch_node as l_node then
|
||||
-- Result.force (l_node)
|
||||
-- end
|
||||
-- sql_forth
|
||||
-- end
|
||||
-- sql_finalize
|
||||
-- end
|
||||
|
||||
-- blogs_limited (a_limit: NATURAL_32; a_offset: NATURAL_32): LIST [CMS_NODE]
|
||||
-- -- <Precursor>
|
||||
-- local
|
||||
-- l_parameters: STRING_TABLE [detachable ANY]
|
||||
-- do
|
||||
-- create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
|
||||
-- error_handler.reset
|
||||
-- write_information_log (generator + ".blogs_limited")
|
||||
|
||||
-- from
|
||||
-- create l_parameters.make (2)
|
||||
-- l_parameters.put (a_limit, "limit")
|
||||
-- l_parameters.put (a_offset, "offset")
|
||||
-- sql_query (sql_blogs_limited, l_parameters)
|
||||
-- sql_start
|
||||
-- until
|
||||
-- sql_after
|
||||
-- loop
|
||||
-- if attached fetch_node as l_node then
|
||||
-- Result.force (l_node)
|
||||
-- end
|
||||
-- sql_forth
|
||||
-- end
|
||||
-- sql_finalize
|
||||
-- end
|
||||
|
||||
-- blogs_from_user_limited (a_user: CMS_USER; a_limit: NATURAL_32; a_offset: NATURAL_32): LIST [CMS_NODE]
|
||||
-- -- <Precursor>
|
||||
-- local
|
||||
-- l_parameters: STRING_TABLE [detachable ANY]
|
||||
-- do
|
||||
-- create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
|
||||
-- error_handler.reset
|
||||
-- write_information_log (generator + ".blogs_from_user_limited")
|
||||
|
||||
-- from
|
||||
-- create l_parameters.make (2)
|
||||
-- l_parameters.put (a_limit, "limit")
|
||||
-- l_parameters.put (a_offset, "offset")
|
||||
-- l_parameters.put (a_user.id, "user")
|
||||
-- sql_query (sql_blogs_from_user_limited, l_parameters)
|
||||
-- sql_start
|
||||
-- until
|
||||
-- sql_after
|
||||
-- loop
|
||||
-- if attached fetch_node as l_node then
|
||||
-- Result.force (l_node)
|
||||
-- end
|
||||
-- sql_forth
|
||||
-- end
|
||||
-- sql_finalize
|
||||
-- end
|
||||
|
||||
feature {NONE} -- Queries
|
||||
|
||||
last_inserted_term_id: INTEGER_64
|
||||
-- Last insert term id.
|
||||
do
|
||||
error_handler.reset
|
||||
sql_query (Sql_last_inserted_term_id, Void)
|
||||
if not has_error and not sql_after then
|
||||
Result := sql_read_integer_64 (1)
|
||||
end
|
||||
sql_finalize
|
||||
end
|
||||
|
||||
fetch_term: detachable CMS_TERM
|
||||
local
|
||||
tid: INTEGER
|
||||
tid: INTEGER_64
|
||||
l_text: detachable READABLE_STRING_32
|
||||
do
|
||||
tid := sql_read_integer_32 (1)
|
||||
tid := sql_read_integer_64 (1)
|
||||
l_text := sql_read_string_32 (2)
|
||||
if tid > 0 and l_text /= Void then
|
||||
create Result.make (tid, l_text)
|
||||
@@ -256,18 +185,18 @@ feature {NONE} -- Queries
|
||||
sql_select_term: STRING = "SELECT tid, text, weight, description FROM taxonomy_term WHERE tid = :tid;"
|
||||
-- Term with tid :tid .
|
||||
|
||||
-- sql_select_blog_count_from_user: STRING = "SELECT count(*) FROM nodes WHERE status != -1 AND type = %"blog%" AND author = :user ;"
|
||||
-- -- Nodes count (Published and not Published)
|
||||
-- --| note: {CMS_NODE_API}.trashed = -1
|
||||
Sql_last_inserted_term_id: STRING = "SELECT MAX(tid) FROM taxonomy_term;"
|
||||
|
||||
-- sql_select_blogs_order_created_desc: STRING = "SELECT * FROM nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC;"
|
||||
-- -- SQL Query to retrieve all nodes that are from the type "blog" ordered by descending creation date.
|
||||
|
||||
-- sql_blogs_limited: STRING = "SELECT * FROM nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC LIMIT :limit OFFSET :offset ;"
|
||||
-- --- SQL Query to retrieve all node of type "blog" limited by limit and starting at offset
|
||||
|
||||
-- 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 Query to retrieve all node of type "blog" from author with id limited by limit + offset
|
||||
sql_insert_term: STRING = "[
|
||||
INSERT INTO taxonomy_terms (tid, text, weight, description, langcode)
|
||||
VALUES (:tid, :text, :weight, :description, null);
|
||||
]"
|
||||
|
||||
sql_update_term: STRING = "[
|
||||
UPDATE taxonomy_terms
|
||||
SET tid=:tid, text=:text, weight=:weight, description=:description, langcode=null
|
||||
WHERE tid=:tid;
|
||||
]"
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user