analogous to the blog example created database table
This commit is contained in:
46
modules/file_upload/cms_file_upload_api.e
Normal file
46
modules/file_upload/cms_file_upload_api.e
Normal file
@@ -0,0 +1,46 @@
|
||||
note
|
||||
description: "Summary description for {CMS_FILE_UPLOAD_API}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_FILE_UPLOAD_API
|
||||
|
||||
inherit
|
||||
CMS_MODULE_API
|
||||
rename
|
||||
make as make_with_cms_api
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_api: CMS_API; a_node_api: CMS_NODE_API)
|
||||
-- (from CMS_MODULE_API)
|
||||
do
|
||||
node_api := a_node_api
|
||||
make_with_cms_api(a_api)
|
||||
end
|
||||
|
||||
initialize
|
||||
do
|
||||
Precursor
|
||||
|
||||
-- create the storage of type file
|
||||
if attached storage.as_sql_storage as l_storage_sql then
|
||||
create {CMS_FILE_UPLOAD_STORAGE_SQL} file_storage.make (l_storage_sql)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature -- Access
|
||||
|
||||
nod_api: CMS_NODE_API
|
||||
|
||||
file_storage: CMS_FILE_UPLOAD_STORAGE_I
|
||||
end
|
||||
@@ -11,6 +11,8 @@ inherit
|
||||
CMS_MODULE
|
||||
rename
|
||||
module_api as file_upload_api
|
||||
redefine
|
||||
install
|
||||
end
|
||||
|
||||
create
|
||||
@@ -21,7 +23,7 @@ feature {NONE} -- Initialisation
|
||||
do
|
||||
version := "1.0"
|
||||
description := "Service to upload a file"
|
||||
package := "demo"
|
||||
package := "file_upload"
|
||||
add_dependency({CMS_NODE_MODULE})
|
||||
end
|
||||
|
||||
@@ -29,6 +31,7 @@ feature -- Access
|
||||
|
||||
name: STRING = "file_uploader"
|
||||
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
setup_router(a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
@@ -37,4 +40,31 @@ feature -- Access: router
|
||||
|
||||
end
|
||||
|
||||
feature -- Module Management
|
||||
|
||||
install (api: CMS_API)
|
||||
-- install the module
|
||||
local
|
||||
sql_query: STRING
|
||||
do
|
||||
-- create the database
|
||||
if attached api.storage.as_sql_storage as l_sql_storage then
|
||||
if not l_sql_storage.sql_table_exists ("file_nodes") then
|
||||
sql := "[
|
||||
CREATE TABLE file_nodes(
|
||||
`nid` INTEGER NOT NULL CHECK("nid">=0),
|
||||
`type` VARCHAR(255) NOT NULL,
|
||||
CONSTRAINT unique_id PRIMARY KEY nid
|
||||
);
|
||||
]"
|
||||
|
||||
l_sql_storage.sql_execute_script (sql, void)
|
||||
if l_sql_storage.has_error then
|
||||
api.logger.put_error ("Could not initialize database for file_uploader module", generating_type)
|
||||
|
||||
end
|
||||
end
|
||||
Precursor (api)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ feature -- Access
|
||||
deferred
|
||||
end
|
||||
|
||||
files:<EFBFBD>LIST [CMS_NODE]
|
||||
files: LIST [CMS_NODE]
|
||||
-- List of files
|
||||
deferred
|
||||
end
|
||||
|
||||
@@ -14,6 +14,17 @@ inherit
|
||||
create
|
||||
make
|
||||
|
||||
feature
|
||||
|
||||
files_count: INTEGER_64
|
||||
-- Precursor
|
||||
do
|
||||
|
||||
end
|
||||
|
||||
files: LIST [CMS_NODE]
|
||||
do
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user