Commit abfda9fd authored by Frank Bergmann's avatar Frank Bergmann

- WIP version with im_file and im_file_version

parent 3af9e743
......@@ -7,18 +7,413 @@
--
-- @author frank.bergmann@project-open.com
-----------------------------------------------------------
--
--
-- Install crypto extension in order to have sha1 available
create extension pgcrypto;
-- create extension pgcrypto;
SELECT acs_object_type__create_type (
'im_file', -- object_type - only lower case letters and "_"
'File', -- pretty_name - Human readable name
'Files', -- pretty_plural - Human readable plural
'content_item', -- supertype - "acs_object" is topmost object type.
'im_files', -- table_name - where to store data for this object?
'file_id', -- id_column - where to store object_id in the table?
'intranet-rest-fs-openacs', -- package_name - name of this package
'f', -- abstract_p - abstract class or not
null, -- type_extension_table
'im_file__name' -- name_method - a PL/SQL procedure that
-- returns the name of the object.
);
-- Add additional meta information to allow DynFields to extend the im_file object.
update acs_object_types set
status_type_table = 'im_files', -- which table contains the status_id field?
status_column = 'file_status_id', -- which column contains the status_id field?
type_column = 'file_type_id', -- which column contains the type_id field?
type_category_type = 'Intranet File Type',
status_category_type = 'Intranet File Status'
where object_type = 'im_file';
-- Object Type Tables contain the lists of all tables
insert into acs_object_type_tables (object_type, table_name, id_column)
values ('im_file', 'im_files', 'file_id');
insert into acs_object_type_tables (object_type, table_name, id_column)
values ('im_file', 'content_items', 'item_id');
-- Generic URLs to link to an object of type "im_file".
insert into im_biz_object_urls (object_type, url_type, url) values (
'im_file','view','/intranet-rest-fs-openacs/new?display_mode=display&file_id=');
insert into im_biz_object_urls (object_type, url_type, url) values (
'im_file','edit','/intranet-rest-fs-openacs/new?display_mode=edit&file_id=');
create table im_files (
file_id integer
constraint im_files_pk
primary key
constraint im_files_id_fk
references cr_items,
file_status_id integer
constraint im_files_status_fk
references im_categories,
file_type_id integer
constraint im_files_type_fk
references im_categories
);
create or replace function im_file__name(integer)
returns varchar as $body$
DECLARE
p_file_id alias for $1;
v_name varchar;
BEGIN
select name into v_name
from cr_items
where item_id = p_file_id;
return v_name;
end; $body$ language 'plpgsql';
create or replace function im_file__new (
integer, varchar, timestamptz,
integer, varchar, integer,
varchar, integer,
integer, integer
) returns integer as $body$
DECLARE
-- Default 6 parameters that go into the acs_objects table
p_file_id alias for $1; -- file_id default null
p_object_type alias for $2; -- object_type default im_file
p_creation_date alias for $3; -- creation_date default now()
p_creation_user alias for $4; -- creation_user default null
p_creation_ip alias for $5; -- creation_ip default null
p_context_id alias for $6; -- context_id default null
-- Specific parameters with data to go into the im_files table
p_note alias for $7; -- im_files.note - contents
p_object_id alias for $8; -- associated object (project, user, ...)
p_file_type_id alias for $9; -- type (email, http, text comment, ...)
p_file_status_id alias for $10; -- status ("active" or "deleted").
-- This is a variable for the PL/SQL function
v_file_id integer;
v_revision_id integer;
BEGIN
-- ToDo: Not implemented yet
v_file_id := content_item__new(
new__name,
new__parent_id,
new__item_id,
new__locale,
new__creation_date,
new__creation_user,
new__context_id,
new__creation_ip,
new__item_subtype,
new__content_type,
new__title,
new__description,
new__mime_type,
new__nls_language,
new__text,
new__data,
new__relation_tag,
new__is_live,
new__storage_type,
new__package_id
/*
'PO-V50-Project-Types.170909.ppt',
'53018',
'53220',
null,
null,
'624',
null,
'127.0.0.1',
'content_item',
'file_storage_object',
NULL,
NULL,
'text/plain',
null,
NULL,
NULL,
null,
'f',
'file',
'35997'
*/
);
v_revision_id := content_revision__new(
p_new.title,
p_new.description,
now(),
p_new.mime_type,
p_new.nls_language,
case when p_new.text is null then p_new.data else p_new.text end,
content_symlink__resolve(p_new.item_id),
p_new.revision_id,
now(),
p_new.creation_user,
p_new.creation_ip,
p_new.object_package_id
);
-- Create an entry in the im_files table with the same
-- v_file_id from acs_objects.object_id
insert into im_files (
file_id, note, object_id,
file_type_id, file_status_id
) values (
v_file_id, p_note, p_object_id,
p_file_type_id, p_file_status_id
);
return v_file_id;
END;$body$ language 'plpgsql';
create or replace function im_file__delete(integer)
returns integer as $body$
DECLARE
p_file_id alias for $1;
BEGIN
-- ToDo: not implemented yet
-- Delete any data related to the object
delete from im_files
where file_id = p_file_id;
-- Finally delete the object iself
PERFORM acs_object__delete(p_file_id);
return 0;
end;$body$ language 'plpgsql';
-----------------------------------------------------------
--
-- Install crypto extension in order to have sha1 available
-- create extension pgcrypto;
SELECT acs_object_type__create_type (
'im_file_version', -- object_type - only lower case letters and "_"
'File Version', -- pretty_name - Human readable name
'File Versions', -- pretty_plural - Human readable plural
'content_revision', -- supertype - "acs_object" is topmost object type.
'im_file_versions', -- table_name - where to store data for this object?
'file_version_id', -- id_column - where to store object_id in the table?
'intranet-rest-fs-openacs', -- package_name - name of this package
'f', -- abstract_p - abstract class or not
null, -- type_extension_table
'im_file_version__name' -- name_method - a PL/SQL procedure that
-- returns the name of the object.
);
-- Add additional meta information to allow DynFields to extend the im_file_version object.
update acs_object_types set
status_type_table = 'im_file_versions', -- which table contains the status_id field?
status_column = 'file_version_status_id', -- which column contains the status_id field?
type_column = 'file_version_type_id', -- which column contains the type_id field?
type_category_type = 'Intranet File Version Type',
status_category_type = 'Intranet File Version Status'
where object_type = 'im_file_version';
-- Object Type Tables contain the lists of all tables
insert into acs_object_type_tables (object_type, table_name, id_column)
values ('im_file_version', 'im_file_versions', 'file_version_id');
insert into acs_object_type_tables (object_type, table_name, id_column)
values ('im_file_version', 'content_items', 'item_id');
-- Generic URLs to link to an object of type "im_file_version".
insert into im_biz_object_urls (object_type, url_type, url) values (
'im_file_version','view','/intranet-rest-fs-openacs/new?display_mode=display&file_version_id=');
insert into im_biz_object_urls (object_type, url_type, url) values (
'im_file_version','edit','/intranet-rest-fs-openacs/new?display_mode=edit&file_version_id=');
create table im_file_versions (
version_id integer
constraint im_file_versions_pk
primary key
constraint im_file_versions_id_fk
references cr_revisions,
version_status_id integer
constraint im_file_versions_status_fk
references im_categories,
version_type_id integer
constraint im_file_versions_type_fk
references im_categories,
version_creation_date timestamptz,
version_modification_date timestamptz,
version_sha1 text,
version_upload_comment text
);
create or replace function im_file_version__name(integer)
returns varchar as $body$
DECLARE
p_file_version_id alias for $1;
v_name varchar;
BEGIN
select title into v_name
from cr_revisions
where revision_id = p_file_version_id;
return v_name;
end; $body$ language 'plpgsql';
create or replace function im_file_version__new (
integer, varchar, timestamptz,
integer, varchar, integer,
varchar, integer,
integer, integer
) returns integer as $body$
DECLARE
-- Default 6 parameters that go into the acs_objects table
p_file_version_id alias for $1; -- file_version_id default null
p_object_type alias for $2; -- object_type default im_file_version
p_creation_date alias for $3; -- creation_date default now()
p_creation_user alias for $4; -- creation_user default null
p_creation_ip alias for $5; -- creation_ip default null
p_context_id alias for $6; -- context_id default null
-- Specific parameters with data to go into the im_file_versions table
p_note alias for $7; -- im_file_versions.note - contents
p_object_id alias for $8; -- associated object (project, user, ...)
p_file_version_type_id alias for $9; -- type (email, http, text comment, ...)
p_file_version_status_id alias for $10; -- status ("active" or "deleted").
-- This is a variable for the PL/SQL function
v_file_version_id integer;
v_revision_id integer;
BEGIN
-- ToDo: Not implemented yet
v_revision_id := content_revision__new(
p_new.title,
p_new.description,
now(),
p_new.mime_type,
p_new.nls_language,
case when p_new.text is null then p_new.data else p_new.text end,
content_symlink__resolve(p_new.item_id),
p_new.revision_id,
now(),
p_new.creation_user,
p_new.creation_ip,
p_new.object_package_id
);
-- Create an entry in the im_file_versions table with the same
-- v_file_version_id from acs_objects.object_id
insert into im_file_versions (
file_version_id, note, object_id,
file_version_type_id, file_version_status_id
) values (
v_file_version_id, p_note, p_object_id,
p_file_version_type_id, p_file_version_status_id
);
return v_file_version_id;
END;$body$ language 'plpgsql';
create or replace function im_file_version__delete(integer)
returns integer as $body$
DECLARE
p_file_version_id alias for $1;
BEGIN
-- ToDo: not implemented yet
-- Delete any data related to the object
delete from im_file_versions
where file_version_id = p_file_version_id;
-- Finally delete the object iself
PERFORM acs_object__delete(p_file_version_id);
return 0;
end;$body$ language 'plpgsql';
alter table fs_files add column sha1 text;
-----------------------------------------------------------
-- Categories for Type and Status
--
-- 91000-91099 Intranet File Version Status (100)
-- 91100-91199 Intranet File Version Type (100)
-- 91200-91299 Intranet File Version Status (100)
-- 91300-91399 Intranet File Version Type (100)
-- 91400-91999 Intranet File reserved (600)
-- File Status
SELECT im_category_new (91000, 'Active', 'Intranet File Version Status');
SELECT im_category_new (91002, 'Deleted', 'Intranet File Version Status');
-- File Type
SELECT im_category_new (91100, 'Default', 'Intranet File Version Type');
-- Version Status
SELECT im_category_new (91200, 'Active', 'Intranet File Version Status');
SELECT im_category_new (91202, 'Deleted', 'Intranet File Version Status');
-- Version Type
SELECT im_category_new (91300, 'Default', 'Intranet File Version Type');
-----------------------------------------------------------
-- Create views for shortcut
--
-- These views are optional.
create or replace view im_file_status as
select category_id as file_status_id, category as file_status
from im_categories
where category_type = 'Intranet File Status'
and enabled_p = 't';
create or replace view im_file_types as
select category_id as file_type_id, category as file_type
from im_categories
where category_type = 'Intranet File Type'
and enabled_p = 't';
create or replace view im_file_version_status as
select category_id as file_version_version_status_id, category as file_version_version_status
from im_categories
where category_type = 'Intranet File Version Status'
and enabled_p = 't';
create or replace view im_file_version_types as
select category_id as file_version_version_type_id, category as file_version_version_type
from im_categories
where category_type = 'Intranet File Version Type'
and enabled_p = 't';
-----------------------------------------------------------
-- Plugin Components
--
......@@ -26,15 +421,17 @@ alter table fs_files add column sha1 text;
-- List of Risks per project
SELECT im_component_plugin__new (
null, 'im_component_plugin', now(), null, null, null,
'Project HTML5 File-Storage', -- plugin_name
'Project HTML5 File Version-Storage', -- plugin_name
'intranet-rest-fs-openacs', -- package_name
'right', -- location
'right', -- location
'/intranet/projects/view', -- page_url
null, -- view_name
300, -- sort_order
null, -- view_name
300, -- sort_order
'im_rest_fs_component -object_id $project_id' -- component_tcl
);
update im_component_plugins
set title_tcl = 'lang::message::lookup "" intranet-rest-fs-openacs.Project_HTML5_File_Storage "Project HTML5 File-Storage"'
where plugin_name = 'Project HTML5 File-Storage';
update im_component_plugins
set title_tcl = 'lang::message::lookup "" intranet-rest-fs-openacs.Project_HTML5_File Version_Storage "Project HTML5 File Version-Storage"'
where plugin_name = 'Project HTML5 File Version-Storage';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment