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:
@@ -11,7 +11,6 @@ inherit
|
||||
redefine
|
||||
register_hooks,
|
||||
initialize,
|
||||
is_installed,
|
||||
install
|
||||
end
|
||||
|
||||
@@ -53,12 +52,6 @@ feature {CMS_API} -- Module Initialization
|
||||
|
||||
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)
|
||||
local
|
||||
sql: STRING
|
||||
@@ -78,7 +71,7 @@ CREATE TABLE "blog_post_nodes"(
|
||||
api.logger.put_error ("Could not initialize database for blog module", generating_type)
|
||||
end
|
||||
end
|
||||
api.storage.set_custom_value ("is_initialized", "module-" + name, "yes")
|
||||
Precursor (api)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -16,20 +16,21 @@ inherit
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
create {NODE_MODULE}
|
||||
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
|
||||
-- <Precursor>
|
||||
do
|
||||
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
|
||||
end
|
||||
|
||||
@@ -212,7 +213,6 @@ feature -- Access: Node
|
||||
Result := node_storage.nodes
|
||||
end
|
||||
|
||||
|
||||
trashed_nodes (a_user: CMS_USER): LIST [CMS_NODE]
|
||||
-- List of nodes with status in {CMS_NODE_API}.trashed.
|
||||
-- if the current user is admin, it will retrieve all the trashed nodes
|
||||
|
||||
@@ -9,14 +9,12 @@ class
|
||||
inherit
|
||||
|
||||
CMS_MODULE
|
||||
rename
|
||||
module_api as node_api
|
||||
redefine
|
||||
register_hooks,
|
||||
initialize,
|
||||
is_installed,
|
||||
install,
|
||||
node_api
|
||||
module_api
|
||||
end
|
||||
|
||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
||||
@@ -43,15 +41,26 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature {CMS_API} -- Module Initialization
|
||||
|
||||
initialize (api: CMS_API)
|
||||
initialize (a_api: CMS_API)
|
||||
-- <Precursor>
|
||||
local
|
||||
p1,p2: CMS_PAGE
|
||||
ct: CMS_PAGE_NODE_TYPE
|
||||
l_node_api: like node_api
|
||||
l_node_storage: CMS_NODE_STORAGE_I
|
||||
do
|
||||
Precursor (api)
|
||||
create l_node_api.make (api)
|
||||
Precursor (a_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
|
||||
|
||||
-- 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
|
||||
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
|
||||
p1 := ct.new_node (Void)
|
||||
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.
|
||||
-- IDEA: we could also have generic extension to node system, that handle generic addition field.
|
||||
end
|
||||
ensure then
|
||||
node_api_set: node_api /= Void
|
||||
end
|
||||
|
||||
feature {CMS_API} -- Module management
|
||||
|
||||
is_installed (api: CMS_API): BOOLEAN
|
||||
is_installed (a_api: CMS_API): BOOLEAN
|
||||
-- Is Current module installed?
|
||||
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
|
||||
l_sql_storage.sql_table_exists ("page_nodes")
|
||||
end
|
||||
end
|
||||
|
||||
install (api: CMS_API)
|
||||
install (a_api: CMS_API)
|
||||
do
|
||||
-- Schema
|
||||
if attached {CMS_STORAGE_SQL_I} 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"))
|
||||
if attached {CMS_STORAGE_SQL_I} a_api.storage as l_sql_storage then
|
||||
l_sql_storage.sql_execute_file_script (a_api.setup.environment.path.extended ("scripts").extended (name).appended_with_extension ("sql"))
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
-- <Precursor>
|
||||
|
||||
@@ -111,15 +133,10 @@ feature -- Access: router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_node_api: like node_api
|
||||
do
|
||||
l_node_api := node_api
|
||||
if l_node_api = Void then
|
||||
create l_node_api.make (a_api)
|
||||
node_api := l_node_api
|
||||
if attached node_api as l_node_api then
|
||||
configure_web (a_api, l_node_api, a_router)
|
||||
end
|
||||
configure_web (a_api, l_node_api, a_router)
|
||||
end
|
||||
|
||||
configure_web (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
|
||||
@@ -113,7 +113,7 @@ feature -- Change: Node
|
||||
valid_user: attached a_node.author as l_author and then l_author.id > 0
|
||||
deferred
|
||||
ensure
|
||||
has_id: a_node.has_id
|
||||
has_id: not error_handler.has_error implies a_node.has_id
|
||||
end
|
||||
|
||||
update_node (a_node: CMS_NODE)
|
||||
@@ -170,33 +170,6 @@ feature -- Change: Node
|
||||
deferred
|
||||
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
|
||||
|
||||
fill_node (a_node: CMS_NODE)
|
||||
|
||||
31
package.iron
Normal file
31
package.iron
Normal 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
|
||||
@@ -158,6 +158,8 @@ feature -- Query: module
|
||||
t := a_type.name
|
||||
if t.starts_with ("!") then
|
||||
t.remove_head (1)
|
||||
elseif t.starts_with ("?") then
|
||||
t.remove_head (1)
|
||||
end
|
||||
across
|
||||
setup.modules as ic
|
||||
@@ -186,7 +188,12 @@ feature -- Query: module
|
||||
-- Enabled module API associated with module typed `a_type'.
|
||||
do
|
||||
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
|
||||
|
||||
|
||||
@@ -32,42 +32,57 @@ feature {CMS_API} -- Module Initialization
|
||||
-- Initialize Current module with `api'.
|
||||
require
|
||||
is_enabled: is_enabled
|
||||
is_not_initialized: not is_initialized
|
||||
do
|
||||
-- Redefine to process specific module initialization.
|
||||
is_initialized := True
|
||||
ensure
|
||||
is_initialized: is_initialized
|
||||
end
|
||||
|
||||
feature -- Status
|
||||
|
||||
is_initialized: BOOLEAN
|
||||
-- Is Current module initialized?
|
||||
|
||||
feature {CMS_API} -- Access: API
|
||||
|
||||
module_api: detachable CMS_MODULE_API
|
||||
-- Eventual module api.
|
||||
require
|
||||
is_initialized: is_initialized
|
||||
do
|
||||
-- No API by default.
|
||||
end
|
||||
|
||||
feature {CMS_API} -- Module management
|
||||
|
||||
is_installed (api: CMS_API): BOOLEAN
|
||||
-- Is Current module installed?
|
||||
do
|
||||
Result := is_enabled
|
||||
-- FIXME: implement proper installation status.
|
||||
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)
|
||||
require
|
||||
is_not_installed: not is_installed (api)
|
||||
do
|
||||
-- Not Yet Supported
|
||||
api.storage.set_custom_value ("is_initialized", "module-" + name, "yes")
|
||||
end
|
||||
|
||||
uninstall (api: CMS_API)
|
||||
require
|
||||
is_installed: is_installed (api)
|
||||
do
|
||||
-- Not Yet Supported
|
||||
api.storage.set_custom_value ("is_initialized", "module-" + name, "no")
|
||||
end
|
||||
|
||||
feature -- Router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- Setup url dispatching for Current module.
|
||||
require
|
||||
is_initialized: is_initialized
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
note
|
||||
description: "Summary description for {CMS_MODULE_API}."
|
||||
author: ""
|
||||
date: "$Date: 2015-02-13 14:54:27 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96620 $"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user