Provide a default CMS_MODULE.is_installed: BOOLEAN implementation based on storage of custom value.

Now use CMS_MODULE.is_initialized: BOOLEAN as precondition of many routines.
Instantiation of node storage is now done in NODE_MODULE and not any more in CMS_NODE_API.
CMS_NODE_API can be instantiated only by NODE_MODULE.
This commit is contained in:
2015-05-29 19:20:31 +02:00
parent b77c5cd93c
commit 70d53b3ef1
8 changed files with 105 additions and 70 deletions

View File

@@ -11,7 +11,6 @@ inherit
redefine redefine
register_hooks, register_hooks,
initialize, initialize,
is_installed,
install install
end end
@@ -53,12 +52,6 @@ feature {CMS_API} -- Module Initialization
feature {CMS_API} -- Module management feature {CMS_API} -- Module management
is_installed (api: CMS_API): BOOLEAN
-- Is Current module installed?
do
Result := attached api.storage.custom_value ("is_initialized", "module-" + name) as v and then v.is_case_insensitive_equal_general ("yes")
end
install (api: CMS_API) install (api: CMS_API)
local local
sql: STRING sql: STRING
@@ -78,7 +71,7 @@ CREATE TABLE "blog_post_nodes"(
api.logger.put_error ("Could not initialize database for blog module", generating_type) api.logger.put_error ("Could not initialize database for blog module", generating_type)
end end
end end
api.storage.set_custom_value ("is_initialized", "module-" + name, "yes") Precursor (api)
end end
end end

View File

@@ -16,20 +16,21 @@ inherit
REFACTORING_HELPER REFACTORING_HELPER
create create {NODE_MODULE}
make make_with_storage
feature {NONE} -- Implementation feature {NONE} -- Initialization
make_with_storage (a_api: CMS_API; a_node_storage: CMS_NODE_STORAGE_I)
do
node_storage := a_node_storage
make (a_api)
end
initialize initialize
-- <Precursor> -- <Precursor>
do do
Precursor Precursor
if attached {CMS_STORAGE_SQL_I} storage as l_storage_sql then
create {CMS_NODE_STORAGE_SQL} node_storage.make (l_storage_sql)
else
create {CMS_NODE_STORAGE_NULL} node_storage.make
end
initialize_node_types initialize_node_types
end end
@@ -212,7 +213,6 @@ feature -- Access: Node
Result := node_storage.nodes Result := node_storage.nodes
end end
trashed_nodes (a_user: CMS_USER): LIST [CMS_NODE] trashed_nodes (a_user: CMS_USER): LIST [CMS_NODE]
-- List of nodes with status in {CMS_NODE_API}.trashed. -- List of nodes with status in {CMS_NODE_API}.trashed.
-- if the current user is admin, it will retrieve all the trashed nodes -- if the current user is admin, it will retrieve all the trashed nodes

View File

@@ -9,14 +9,12 @@ class
inherit inherit
CMS_MODULE CMS_MODULE
rename
module_api as node_api
redefine redefine
register_hooks, register_hooks,
initialize, initialize,
is_installed, is_installed,
install, install,
node_api module_api
end end
CMS_HOOK_MENU_SYSTEM_ALTER CMS_HOOK_MENU_SYSTEM_ALTER
@@ -43,15 +41,26 @@ feature {NONE} -- Initialization
feature {CMS_API} -- Module Initialization feature {CMS_API} -- Module Initialization
initialize (api: CMS_API) initialize (a_api: CMS_API)
-- <Precursor> -- <Precursor>
local local
p1,p2: CMS_PAGE p1,p2: CMS_PAGE
ct: CMS_PAGE_NODE_TYPE ct: CMS_PAGE_NODE_TYPE
l_node_api: like node_api l_node_api: like node_api
l_node_storage: CMS_NODE_STORAGE_I
do do
Precursor (api) Precursor (a_api)
create l_node_api.make (api)
-- Storage initialization
if attached {CMS_STORAGE_SQL_I} a_api.storage as l_storage_sql then
create {CMS_NODE_STORAGE_SQL} l_node_storage.make (l_storage_sql)
else
-- FIXME: in case of NULL storage, should Current be disabled?
create {CMS_NODE_STORAGE_NULL} l_node_storage.make
end
-- Node API initialization
create l_node_api.make_with_storage (a_api, l_node_storage)
node_api := l_node_api node_api := l_node_api
-- Add support for CMS_PAGE, which requires a storage extension to store the optional "parent" id. -- Add support for CMS_PAGE, which requires a storage extension to store the optional "parent" id.
@@ -61,7 +70,7 @@ feature {CMS_API} -- Module Initialization
-- FIXME: the following code is mostly for test purpose/initialization, remove later -- FIXME: the following code is mostly for test purpose/initialization, remove later
if l_sql_node_storage.sql_table_items_count ("page_nodes") = 0 then if l_sql_node_storage.sql_table_items_count ("page_nodes") = 0 then
if attached api.user_api.user_by_id (1) as u then if attached a_api.user_api.user_by_id (1) as u then
create ct create ct
p1 := ct.new_node (Void) p1 := ct.new_node (Void)
p1.set_title ("Welcome") p1.set_title ("Welcome")
@@ -81,29 +90,42 @@ feature {CMS_API} -- Module Initialization
-- FIXME: maybe provide a default solution based on file system, when no SQL storage is available. -- FIXME: maybe provide a default solution based on file system, when no SQL storage is available.
-- IDEA: we could also have generic extension to node system, that handle generic addition field. -- IDEA: we could also have generic extension to node system, that handle generic addition field.
end end
ensure then
node_api_set: node_api /= Void
end end
feature {CMS_API} -- Module management feature {CMS_API} -- Module management
is_installed (api: CMS_API): BOOLEAN is_installed (a_api: CMS_API): BOOLEAN
-- Is Current module installed? -- Is Current module installed?
do do
if attached {CMS_STORAGE_SQL_I} api.storage as l_sql_storage then if attached {CMS_STORAGE_SQL_I} a_api.storage as l_sql_storage then
Result := l_sql_storage.sql_table_exists ("nodes") and Result := l_sql_storage.sql_table_exists ("nodes") and
l_sql_storage.sql_table_exists ("page_nodes") l_sql_storage.sql_table_exists ("page_nodes")
end end
end end
install (api: CMS_API) install (a_api: CMS_API)
do do
-- Schema -- Schema
if attached {CMS_STORAGE_SQL_I} api.storage as l_sql_storage then if attached {CMS_STORAGE_SQL_I} a_api.storage as l_sql_storage then
l_sql_storage.sql_execute_file_script (api.setup.environment.path.extended ("scripts").extended (name).appended_with_extension ("sql")) l_sql_storage.sql_execute_file_script (a_api.setup.environment.path.extended ("scripts").extended (name).appended_with_extension ("sql"))
end end
end end
feature {CMS_API} -- Access: API feature {CMS_API} -- Access: API
module_api: detachable CMS_MODULE_API
-- <Precursor>
do
if attached node_api as l_api then
Result := l_api
else
-- Current is initialized, so node_api should be set.
check has_node_api: False end
end
end
node_api: detachable CMS_NODE_API node_api: detachable CMS_NODE_API
-- <Precursor> -- <Precursor>
@@ -111,15 +133,10 @@ feature -- Access: router
setup_router (a_router: WSF_ROUTER; a_api: CMS_API) setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
-- <Precursor> -- <Precursor>
local
l_node_api: like node_api
do do
l_node_api := node_api if attached node_api as l_node_api then
if l_node_api = Void then configure_web (a_api, l_node_api, a_router)
create l_node_api.make (a_api)
node_api := l_node_api
end end
configure_web (a_api, l_node_api, a_router)
end end
configure_web (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER) configure_web (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)

View File

@@ -113,7 +113,7 @@ feature -- Change: Node
valid_user: attached a_node.author as l_author and then l_author.id > 0 valid_user: attached a_node.author as l_author and then l_author.id > 0
deferred deferred
ensure ensure
has_id: a_node.has_id has_id: not error_handler.has_error implies a_node.has_id
end end
update_node (a_node: CMS_NODE) update_node (a_node: CMS_NODE)
@@ -170,33 +170,6 @@ feature -- Change: Node
deferred deferred
end end
-- update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- -- Update node title to `a_title', node identified by id `a_node_id'.
-- -- The user `a_user_id' is an existing or new collaborator.
-- require
-- valid_node_id: a_node_id > 0
-- valid_user_id: a_user_id > 0
-- deferred
-- end
-- update_node_summary (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- -- Update node summary to `a_summary', node identified by id `a_node_id'.
-- -- The user `a_user_id' is an existing or new collaborator.
-- require
-- valid_id: a_node_id > 0
-- valid_user_id: a_user_id > 0
-- deferred
-- end
-- update_node_content (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- -- Update node content to `a_content', node identified by id `a_node_id'.
-- -- The user `a_user_id' is an existing or new collaborator.
-- require
-- valid_id: a_node_id > 0
-- valid_user_id: a_user_id > 0
-- deferred
-- end
feature -- Helpers feature -- Helpers
fill_node (a_node: CMS_NODE) fill_node (a_node: CMS_NODE)

31
package.iron Normal file
View File

@@ -0,0 +1,31 @@
package ROC_cms
project
cms = "cms-safe.ecf"
cms = "cms.ecf"
app_env = "library/app_env/app_env-safe.ecf"
app_env = "library/app_env/app_env.ecf"
config = "library/configuration/config-safe.ecf"
config = "library/configuration/config.ecf"
app_env = "library/layout/layout-safe.ecf"
app_env = "library/layout/layout.ecf"
cms_model = "library/model/cms_model-safe.ecf"
cms_model = "library/model/cms_model.ecf"
persistence_mysql = "library/persistence/mysql/persistence_mysql-safe.ecf"
persistence_mysql = "library/persistence/mysql/persistence_mysql.ecf"
persistence_sqlite = "library/persistence/sqlite/persistence_sqlite-safe.ecf"
persistence_sqlite = "library/persistence/sqlite/persistence_sqlite.ecf"
basic_auth = "modules/basic_auth/basic_auth-safe.ecf"
basic_auth = "modules/basic_auth/basic_auth.ecf"
node = "modules/node/node-safe.ecf"
node = "modules/node/node.ecf"
note
title: ROC CMS
description: CMS written with Eiffel
tags: cms, web, rest, api
license: Eiffel Forum v2
copyright: Jocelyn Fiat, Javier Velilla, Eiffel Software
link[source]: "Github" https://github.com/EiffelWebFramework/ROC.git
end

View File

@@ -158,6 +158,8 @@ feature -- Query: module
t := a_type.name t := a_type.name
if t.starts_with ("!") then if t.starts_with ("!") then
t.remove_head (1) t.remove_head (1)
elseif t.starts_with ("?") then
t.remove_head (1)
end end
across across
setup.modules as ic setup.modules as ic
@@ -186,7 +188,12 @@ feature -- Query: module
-- Enabled module API associated with module typed `a_type'. -- Enabled module API associated with module typed `a_type'.
do do
if attached module (a_type) as mod then if attached module (a_type) as mod then
Result := mod.module_api if mod.is_enabled then
if not mod.is_initialized then
mod.initialize (Current)
end
Result := mod.module_api
end
end end
end end

View File

@@ -32,42 +32,57 @@ feature {CMS_API} -- Module Initialization
-- Initialize Current module with `api'. -- Initialize Current module with `api'.
require require
is_enabled: is_enabled is_enabled: is_enabled
is_not_initialized: not is_initialized
do do
-- Redefine to process specific module initialization. -- Redefine to process specific module initialization.
is_initialized := True
ensure
is_initialized: is_initialized
end end
feature -- Status
is_initialized: BOOLEAN
-- Is Current module initialized?
feature {CMS_API} -- Access: API feature {CMS_API} -- Access: API
module_api: detachable CMS_MODULE_API module_api: detachable CMS_MODULE_API
-- Eventual module api. -- Eventual module api.
require
is_initialized: is_initialized
do
-- No API by default.
end
feature {CMS_API} -- Module management feature {CMS_API} -- Module management
is_installed (api: CMS_API): BOOLEAN is_installed (api: CMS_API): BOOLEAN
-- Is Current module installed? -- Is Current module installed?
do do
Result := is_enabled Result := attached api.storage.custom_value ("is_initialized", "module-" + name) as v and then v.is_case_insensitive_equal_general ("yes")
-- FIXME: implement proper installation status.
end end
install (api: CMS_API) install (api: CMS_API)
require require
is_not_installed: not is_installed (api) is_not_installed: not is_installed (api)
do do
-- Not Yet Supported api.storage.set_custom_value ("is_initialized", "module-" + name, "yes")
end end
uninstall (api: CMS_API) uninstall (api: CMS_API)
require require
is_installed: is_installed (api) is_installed: is_installed (api)
do do
-- Not Yet Supported api.storage.set_custom_value ("is_initialized", "module-" + name, "no")
end end
feature -- Router feature -- Router
setup_router (a_router: WSF_ROUTER; a_api: CMS_API) setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
-- Setup url dispatching for Current module. -- Setup url dispatching for Current module.
require
is_initialized: is_initialized
deferred deferred
end end

View File

@@ -1,6 +1,5 @@
note note
description: "Summary description for {CMS_MODULE_API}." description: "Summary description for {CMS_MODULE_API}."
author: ""
date: "$Date: 2015-02-13 14:54:27 +0100 (ven., 13 févr. 2015) $" date: "$Date: 2015-02-13 14:54:27 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96620 $" revision: "$Revision: 96620 $"