Index: openacs-4/packages/file-storage/sql/oracle/file-storage-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/sql/oracle/file-storage-create.sql,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/file-storage/sql/oracle/file-storage-create.sql 8 Jan 2002 05:15:35 -0000 1.7
+++ openacs-4/packages/file-storage/sql/oracle/file-storage-create.sql 21 Feb 2002 20:06:27 -0000 1.8
@@ -1,7 +1,7 @@
--
-- packages/file-storage/sql/file-storage-create.sql
--
--- @author Kevin Scaldeferri (kevin@arsdigita.com)
+-- @author Kevin Scaldeferri(kevin@arsdigita.com)
-- @creation-date 6 Nov 2000
-- @cvs-id $Id$
--
@@ -10,209 +10,206 @@
-- JS: a file's meta-data, while cr_revisions will store specifics of a
-- JS: file's version. Every file has at least one version.
-- JS:
--- JS: 1) The name attribute in cr_items will store the "title" of the
--- JS: of the file, and all its versions.
+-- JS: 1) The name attribute in cr_items will store the "title" of the
+-- JS: of the file, and all its versions.
-- JS:
--- JS: 2) The title attribute in cr_revisions will store the filename
+-- JS: 2) The title attribute in cr_revisions will store the filename
-- JS: of each version, which may be different among versions of the same title.
-- JS:
--- JS: 3) Version notes will still be stored in the description attribute.
+-- JS: 3) Version notes will still be stored in the description attribute.
-- JS:
--- JS: The unfortunate result is that the use of "title" and "name" in
+-- JS: The unfortunate result is that the use of "title" and "name" in
-- JS: cr_revisions and cr_items, respectively, are interchanged.
-- JS:
-
-
--
--- We need to create a root folder in the content repository for
+-- We need to create a root folder in the content repository for
-- each instance of file storage
--
create table fs_root_folders (
-- ID for this package instance
- package_id integer
- constraint fs_root_folder_package_id_fk
- references apm_packages on delete cascade
- constraint fs_root_folder_package_id_pk
- primary key,
+ package_id integer
+ constraint fs_root_folder_package_id_fk
+ references apm_packages on delete cascade
+ constraint fs_root_folder_package_id_pk
+ primary key,
-- the ID of the root folder
-- JS: I removed the on delete cascade constraint on folder_id
- folder_id integer
- constraint fs_root_folder_folder_id_fk
- references cr_folders
- constraint fs_root_folder_folder_id_un
- unique
+ folder_id integer
+ constraint fs_root_folder_folder_id_fk
+ references cr_folders
+ constraint fs_root_folder_folder_id_un
+ unique
);
---
+--
-- To enable site-wide search to distinguish CR items as File Storage items
-- we create an item subtype of content_item in the ACS Object Model
begin
- content_type.create_type (
- content_type => 'file_storage_object',
- pretty_name => 'File Storage Object',
- pretty_plural => 'File Storage Objects',
- supertype => 'content_revision',
- table_name => 'fs_root_folders',
- id_column => 'folder_id',
- name_method => 'file_storage.get_title'
- );
+ content_type.create_type(
+ content_type => 'file_storage_object',
+ pretty_name => 'File Storage Object',
+ pretty_plural => 'File Storage Objects',
+ supertype => 'content_revision',
+ table_name => 'fs_root_folders',
+ id_column => 'folder_id',
+ name_method => 'file_storage.get_title'
+ );
end;
/
show errors;
-
create or replace package file_storage
as
- function get_root_folder (
- --
- -- Returns the root folder corresponding to a particular
- -- package instance.
- --
- package_id in apm_packages.package_id%TYPE
+ function get_root_folder(
+ --
+ -- Returns the root folder corresponding to a particular
+ -- package instance.
+ --
+ package_id in apm_packages.package_id%TYPE
) return fs_root_folders.folder_id%TYPE;
- function new_root_folder (
- --
- -- Creates a new root folder
- --
- package_id in apm_packages.package_id%TYPE
+ function new_root_folder(
+ --
+ -- Creates a new root folder
+ --
+ package_id in apm_packages.package_id%TYPE,
+ folder_name in cr_folders.label%TYPE default null,
+ description in cr_folders.description%TYPE default null
) return fs_root_folders.folder_id%TYPE;
function new_file(
- --
- -- Create a file in CR in preparation for actual storage
- -- Wrapper for content_item.new
- --
- title in cr_items.name%TYPE,
- folder_id in cr_items.parent_id%TYPE,
- creation_user in acs_objects.creation_user%TYPE,
- creation_ip in acs_objects.creation_ip%TYPE,
- indb_p in char default 't'
+ --
+ -- Create a file in CR in preparation for actual storage
+ -- Wrapper for content_item.new
+ --
+ title in cr_items.name%TYPE,
+ folder_id in cr_items.parent_id%TYPE,
+ creation_user in acs_objects.creation_user%TYPE,
+ creation_ip in acs_objects.creation_ip%TYPE,
+ indb_p in char default 't'
) return cr_items.item_id%TYPE;
- procedure delete_file (
- --
- -- Delete a file and all its version
- -- Wrapper to content_item.delete
- --
- file_id in cr_items.item_id%TYPE
+ procedure delete_file(
+ --
+ -- Delete a file and all its version
+ -- Wrapper to content_item.delete
+ --
+ file_id in cr_items.item_id%TYPE
);
- procedure rename_file (
- --
- -- Rename a file and all
- -- Wrapper to content_item__rename
- --
- file_id in cr_items.item_id%TYPE,
- title in cr_items.name%TYPE
+ procedure rename_file(
+ --
+ -- Rename a file and all
+ -- Wrapper to content_item__rename
+ --
+ file_id in cr_items.item_id%TYPE,
+ title in cr_items.name%TYPE
);
function copy_file(
- --
- -- Copy a file, but only copy the live_revision
- --
- file_id in cr_items.item_id%TYPE,
- target_folder_id in cr_items.parent_id%TYPE,
- creation_user in acs_objects.creation_user%TYPE,
- creation_ip in acs_objects.creation_ip%TYPE
+ --
+ -- Copy a file, but only copy the live_revision
+ --
+ file_id in cr_items.item_id%TYPE,
+ target_folder_id in cr_items.parent_id%TYPE,
+ creation_user in acs_objects.creation_user%TYPE,
+ creation_ip in acs_objects.creation_ip%TYPE
) return cr_revisions.revision_id%TYPE;
procedure move_file(
- --
- -- Move a file, and all its versions, to a new folder
- --
- file_id in cr_items.item_id%TYPE,
- target_folder_id in cr_items.parent_id%TYPE
+ --
+ -- Move a file, and all its versions, to a new folder
+ --
+ file_id in cr_items.item_id%TYPE,
+ target_folder_id in cr_items.parent_id%TYPE
);
- function get_title (
- --
- -- Unfortunately, title in the file-storage context refers
- -- to the name attribute in cr_items, not the title attribute in
- -- cr_revisions
- item_id in cr_items.item_id%TYPE
+ function get_title(
+ --
+ -- Unfortunately, title in the file-storage context refers
+ -- to the name attribute in cr_items, not the title attribute in
+ -- cr_revisions
+ item_id in cr_items.item_id%TYPE
) return varchar;
- function get_content_type (
- --
- -- Wrapper for content_item. get_content_type
- --
- item_id in cr_items.item_id%TYPE
+ function get_content_type(
+ --
+ -- Wrapper for content_item. get_content_type
+ --
+ item_id in cr_items.item_id%TYPE
) return cr_items.content_type%TYPE;
- function get_folder_name (
+ function get_folder_name(
--
-- Wrapper for content_folder__get_label
- --
- folder_id in cr_folders.folder_id%TYPE
+ --
+ folder_id in cr_folders.folder_id%TYPE
) return cr_folders.label%TYPE;
- function new_version (
- --
- -- Create a new version of a file
- -- Wrapper for content_revision.new
- --
- filename in cr_revisions.title%TYPE,
- description in cr_revisions.description%TYPE,
- mime_type in cr_revisions.mime_type%TYPE,
- item_id in cr_items.item_id%TYPE,
- creation_user in acs_objects.creation_user%TYPE,
- creation_ip in acs_objects.creation_ip%TYPE
+ function new_version(
+ --
+ -- Create a new version of a file
+ -- Wrapper for content_revision.new
+ --
+ filename in cr_revisions.title%TYPE,
+ description in cr_revisions.description%TYPE,
+ mime_type in cr_revisions.mime_type%TYPE,
+ item_id in cr_items.item_id%TYPE,
+ creation_user in acs_objects.creation_user%TYPE,
+ creation_ip in acs_objects.creation_ip%TYPE
) return cr_revisions.revision_id%TYPE;
- function delete_version (
- --
- -- Delete a version of a file
- --
- file_id in cr_items.item_id%TYPE,
- version_id in cr_revisions.revision_id%TYPE
+ function delete_version(
+ --
+ -- Delete a version of a file
+ --
+ file_id in cr_items.item_id%TYPE,
+ version_id in cr_revisions.revision_id%TYPE
) return cr_items.parent_id%TYPE;
-
function new_folder(
- --
- -- Create a folder
- --
- name in cr_items.name%TYPE,
- folder_name in cr_folders.label%TYPE,
- parent_id cr_items.parent_id%TYPE,
- creation_user in acs_objects.creation_user%TYPE,
- creation_ip in acs_objects.creation_ip%TYPE
+ --
+ -- Create a folder
+ --
+ name in cr_items.name%TYPE,
+ folder_name in cr_folders.label%TYPE,
+ parent_id in cr_items.parent_id%TYPE,
+ creation_user in acs_objects.creation_user%TYPE,
+ creation_ip in acs_objects.creation_ip%TYPE
) return cr_folders.folder_id%TYPE;
procedure delete_folder(
- --
- -- Delete a folder
- --
- folder_id in cr_folders.folder_id%TYPE
+ --
+ -- Delete a folder
+ --
+ folder_id in cr_folders.folder_id%TYPE
);
end file_storage;
/
show errors
-
-
create or replace package body file_storage
as
- function get_root_folder (
+ function get_root_folder(
package_id in apm_packages.package_id%TYPE
- ) return fs_root_folders.folder_id%TYPE
+ ) return fs_root_folders.folder_id%TYPE
is
- v_folder_id fs_root_folders.folder_id%TYPE;
- v_count integer;
+ v_folder_id fs_root_folders.folder_id%TYPE;
+ v_count integer;
begin
-
- select count(*) into v_count
+ select count(*)
+ into v_count
from fs_root_folders
where package_id = get_root_folder.package_id;
if v_count > 0 then
- select folder_id into v_folder_id
+ select folder_id
+ into v_folder_id
from fs_root_folders
where package_id = get_root_folder.package_id;
else
@@ -221,428 +218,413 @@
end if;
return v_folder_id;
-
end get_root_folder;
-
- function new_root_folder (
- --
- -- A hackish function to get around the fact that we can't run
- -- code automatically when a new package instance is created.
- --
- package_id in apm_packages.package_id%TYPE
+ function new_root_folder(
+ --
+ -- A hackish function to get around the fact that we can't run
+ -- code automatically when a new package instance is created.
+ --
+ package_id in apm_packages.package_id%TYPE,
+ folder_name in cr_folders.label%TYPE default null,
+ description in cr_folders.description%TYPE default null
) return fs_root_folders.folder_id%TYPE
is
- v_folder_id fs_root_folders.folder_id%TYPE;
- v_package_name apm_packages.instance_name%TYPE;
- v_package_key apm_packages.package_key%TYPE;
+ v_folder_id fs_root_folders.folder_id%TYPE;
+ v_package_name apm_packages.instance_name%TYPE;
+ v_package_key apm_packages.package_key%TYPE;
+ v_folder_name cr_folders.label%TYPE;
+ v_description cr_folders.description%TYPE;
begin
-
- select instance_name, package_key
+ select instance_name, package_key
into v_package_name, v_package_key
from apm_packages
where package_id = new_root_folder.package_id;
- v_folder_id := content_folder.new (
+ if new_root_folder.folder_name is null
+ then
+ v_folder_name := v_package_name || ' Root Folder';
+ else
+ v_folder_name := folder_name;
+ end if;
+
+ if new_root_folder.description is null
+ then
+ v_description := 'Root folder for the file-storage system. All other folders in file storage are subfolders of this one.';
+ else
+ v_description := description;
+ end if;
+
+ v_folder_id := content_folder.new(
name => v_package_key || '_' || package_id,
- label => v_package_name || ' Root Folder',
- description => 'Root folder for the file-storage system. All other folders in file storage are subfolders of this one.'
+ label => v_folder_name,
+ description => v_description
);
- insert into fs_root_folders
+ insert
+ into fs_root_folders
(package_id, folder_id)
- values
+ values
(package_id, v_folder_id);
-- allow child items to be added
content_folder.register_content_type(v_folder_id,'content_revision','t');
content_folder.register_content_type(v_folder_id,'content_folder','t');
-- set up default permissions
- acs_permission.grant_permission (
+ acs_permission.grant_permission(
object_id => v_folder_id,
grantee_id => acs.magic_object_id('the_public'),
privilege => 'read'
);
- acs_permission.grant_permission (
+
+ acs_permission.grant_permission(
object_id => v_folder_id,
grantee_id => acs.magic_object_id('registered_users'),
privilege => 'write'
);
return v_folder_id;
+ end new_root_folder;
- end new_root_folder;
-
-
- function new_file (
- --
- -- Create a file in CR in preparation for actual storage
- -- Wrapper for content_item.new
- --
- title in cr_items.name%TYPE,
- folder_id in cr_items.parent_id%TYPE,
- creation_user in acs_objects.creation_user%TYPE,
- creation_ip in acs_objects.creation_ip%TYPE,
- indb_p in char default 't'
+ function new_file(
+ --
+ -- Create a file in CR in preparation for actual storage
+ -- Wrapper for content_item.new
+ --
+ title in cr_items.name%TYPE,
+ folder_id in cr_items.parent_id%TYPE,
+ creation_user in acs_objects.creation_user%TYPE,
+ creation_ip in acs_objects.creation_ip%TYPE,
+ indb_p in char default 't'
) return cr_items.item_id%TYPE
is
- v_item_id cr_items.item_id%TYPE;
+ v_item_id cr_items.item_id%TYPE;
begin
+ if new_file.indb_p = 't'
+ then
+ v_item_id := content_item.new(
+ name => new_file.title,
+ parent_id => new_file.folder_id,
+ creation_user => new_file.creation_user,
+ context_id => new_file.folder_id,
+ creation_ip => new_file.creation_ip,
+ content_type => 'file_storage_object',
+ item_subtype => 'content_item'
+ );
+ else
+ v_item_id := content_item.new(
+ name => new_file.title,
+ parent_id => new_file.folder_id,
+ creation_user => new_file.creation_user,
+ context_id => new_file.folder_id,
+ creation_ip => new_file.creation_ip,
+ content_type => 'file_storage_object',
+ item_subtype => 'content_item',
+ storage_type => 'file'
+ );
+ end if;
- if new_file.indb_p = 't'
- then
- v_item_id := content_item.new (
- name => new_file.title,
- parent_id => new_file.folder_id,
- creation_user => new_file.creation_user,
- context_id => new_file.folder_id,
- creation_ip => new_file.creation_ip,
- content_type => 'file_storage_object',
- item_subtype => 'content_item'
- );
- else
- v_item_id := content_item.new (
- name => new_file.title,
- parent_id => new_file.folder_id,
- creation_user => new_file.creation_user,
- context_id => new_file.folder_id,
- creation_ip => new_file.creation_ip,
- content_type => 'file_storage_object',
- item_subtype => 'content_item',
- storage_type => 'file'
- );
-
- end if;
-
- return v_item_id;
-
+ return v_item_id;
end new_file;
-
- procedure delete_file (
- --
- -- Delete a file and all its version
- -- Wrapper to content_item__delete
- --
- file_id in cr_items.item_id%TYPE
- )
+ procedure delete_file(
+ --
+ -- Delete a file and all its version
+ -- Wrapper to content_item__delete
+ --
+ file_id in cr_items.item_id%TYPE
+ )
is
begin
-
- content_item.delete(item_id => file_storage.delete_file.file_id);
-
+ content_item.delete(item_id => file_storage.delete_file.file_id);
end delete_file;
-
- procedure rename_file (
- --
- -- Rename a file and all
- -- Wrapper to content_item__rename
- --
- file_id in cr_items.item_id%TYPE,
- title in cr_items.name%TYPE
+ procedure rename_file(
+ --
+ -- Rename a file and all
+ -- Wrapper to content_item__rename
+ --
+ file_id in cr_items.item_id%TYPE,
+ title in cr_items.name%TYPE
)
is
begin
-
- content_item.rename(
- item_id => file_storage.rename_file.file_id, -- item_id
- name => file_storage.rename_file.title -- name
- );
-
+ content_item.rename(
+ item_id => file_storage.rename_file.file_id,
+ name => file_storage.rename_file.title
+ );
end rename_file;
-
function copy_file(
- --
- -- Copy a file, but only copy the live_revision
- --
- file_id in cr_items.item_id%TYPE,
- target_folder_id in cr_items.parent_id%TYPE,
- creation_user in acs_objects.creation_user%TYPE,
- creation_ip in acs_objects.creation_ip%TYPE
- ) return cr_revisions.revision_id%TYPE
+ --
+ -- Copy a file, but only copy the live_revision
+ --
+ file_id in cr_items.item_id%TYPE,
+ target_folder_id in cr_items.parent_id%TYPE,
+ creation_user in acs_objects.creation_user%TYPE,
+ creation_ip in acs_objects.creation_ip%TYPE
+ ) return cr_revisions.revision_id%TYPE
is
- v_title cr_items.name%TYPE;
- v_live_revision cr_items.live_revision%TYPE;
- v_filename cr_revisions.title%TYPE;
- v_description cr_revisions.description%TYPE;
- v_mime_type cr_revisions.mime_type%TYPE;
- v_content_length cr_revisions.content_length%TYPE;
- v_lob cr_revisions.content%TYPE;
- v_file_path cr_revisions.filename%TYPE;
- v_new_file_id cr_items.item_id%TYPE;
- v_new_version_id cr_revisions.revision_id%TYPE;
- v_indb_p char;
+ v_title cr_items.name%TYPE;
+ v_live_revision cr_items.live_revision%TYPE;
+ v_filename cr_revisions.title%TYPE;
+ v_description cr_revisions.description%TYPE;
+ v_mime_type cr_revisions.mime_type%TYPE;
+ v_content_length cr_revisions.content_length%TYPE;
+ v_lob cr_revisions.content%TYPE;
+ v_file_path cr_revisions.filename%TYPE;
+ v_new_file_id cr_items.item_id%TYPE;
+ v_new_version_id cr_revisions.revision_id%TYPE;
+ v_indb_p char;
begin
+ -- We copy only the title from the file being copied, and attributes of the
+ -- live revision
+ select i.name, i.live_revision, r.title, r.description,
+ r.mime_type, r.content, r.filename, r.content_length,
+ decode(i.storage_type,'lob','t','f')
+ into v_title, v_live_revision, v_filename, v_description,
+ v_mime_type, v_lob, v_file_path, v_content_length,
+ v_indb_p
+ from cr_items i, cr_revisions r
+ where r.item_id = i.item_id
+ and r.revision_id = i.live_revision
+ and i.item_id = file_storage.copy_file.file_id;
- -- We copy only the title from the file being copied, and attributes of the
- -- live revision
- select i.name,i.live_revision,r.title,r.description,
- r.mime_type,r.content,r.filename,r.content_length,
- decode(i.storage_type,'lob','t','f')
- into v_title,v_live_revision,v_filename,v_description,
- v_mime_type,v_lob,v_file_path,v_content_length,
- v_indb_p
- from cr_items i, cr_revisions r
- where r.item_id = i.item_id
- and r.revision_id = i.live_revision
- and i.item_id = file_storage.copy_file.file_id;
+ -- We should probably use the copy functions of CR
+ -- when we optimize this function
+ v_new_file_id := file_storage.new_file(
+ title => v_title,
+ folder_id => file_storage.copy_file.target_folder_id,
+ creation_user => file_storage.copy_file.creation_user,
+ creation_ip => file_storage.copy_file.creation_ip,
+ indb_p => v_indb_p
+ );
- -- We should probably use the copy functions of CR
- -- when we optimize this function
- v_new_file_id := file_storage.new_file(
- title => v_title,
- folder_id => file_storage.copy_file.target_folder_id,
- creation_user => file_storage.copy_file.creation_user,
- creation_ip => file_storage.copy_file.creation_ip,
- indb_p => v_indb_p
- );
+ v_new_version_id := file_storage.new_version(
+ filename => v_filename,
+ description => v_description,
+ mime_type => v_mime_type,
+ item_id => v_new_file_id,
+ creation_user => file_storage.copy_file.creation_user,
+ creation_ip => file_storage.copy_file.creation_ip
+ );
- v_new_version_id := file_storage.new_version (
- filename => v_filename,
- description => v_description,
- mime_type => v_mime_type,
- item_id => v_new_file_id,
- creation_user => file_storage.copy_file.creation_user,
- creation_ip => file_storage.copy_file.creation_ip
- );
-
- -- Oracle is easier, since lobs are true lobs
- -- For now, we simply copy the file name
- update cr_revisions
- set filename = v_file_path,
- content = v_lob,
- content_length = v_content_length
- where revision_id = v_new_version_id;
+ -- Oracle is easier, since lobs are true lobs
+ -- For now, we simply copy the file name
+ update cr_revisions
+ set filename = v_file_path,
+ content = v_lob,
+ content_length = v_content_length
+ where revision_id = v_new_version_id;
- return v_new_version_id;
-
+ return v_new_version_id;
end copy_file;
-
- procedure move_file (
- --
- -- Move a file, and all its versions, to a new folder
- --
- file_id in cr_items.item_id%TYPE,
- target_folder_id in cr_items.parent_id%TYPE
- )
+ procedure move_file(
+ --
+ -- Move a file, and all its versions, to a new folder
+ --
+ file_id in cr_items.item_id%TYPE,
+ target_folder_id in cr_items.parent_id%TYPE
+ )
is
begin
+ content_item.move(
+ item_id => file_storage.move_file.file_id,
+ target_folder_id => file_storage.move_file.target_folder_id
+ );
+ end;
- content_item.move(
- item_id => file_storage.move_file.file_id,
- target_folder_id => file_storage.move_file.target_folder_id
- );
-
- end;
-
-
- function new_version (
- --
- -- Create a new version of a file
- -- Wrapper for content_revision.new
- --
- filename in cr_revisions.title%TYPE,
- description in cr_revisions.description%TYPE,
- mime_type in cr_revisions.mime_type%TYPE,
- item_id in cr_items.item_id%TYPE,
- creation_user in acs_objects.creation_user%TYPE,
- creation_ip in acs_objects.creation_ip%TYPE
+ function new_version(
+ --
+ -- Create a new version of a file
+ -- Wrapper for content_revision.new
+ --
+ filename in cr_revisions.title%TYPE,
+ description in cr_revisions.description%TYPE,
+ mime_type in cr_revisions.mime_type%TYPE,
+ item_id in cr_items.item_id%TYPE,
+ creation_user in acs_objects.creation_user%TYPE,
+ creation_ip in acs_objects.creation_ip%TYPE
) return cr_revisions.revision_id%TYPE
- is
- v_revision_id cr_revisions.revision_id%TYPE;
+ is
+ v_revision_id cr_revisions.revision_id%TYPE;
begin
- -- Create a revision
- v_revision_id := content_revision.new (
- title => new_version.filename,
- description => new_version.description,
- mime_type => new_version.mime_type,
- item_id => new_version.item_id,
- creation_user => new_version.creation_user,
- creation_ip => new_version.creation_ip
- );
+ -- Create a revision
+ v_revision_id := content_revision.new(
+ title => new_version.filename,
+ description => new_version.description,
+ mime_type => new_version.mime_type,
+ item_id => new_version.item_id,
+ creation_user => new_version.creation_user,
+ creation_ip => new_version.creation_ip
+ );
- -- Make live the newly created revision
- content_item.set_live_revision(revision_id => v_revision_id);
+ -- Make live the newly created revision
+ content_item.set_live_revision(revision_id => v_revision_id);
- return v_revision_id;
-
+ return v_revision_id;
end new_version;
-
- function get_title (
- --
- -- Unfortunately, title in the file-storage context refers
- -- to the name attribute in cr_items, not the title attribute in
- -- cr_revisions
- item_id in cr_items.item_id%TYPE
+ function get_title(
+ --
+ -- Unfortunately, title in the file-storage context refers
+ -- to the name attribute in cr_items, not the title attribute in
+ -- cr_revisions
+ item_id in cr_items.item_id%TYPE
) return varchar
is
- v_title cr_items.name%TYPE;
- v_content_type cr_items.content_type%TYPE;
+ v_title cr_items.name%TYPE;
+ v_content_type cr_items.content_type%TYPE;
begin
-
- select content_type into v_content_type
- from cr_items
- where item_id = get_title.item_id;
+ select content_type
+ into v_content_type
+ from cr_items
+ where item_id = get_title.item_id;
- if v_content_type = 'content_folder'
- then
- select label into v_title
- from cr_folders
- where folder_id = get_title.item_id;
- else if v_content_type = 'content_symlink'
- then
- select label into v_title
- from cr_symlinks
- where symlink_id = get_title.item_id;
- else
- select name into v_title
- from cr_items
- where item_id = get_title.item_id;
- end if;
+ if v_content_type = 'content_folder'
+ then
+ select label
+ into v_title
+ from cr_folders
+ where folder_id = get_title.item_id;
+ else if v_content_type = 'content_symlink'
+ then
+ select label into v_title
+ from cr_symlinks
+ where symlink_id = get_title.item_id;
+ else
+ select name into v_title
+ from cr_items
+ where item_id = get_title.item_id;
+ end if;
end if;
return v_title;
-
end get_title;
-
- function get_content_type (
- --
- -- Wrapper for content_item. get_content_type
- --
- item_id in cr_items.item_id%TYPE
+ function get_content_type(
+ --
+ -- Wrapper for content_item. get_content_type
+ --
+ item_id in cr_items.item_id%TYPE
) return cr_items.content_type%TYPE
is
- v_content_type cr_items.content_type%TYPE;
+ v_content_type cr_items.content_type%TYPE;
begin
- v_content_type := content_item.get_content_type(
- item_id => file_storage.get_content_type.item_id
- );
+ v_content_type := content_item.get_content_type(
+ item_id => file_storage.get_content_type.item_id
+ );
- return v_content_type;
-
+ return v_content_type;
end get_content_type;
- function get_folder_name (
- --
- -- Wrapper for content_folder.get_label
- --
- folder_id in cr_folders.folder_id%TYPE
+ function get_folder_name(
+ --
+ -- Wrapper for content_folder.get_label
+ --
+ folder_id in cr_folders.folder_id%TYPE
) return cr_folders.label%TYPE
is
- v_folder_name cr_folders.label%TYPE;
+ v_folder_name cr_folders.label%TYPE;
begin
- v_folder_name := content_folder.get_label(
- folder_id => file_storage.get_folder_name.folder_id
- );
+ v_folder_name := content_folder.get_label(
+ folder_id => file_storage.get_folder_name.folder_id
+ );
- return v_folder_name;
-
+ return v_folder_name;
end get_folder_name;
-
- function delete_version (
- --
- -- Delete a version of a file
- --
- file_id in cr_items.item_id%TYPE,
- version_id in cr_revisions.revision_id%TYPE
+ function delete_version(
+ --
+ -- Delete a version of a file
+ --
+ file_id in cr_items.item_id%TYPE,
+ version_id in cr_revisions.revision_id%TYPE
) return cr_items.parent_id%TYPE
is
- v_parent_id cr_items.parent_id%TYPE;
+ v_parent_id cr_items.parent_id%TYPE;
begin
-
- if file_storage.delete_version.version_id = content_item.get_live_revision(file_storage.delete_version.file_id)
- then
+ if file_storage.delete_version.version_id = content_item.get_live_revision(file_storage.delete_version.file_id)
+ then
content_revision.delete(file_storage.delete_version.version_id);
content_item.set_live_revision(
- content_item.get_latest_revision(file_storage.delete_version.file_id)
- );
+ content_item.get_latest_revision(file_storage.delete_version.file_id)
+ );
else
content_revision.delete(file_storage.delete_version.version_id);
end if;
- -- If the live revision is null, we have deleted the last version above
- select decode(live_revision,null,parent_id,0) into v_parent_id
+ -- If the live revision is null, we have deleted the last version above
+ select decode(live_revision, null, parent_id, 0)
+ into v_parent_id
from cr_items
where item_id = file_storage.delete_version.file_id;
- -- Unfortunately, due to PostgreSQL behavior with regards referential integrity,
- -- we cannot delete the content_item entry if there are no more revisions.
- return v_parent_id;
-
+ -- Unfortunately, due to PostgreSQL behavior with regards referential integrity,
+ -- we cannot delete the content_item entry if there are no more revisions.
+ return v_parent_id;
end delete_version;
-
function new_folder(
- --
- -- Create a folder
- --
- name in cr_items.name%TYPE,
- folder_name in cr_folders.label%TYPE,
- parent_id cr_items.parent_id%TYPE,
- creation_user in acs_objects.creation_user%TYPE,
- creation_ip in acs_objects.creation_ip%TYPE
+ --
+ -- Create a folder
+ --
+ name in cr_items.name%TYPE,
+ folder_name in cr_folders.label%TYPE,
+ parent_id in cr_items.parent_id%TYPE,
+ creation_user in acs_objects.creation_user%TYPE,
+ creation_ip in acs_objects.creation_ip%TYPE
) return cr_folders.folder_id%TYPE
- is
- v_folder_id cr_folders.folder_id%TYPE;
+ is
+ v_folder_id cr_folders.folder_id%TYPE;
begin
+ -- Create a new folder
+ v_folder_id := content_folder.new(
+ name => file_storage.new_folder.name,
+ label => file_storage.new_folder.folder_name,
+ parent_id => file_storage.new_folder.parent_id,
+ creation_user => file_storage.new_folder.creation_user,
+ creation_ip => file_storage.new_folder.creation_ip
+ );
- -- Create a new folder
- v_folder_id := content_folder.new (
- name => file_storage.new_folder.name,
- label => file_storage.new_folder.folder_name,
- parent_id => file_storage.new_folder.parent_id,
- creation_user => file_storage.new_folder.creation_user,
- creation_ip => file_storage.new_folder.creation_ip
- );
+ -- register the standard content types
+ content_folder.register_content_type(
+ v_folder_id, -- folder_id
+ 'content_revision', -- content_type
+ 't' -- include_subtypes
+ );
- -- register the standard content types
- content_folder.register_content_type(
- v_folder_id, -- folder_id
- 'content_revision', -- content_type
- 't' -- include_subtypes
- );
+ content_folder.register_content_type(
+ v_folder_id, -- folder_id
+ 'content_folder', -- content_type
+ 't' -- include_subtypes
+ );
- content_folder.register_content_type(
- v_folder_id, -- folder_id
- 'content_folder', -- content_type
- 't' -- include_subtypes
- );
+ -- Give the creator admin privileges on the folder
+ acs_permission.grant_permission(
+ v_folder_id, -- object_id
+ file_storage.new_folder.creation_user, -- grantee_id
+ 'admin' -- privilege
+ );
- -- Give the creator admin privileges on the folder
- acs_permission.grant_permission (
- v_folder_id, -- object_id
- file_storage.new_folder.creation_user, -- grantee_id
- 'admin' -- privilege
- );
-
- return v_folder_id;
-
+ return v_folder_id;
end new_folder;
-
procedure delete_folder(
- --
- -- Delete a folder
- --
- folder_id in cr_folders.folder_id%TYPE
+ --
+ -- Delete a folder
+ --
+ folder_id in cr_folders.folder_id%TYPE
)
- is
+ is
begin
-
- content_folder.delete(
- folder_id => file_storage.delete_folder.folder_id
- );
-
+ content_folder.delete(
+ folder_id => file_storage.delete_folder.folder_id
+ );
end delete_folder;
-
end file_storage;
/
show errors;
@@ -652,50 +634,41 @@
before delete on fs_root_folders
for each row
declare
-
- cursor v_cursor is
- select item_id,content_type
- from cr_items
- where item_id != :old.folder_id
- connect by parent_id = prior item_id
- start with item_id = :old.folder_id
- order by level desc;
+ cursor v_cursor is
+ select item_id,content_type
+ from cr_items
+ where item_id != :old.folder_id
+ connect by parent_id = prior item_id
+ start with item_id = :old.folder_id
+ order by level desc;
begin
- for v_rec in v_cursor
- loop
+ for v_rec in v_cursor
+ loop
+ -- We delete the item. On delete cascade should take care
+ -- of deletion of revisions.
+ if v_rec.content_type = 'file_storage_object'
+ then
+ content_item.delete(v_rec.item_id);
+ end if;
- -- We delete the item. On delete cascade should take care
- -- of deletion of revisions.
- if v_rec.content_type = 'file_storage_object'
- then
- content_item.delete(v_rec.item_id);
- end if;
+ -- Instead of doing an if-else, we make sure we are deleting a folder.
+ if v_rec.content_type = 'content_folder'
+ then
+ content_folder.delete(v_rec.item_id);
+ end if;
- -- Instead of doing an if-else, we make sure we are deleting a folder.
- if v_rec.content_type = 'content_folder'
- then
- content_folder.delete(v_rec.item_id);
- end if;
-
- -- We may have to delete other items here, e.g., symlinks (future feature)
-
- end loop;
+ -- We may have to delete other items here, e.g., symlinks(future feature)
+ end loop;
end;
/
show errors;
-
-- JS: AFTER DELETE TRIGGER to clean up last entry in CR
create or replace trigger fs_root_folder_delete_trig
after delete on fs_root_folders
for each row
begin
- content_folder.delete(:old.folder_id);
+ content_folder.delete(:old.folder_id);
end;
/
show errors;
-
-
-
-
-
Index: openacs-4/packages/file-storage/sql/postgresql/file-storage-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/sql/postgresql/file-storage-create.sql,v
diff -u -r1.9 -r1.10
--- openacs-4/packages/file-storage/sql/postgresql/file-storage-create.sql 18 Dec 2001 20:55:08 -0000 1.9
+++ openacs-4/packages/file-storage/sql/postgresql/file-storage-create.sql 21 Feb 2002 20:06:27 -0000 1.10
@@ -97,25 +97,45 @@
-- A hackish function to get around the fact that we can not run
-- code automatically when a new package instance is created.
--
- integer -- apm_packages.package_id%TYPE
+ integer, -- apm_packages.package_id%TYPE
+ varchar, -- cr_folders.label%TYPE
+ varchar -- cr_folders.description%TYPE
)
returns integer as ' -- fs_root_folders.folder_id%TYPE
declare
- new_root_folder__package_id alias for $1;
- v_folder_id fs_root_folders.folder_id%TYPE;
- v_package_name apm_packages.instance_name%TYPE;
- v_package_key apm_packages.package_key%TYPE;
+ new_root_folder__package_id alias for $1;
+ new_root_folder__folder_name alias for $2;
+ new_root_folder__description alias for $3;
+ v_folder_id fs_root_folders.folder_id%TYPE;
+ v_package_name apm_packages.instance_name%TYPE;
+ v_package_key apm_packages.package_key%TYPE;
+ v_folder_name cr_folders.label%TYPE;
+ v_description cr_folders.description%TYPE;
begin
select instance_name, package_key
into v_package_name, v_package_key
from apm_packages
where package_id = new_root_folder__package_id;
+ if new_root_folder__folder_name is null
+ then
+ v_folder_name := v_package_name || '' Root Folder '';
+ else
+ v_folder_name := new_root_folder__folder_name;
+ end if;
+
+ if new_root_folder__description is null
+ then
+ v_description := ''Root folder for the file-storage system. All other folders in file storage are subfolders of this one.'';
+ else
+ v_description := new_root_folder__description;
+ end if;
+
v_folder_id := content_folder__new (
v_package_key || ''_'' || new_root_folder__package_id, -- name
- v_package_name || '' Root Folder'', -- label
- ''Root folder for the file-storage system. All other folders in file storage are subfolders of this one.'', -- description
+ v_folder_name, -- label
+ v_description, -- description
null -- parent_id (default)
);
Index: openacs-4/packages/file-storage/tcl/file-storage-procs-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs-oracle.xql,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/file-storage/tcl/file-storage-procs-oracle.xql 20 Feb 2002 16:39:39 -0000 1.3
+++ openacs-4/packages/file-storage/tcl/file-storage-procs-oracle.xql 21 Feb 2002 20:06:27 -0000 1.4
@@ -7,7 +7,9 @@
begin
:1 := file_storage.new_root_folder(
- package_id => :package_id
+ package_id => :package_id,
+ folder_name => :pretty_name,
+ description => :description
);
end;
Index: openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql,v
diff -u -r1.10 -r1.11
--- openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql 20 Feb 2002 16:39:39 -0000 1.10
+++ openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql 21 Feb 2002 20:06:27 -0000 1.11
@@ -5,7 +5,11 @@
- select file_storage__new_root_folder(:package_id);
+ select file_storage__new_root_folder(
+ :package_id,
+ :pretty_name,
+ :description
+ );
Index: openacs-4/packages/file-storage/tcl/file-storage-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs.tcl,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 20 Feb 2002 21:25:21 -0000 1.6
+++ openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 21 Feb 2002 20:06:27 -0000 1.7
@@ -226,6 +226,8 @@
ad_proc -public new_root_folder {
{-package_id:required}
+ {-pretty_name ""}
+ {-description ""}
} {
Create a root folder for a package instance
@@ -277,4 +279,20 @@
return [db_exec_plsql new_folder {}]
}
+ ad_proc -public get_folder {
+ {-name:required}
+ {-parent_id:required}
+ } {
+ Retrieve the folder_id of a folder given it's name and parent folder
+
+ @param name Internal name of the folder, must be unique under a given
+ parent_id
+ @param parent_id The parent folder to look under
+
+ @return folder_id of the folder, or null if no folder was found by that
+ name
+ } {
+ return [db_string get_folder {} -default ""]
+ }
+
}
Index: openacs-4/packages/file-storage/tcl/file-storage-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/file-storage/tcl/file-storage-procs.xql 13 Aug 2001 15:41:00 -0000 1.1
+++ openacs-4/packages/file-storage/tcl/file-storage-procs.xql 21 Feb 2002 20:06:27 -0000 1.2
@@ -40,4 +40,13 @@
+
+
+ select item_id
+ from cr_items
+ where parent_id = :parent_id
+ and name = :name
+
+
+
Index: openacs-4/packages/file-storage/www/index-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/Attic/index-oracle.xql,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/file-storage/www/index-oracle.xql 4 Dec 2001 04:59:48 -0000 1.4
+++ openacs-4/packages/file-storage/www/index-oracle.xql 21 Feb 2002 20:06:27 -0000 1.5
@@ -3,37 +3,38 @@
oracle8.1.6
-
-
-
-select i.item_id as file_id,
- i.name as name,
- i.live_revision,
- r.mime_type as type,
- to_char(o.last_modified,'YYYY-MM-DD HH24:MI') as last_modified,
- r.content_length as content_size,
- 1 as ordering_key
-from cr_items i, cr_revisions r, acs_objects o
-where i.item_id = o.object_id
-and i.live_revision = r.revision_id (+)
-and i.parent_id = :folder_id
-and acs_permission.permission_p(i.item_id, :user_id, 'read') = 't'
-and i.content_type = 'content_revision'
-UNION
-select i.item_id as file_id,
- f.label as name,
- 0,
- 'Folder',
- NULL,
- 0,
- 0
-from cr_items i, cr_folders f
-where i.item_id = f.folder_id
-and i.parent_id = :folder_id
-and acs_permission.permission_p(folder_id, :user_id, 'read') = 't'
-order by ordering_key,name
-
-
+
+
+ select cr_items.item_id as file_id,
+ cr_items.name as name,
+ cr_items.live_revision,
+ cr_revisions.mime_type as type,
+ to_char(acs_objects.last_modified,'YYYY-MM-DD HH24:MI') as last_modified,
+ cr_revisions.content_length as content_size,
+ 1 as ordering_key
+ from cr_items,
+ cr_revisions,
+ acs_objects
+ where cr_items.parent_id = :folder_id
+ and cr_items.content_type = 'file_storage_object'
+ and 't' = acs_permission.permission_p(cr_items.item_id, :user_id, 'read')
+ and cr_items.item_id = acs_objects.object_id
+ and cr_items.live_revision = cr_revisions.revision_id (+)
+ UNION
+ select cr_items.item_id as file_id,
+ cr_folders.label as name,
+ 0 as live_revision,
+ 'Folder' as type,
+ NULL as last_modified,
+ 0 as content_size,
+ 0 as ordering_key
+ from cr_items,
+ cr_folders
+ where cr_items.parent_id = :folder_id
+ and cr_items.item_id = cr_folders.folder_id
+ and 't' = acs_permission.permission_p(cr_folders.folder_id, :user_id, 'read')
+ order by ordering_key, name
+
+
-
Index: openacs-4/packages/file-storage/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/index.tcl,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/file-storage/www/index.tcl 4 Dec 2001 04:59:48 -0000 1.6
+++ openacs-4/packages/file-storage/www/index.tcl 21 Feb 2002 20:06:27 -0000 1.7
@@ -47,32 +47,6 @@
set package_id [ad_conn package_id]
-db_multirow file file_select "
-select i.item_id as file_id,
- r.title as name,
- i.live_revision,
- r.mime_type as type,
- to_char(o.last_modified,'YYYY-MM-DD HH24:MI') as last_modified,
- r.content_length as content_size,
- 1 as ordering_key
-from cr_items i, cr_revisions r, acs_objects o
-where i.item_id = o.object_id
-and i.live_revision = r.revision_id (+)
-and i.parent_id = :folder_id
-and acs_permission.permission_p(i.item_id, :user_id, 'read') = 't'
-and i.content_type = 'content_revision'
-UNION
-select i.item_id as file_id,
- f.label as name,
- 0,
- 'Folder',
- NULL,
- 0,
- 0
-from cr_items i, cr_folders f
-where i.item_id = f.folder_id
-and i.parent_id = :folder_id
-and acs_permission.permission_p(folder_id, :user_id, 'read') = 't'
-order by ordering_key,name"
+db_multirow file file_select {}
ad_return_template