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.8 -r1.9 --- openacs-4/packages/file-storage/sql/postgresql/file-storage-create.sql 8 Dec 2001 01:18:00 -0000 1.8 +++ openacs-4/packages/file-storage/sql/postgresql/file-storage-create.sql 18 Dec 2001 20:55:08 -0000 1.9 @@ -22,21 +22,6 @@ -- JS: cr_revisions and cr_items, respectively, are interchanged. -- JS: --- 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 - select acs_object_type__create_type ( - 'file_storage_item', -- object_type - 'File Storage Item', -- pretty_name - 'File Storage Items', -- pretty_plural - 'content_item', -- supertype - 'fs_root_folders', -- table_name (JS: Will not do anything, but we have to insert something) - 'folder_id', -- id_column (JS: Same) - null, -- package_name (default) - 'f', -- abstract_p (default) - null, -- type_extension_table (default) - 'content_item.get_title' -- name_method - ); - -- -- We need to create a root folder in the content repository for -- each instance of file storage @@ -58,6 +43,20 @@ unique ); +-- Create a subtype of content_revision so that site-wide-search can +-- distinguish file-storage items (v.s. generic content repository +-- items) in the search results +select content_type__create_type ( + 'file_storage_object', -- content_type + 'content_revision', -- supertype. We search revision content + -- first, before item metadata + 'File Storage Object', -- pretty_name + 'File Storage Objects', -- pretty_plural + 'fs_root_folders', -- table_name + 'folder_id', -- id_column + 'file_storage__get_title' -- name_method + ); + create function file_storage__get_root_folder ( -- -- Returns the root folder corresponding to a particular @@ -90,7 +89,6 @@ end;' language 'plpgsql' with (iscachable); - create function file_storage__new_root_folder ( -- -- Creates a new root folder @@ -127,15 +125,17 @@ (new_root_folder__package_id, v_folder_id); -- allow child items to be added + -- JS: Note that we need to set include_subtypes to + -- JS: true since we created a new subtype. PERFORM content_folder__register_content_type( v_folder_id, -- folder_id ''content_revision'', -- content_types - ''f'' -- include_subtypes (default) + ''t'' -- include_subtypes ); PERFORM content_folder__register_content_type( v_folder_id, -- folder_id ''content_folder'', -- content_types - ''f'' -- include_subtypes (default) + ''t'' -- include_subtypes ); -- set up default permissions @@ -186,8 +186,8 @@ new_file__user_id, -- creation_user new_file__folder_id, -- context_id new_file__creation_ip, -- creation_ip - ''file_storage_item'', -- item_subtype (needed by site-wide search) - ''content_revision'', -- content_type (default) + ''content_item'', -- item_subtype (default) + ''file_storage_object'', -- content_type (needed by site-wide search) null, -- title (default) null, -- description ''text/plain'', -- mime_type (default) @@ -204,8 +204,8 @@ new_file__user_id, -- creation_user new_file__folder_id, -- context_id new_file__creation_ip, -- creation_ip - ''file_storage_item'', -- item_subtype (needed by site-wide search) - ''content_revision'', -- content_type (default) + ''content_item'', -- item_subtype (default) + ''file_storage_object'', -- content_type (needed by site-wide search) null, -- title (default) null, -- description ''text/plain'', -- mime_type (default) @@ -218,6 +218,7 @@ end;' language 'plpgsql'; + create function file_storage__delete_file ( -- -- Delete a file and all its version @@ -377,76 +378,6 @@ end;' language 'plpgsql'; - -create function file_storage__get_path ( - -- - -- Get the virtual path, but replace title with name at the end - -- Wrapper for content_item__get_path - -- - integer, -- cr_items.item_id%TYPE - integer, -- cr_items.parent_id%TYPE - integer -- cr_revisions.revision_id%TYPE -) returns varchar as ' -declare - get_path__item_id alias for $1; - get_path__root_folder_id alias for $2; - get_path__revision_id alias for $3; - v_filename cr_revisions.title%TYPE; - v_content_type cr_items.content_type%TYPE; -begin - - select content_type into v_content_type - from cr_items - where item_id = get_path__item_id; - - if v_content_type = ''content_revision'' - then - select title into v_filename - from cr_revisions - where revision_id = get_path__revision_id; - - return content_item__get_path( - get_path__item_id, - get_path__root_folder_id - ) || ''/../'' || v_filename; - - else - - return content_item__get_path( - get_path__item_id, - get_path__root_folder_id - ); - - end if; - -end;' language 'plpgsql'; - -create function file_storage__get_path ( - -- - -- Get path, using the live revision for revision_id - -- - integer, -- cr_items.item_id%TYPE - integer -- cr_items.parent_id%TYPE -) returns varchar as ' -declare - get_path__item_id alias for $1; - get_path__root_folder_id alias for $2; - v_live_revision cr_items.live_revision%TYPE; -begin - - select live_revision into v_live_revision - from cr_items - where item_id = get_path__item_id; - - return file_storage__get_path( - get_path__item_id, - get_path__root_folder_id, - v_live_revision - ); - -end;' language 'plpgsql'; - - create function file_storage__get_title ( -- -- Unfortunately, title in the file-storage context refers @@ -634,15 +565,17 @@ ); -- register the standard content types + -- JS: Note that we need to set include_subtypes + -- JS: to true since we created a new subtype. PERFORM content_folder__register_content_type( v_folder_id, -- folder_id ''content_revision'', -- content_type - ''f''); -- include_subtypes (default) + ''t''); -- include_subtypes (default) PERFORM content_folder__register_content_type( v_folder_id, -- folder_id ''content_folder'', -- content_type - ''f'' -- include_subtypes (default) + ''t'' -- include_subtypes (default) ); -- Give the creator admin privileges on the folder @@ -689,14 +622,14 @@ from cr_items c1, cr_items c2 where c2.item_id = old.folder_id and c1.tree_sortkey between c2.tree_sortkey and tree_right(c2.tree_sortkey) - and item_id != old.folder_id + and c1.item_id <> old.folder_id order by c1.tree_sortkey desc loop -- We delete the item. On delete cascade should take care -- of deletion of revisions. - if v_rec.content_type = ''content_revision'' + if v_rec.content_type = ''file_storage_object'' then raise notice ''Deleting item_id = %'',v_rec.item_id; PERFORM content_item__delete(v_rec.item_id); @@ -735,3 +668,6 @@ on fs_root_folders for each row execute procedure fs_root_folder_delete_trig (); + +-- Comment out to disable site-wide search interface +\i file-storage-sc-create.sql Index: openacs-4/packages/file-storage/sql/postgresql/file-storage-sc-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/sql/postgresql/file-storage-sc-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/file-storage/sql/postgresql/file-storage-sc-create.sql 18 Dec 2001 20:54:42 -0000 1.1 @@ -0,0 +1,34 @@ +-- Implement site-wide search using OpenFTS +-- +-- packages/file-storage/sql/postgresql/file-storage-sc-create.sql +-- +-- @author Jowell Sabino (jowellsabino@netscape.net) +-- + +--Implement a content provider contract +select acs_sc_impl__new( + 'FtsContentProvider', -- impl_contract_name + 'file_storage_object', -- impl_name (the content_type created above) + 'file-storage' -- impl_owner_name (package key of File Storage) + ); + +-- Implement an association with function 'datasource' and the concrete implementation 'fs__datasource' +select acs_sc_impl_alias__new( + 'FtsContentProvider', -- impl_contract_name + 'file_storage_object', -- impl_name + 'datasource', -- impl_operation_name + 'fs__datasource', -- impl_alias + 'TCL' -- impl_pl +); + +-- Implement an association with function 'url' and the concrete implementation 'fs__url' +select acs_sc_impl_alias__new( + 'FtsContentProvider', -- impl_contract_name + 'file_storage_object', -- impl_name + 'url', -- impl_operation_name + 'fs__url', -- impl_alias + 'TCL' -- impl_pl +); + + + Index: openacs-4/packages/file-storage/sql/postgresql/file-storage-sc-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/sql/postgresql/file-storage-sc-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/file-storage/sql/postgresql/file-storage-sc-drop.sql 18 Dec 2001 20:54:42 -0000 1.1 @@ -0,0 +1,32 @@ +-- Drop site-wide search using OpenFTS +-- +-- packages/file-storage/sql/postgresql/file-storage-sc-drop.sql +-- +-- @author Jowell Sabino (jowellsabino@netscape.net) +-- + +-- Drop association with function 'datasource' and their concrete implementation 'fs__datasource' +select acs_sc_impl_alias__delete( + 'FtsContentProvider', -- impl_contract_name + 'file_storage_object', -- impl_name + 'datasource' -- impl_operation_name + ); + +-- Drop association with function 'url' and their concrete implementation 'fs__url' +select acs_sc_impl_alias__delete( + 'FtsContentProvider', -- impl_contract_name + 'file_storage_object', -- impl_name + 'url' -- impl_operation_name + ); + +-- Drop the search contract implementation +select acs_sc_impl__delete( + 'FtsContentProvider', -- impl_contract_name + 'file_storage_object' -- impl_name (the content_type created above) + ); + + + + + + Index: openacs-4/packages/file-storage/tcl/file-storage-search-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-search-procs-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/file-storage/tcl/file-storage-search-procs-postgresql.xql 18 Dec 2001 20:56:35 -0000 1.1 @@ -0,0 +1,47 @@ + + + + postgresql7.1 + + + + + select r.revision_id as object_id, + i.name as title, + (case i.storage_type + when 'lob' then r.lob::text + when 'file' then '[cr_fs_path]' || r.content + else r.content + end) as content, + r.mime_type as mime, + '' as keywords, + i.storage_type as storage_type + from cr_items i, cr_revisions r + where r.item_id = i.item_id + and r.revision_id = :revision_id + + + + + + select f.package_id as package_id + from fs_root_folders f, + (select i2.parent_id + from cr_items i1, cr_items i2, cr_revisions r + where i1.item_id = r.item_id + and r.revision_id = $revision_id + and i2.tree_sortkey <= i1.tree_sortkey + and i1.tree_sortkey like (i2.tree_sortkey || '%')) as i + where f.folder_id = i.parent_id + + + + + + select site_node__url(node_id) as url_stub + from site_nodes + where object_id=:package_id + + + + Index: openacs-4/packages/file-storage/tcl/file-storage-search-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-search-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/file-storage/tcl/file-storage-search-procs.tcl 18 Dec 2001 20:56:35 -0000 1.1 @@ -0,0 +1,53 @@ +# Site-wide search procs +ad_proc fs__datasource { + revision_id +} { + @author Jowell S. Sabino (jowellsabino@netscape.net) +} { + + db_0or1row fs_datasource " + select r.revision_id as object_id, + i.name as title, + case i.storage_type + when 'lob' then r.lob::text + when 'file' then '[cr_fs_path]' || r.content + else r.content + end as content, + r.mime_type as mime, + '' as keywords, + i.storage_type as storage_type + from cr_items i, cr_revisions r + where r.item_id = i.item_id + and r.revision_id = :revision_id + " -column_array datasource + + return [array get datasource] +} + +ad_proc fs__url { + revision_id +} { + @author Jowell S. Sabino (jowellsabino@netscape.net) +} { + + db_1row fs_get_package_id " + select f.package_id as package_id + from fs_root_folders f, + (select parent.parent_id + from cr_items parent, cr_items children, cr_revisions r + where children.item_id = r.item_id + and r.revision_id = $revision_id + and children.tree_sortkey + between parent.tree_sortkey + and tree_right(parent.tree_sortkey) ) as i + where f.folder_id = i.parent_id + " + + db_1row fs_get_url_stub " + select site_node__url(node_id) as url_stub + from site_nodes + where object_id=:package_id + " + + return "${url_stub}download/index?version_id=$revision_id" +} \ No newline at end of file