Index: openacs-4/packages/static-pages/static-pages.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/static-pages.info,v diff -u -r1.7 -r1.8 --- openacs-4/packages/static-pages/static-pages.info 19 Oct 2001 02:11:55 -0000 1.7 +++ openacs-4/packages/static-pages/static-pages.info 23 Oct 2001 18:53:36 -0000 1.8 @@ -34,6 +34,7 @@ + Index: openacs-4/packages/static-pages/sql/postgresql/static-pages-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/sql/postgresql/static-pages-create.sql,v diff -u -r1.8 -r1.9 --- openacs-4/packages/static-pages/sql/postgresql/static-pages-create.sql 19 Oct 2001 02:11:55 -0000 1.8 +++ openacs-4/packages/static-pages/sql/postgresql/static-pages-create.sql 23 Oct 2001 18:53:36 -0000 1.9 @@ -15,7 +15,6 @@ -- **/ -- set def off - create table sp_folders ( folder_id integer constraint sp_folders_folder_id_pk primary key @@ -62,15 +61,24 @@ v_parent_sk varchar; max_key varchar; begin - select max(tree_sortkey) into max_key + if new.parent_id is null then + select max(tree_sortkey) into max_key + from sp_folders + where parent_id is null; + + v_parent_sk := ''''; + else + + select max(tree_sortkey) into max_key from sp_folders where parent_id = new.parent_id; select coalesce(max(tree_sortkey),'''') into v_parent_sk from sp_folders - where folder_id = new.folder_id; + where folder_id = new.parent_id; new.tree_sortkey := v_parent_sk || ''/'' || tree_next_key(max_key); + end if; return new; @@ -240,10 +248,7 @@ 'varchar(500)' -- column_spec ); - - -- create or replace package body static_page as --- create or replace package body static_page as create function static_page__new ( integer, -- static_page_id in static_pages.static_page_id%TYPE -- default null, @@ -298,7 +303,10 @@ v_mime_type, -- mime_type p_content, -- text v_storage_type, -- storage_type - FALSE -- security_inherit_p + FALSE, -- security_inherit_p + ''STATIC_PAGES'', -- storage_area_key + ''static_page'', -- item subtype + ''static_page'' -- content_type ); @@ -372,15 +380,21 @@ ) returns integer as ' declare p_static_page_id alias for $1; - v_comment_row general_comments.comment_id%TYPE; + v_comment_row RECORD; + v_rec_affected integer; + v_static_page_id integer; begin -- Delete all permissions on this page: - delete from acs_permissions where object_id = p_static_page_id; +RAISE NOTICE ''***Deleting id:%'',p_static_page_id; + + delete from acs_permissions where object_id = p_static_page_id; + -- Drop all comments on this page. general-comments doesn''t have -- a comment.delete() function, so I just do this (see the -- general-comments drop script): - for v_comment_row in + + for v_comment_row in select comment_id from general_comments where object_id = p_static_page_id loop @@ -391,15 +405,24 @@ where parent_id = v_comment_row ); - PERFORM acs_message__delete(v_comment_row); + PERFORM acs_message__delete(v_comment_row.comment_id); end loop; -- Delete the page. -- WE SHOULDN''T NEED TO DO THIS: CONTENT_ITEM.DELETE SHOULD TAKE CARE OF -- DELETING FROM STATIC PAGES. - delete from static_pages where static_page_id = p_static_page_id; - PERFORM content_item__delete(p_static_page_id); - return 0; + + delete from static_pages where static_page_id = p_static_page_id; + + GET DIAGNOSTICS v_rec_affected = ROW_COUNT; + RAISE NOTICE ''*** Number of rows deleted: %'',v_rec_affected; + select into v_static_page_id static_page_id from static_pages where static_page_id = p_static_page_id; + GET DIAGNOSTICS v_rec_affected = ROW_COUNT; + RAISE NOTICE ''*** selected % rows still in static_pages'',v_rec_affected; + + + PERFORM content_item__delete(p_static_page_id); +return 0; end;' language 'plpgsql'; create function static_page__get_root_folder ( @@ -409,7 +432,8 @@ p_package_id alias for $1; v_folder_exists_p integer; v_folder_id sp_folders.folder_id%TYPE; - begin + v_rows integer; +begin -- If there isn''t a root folder for this package, create one. -- Otherwise, just return its id. select count(*) into v_folder_exists_p where exists ( @@ -457,7 +481,6 @@ return v_folder_id; end;' language 'plpgsql'; - create function static_page__new_folder ( integer, -- folder_id in sp_folders.folder_id%TYPE -- default null, @@ -489,7 +512,7 @@ v_parent_id cr_items.parent_id%TYPE; v_package_id apm_packages.package_id%TYPE; v_creation_date acs_objects.creation_date%TYPE; - v_permission_row acs_permissions%ROWTYPE; + v_permission_row RECORD; begin if p_creation_date is null then v_creation_date := now(); @@ -512,7 +535,8 @@ p_folder_id, -- folder_id v_creation_date, -- creation_date p_creation_user, -- creation_user - p_creation_ip -- creation_ip + p_creation_ip, -- creation_ip + ''f'' -- secuity_inherit_p ); @@ -524,8 +548,8 @@ insert into sp_folders (folder_id, parent_id, package_id) values (v_folder_id, p_parent_id, v_package_id); - update acs_objects set security_inherit_p = ''f'' - where object_id = v_folder_id; +-- update acs_objects set security_inherit_p = ''f'' +-- where object_id = v_folder_id; -- Copy permissions from the parent: for v_permission_row in @@ -569,27 +593,28 @@ ) returns integer as ' declare p_folder_id alias for $1; - v_folder_row sp_folders.folder_id%TYPE; - v_page_row static_pages.static_page_id%TYPE; + v_folder_row RECORD; + v_page_row RECORD; begin for v_folder_row in select folder_id from ( select folder_id, tree_level(''folder_id'') as path_depth from sp_folders where tree_sortkey like ( select tree_sortkey || ''%'' from sp_folders where folder_id = p_folder_id) - ) order by path_depth desc + ) folders order by path_depth desc loop for v_page_row in select static_page_id from static_pages - where folder_id = v_folder_row + where folder_id = v_folder_row.folder_id loop - static_page__delete(v_page_row); + PERFORM static_page__delete(v_page_row.static_page_id); end loop; - delete from sp_folders where folder_id = v_folder_row; - PERFORM content_folder__delete(v_folder_row); + delete from sp_folders where folder_id = v_folder_row.folder_id; + PERFORM content_folder__delete(v_folder_row.folder_id); end loop; +return 0; end;' language 'plpgsql'; create function static_page__delete_stale_items ( @@ -600,48 +625,45 @@ p_session_id alias for $1; p_package_id alias for $2; v_root_folder_id sp_folders.folder_id%TYPE; - v_stale_file_row static_pages%ROWTYPE; - v_stale_folder_row sp_folders%ROWTYPE; + v_stale_file_row RECORD; + v_stale_folder_row RECORD; begin v_root_folder_id := static_page__get_root_folder(p_package_id); - -- First delete all files that are descendants of the root folder - -- but aren''t in sp_extant_files + -- First delete all files that are descendants of the root folder + -- but aren''t in sp_extant_files - for v_stale_file_row in - select static_page_id from static_pages - where static_page_id not in ( - select static_page_id - from sp_extant_files - where session_id = p_session_id - ) - --- where folder_id in ( --- select folder_id from sp_folders --- where tree_sortkey like ( select tree_sortkey || ''%'' --- from sp_folders --- where folder_id = v_root_folder_id) --- ) and static_page_id not in ( --- select static_page_id --- from sp_extant_files --- where session_id = p_session_id --- ) - loop - PERFORM static_page__delete(v_stale_file_row); - end loop; + for v_stale_file_row in + select static_page_id from static_pages + where folder_id in ( + select folder_id from sp_folders + where tree_sortkey like ( + select tree_sortkey || ''%'' + from sp_folders + where folder_id = v_root_folder_id ) + ) + and + static_page_id not in ( + select static_page_id from + sp_extant_files + where session_id = p_session_id ) + loop - -- Now delete all folders that aren''t in sp_extant_folders. There are two - -- views created on the fly here: dead (all descendants of the root - -- folder not in sp_extant_folders) and path (each folder and its depth). - -- They are joined together to get the depth of all the folders that - -- need to be deleted. The root folder is excluded because it won''t - -- show up in the filesystem search, so it will be missing from - -- sp_extant_folders. - -- - for v_stale_folder_row in - select dead.folder_id from + PERFORM static_page__delete(v_stale_file_row.static_page_id); + end loop; + +-- Now delete all folders that aren''t in sp_extant_folders. There are two +-- views created on the fly here: dead (all descendants of the root +-- folder not in sp_extant_folders) and path (each folder and its depth). +-- They are joined together to get the depth of all the folders that +-- need to be deleted. The root folder is excluded because it won''t +-- show up in the filesystem search, so it will be missing from +-- sp_extant_folders. + + for v_stale_folder_row in + select dead.folder_id from (select folder_id from sp_folders - where (folder_id) not in ( + where folder_id not in ( select folder_id from sp_extant_folders where session_id = p_session_id @@ -657,12 +679,14 @@ order by path.depth desc loop delete from sp_folders - where folder_id = v_stale_folder_row; + where folder_id = v_stale_folder_row.folder_id; - perform content_folder__delete(v_stale_folder_row); + perform content_folder__delete(v_stale_folder_row.folder_id); end loop; - return 0; + +return 0; end;' language 'plpgsql'; + create function static_page__grant_permission ( integer, -- item_id in acs_permissions.object_id%TYPE, @@ -718,6 +742,7 @@ return 0; end;' language 'plpgsql'; + create function static_page__revoke_permission ( integer, -- item_id in acs_permissions.object_id%TYPE, integer, -- grantee_id in acs_permissions.grantee_id%TYPE, Index: openacs-4/packages/static-pages/tcl/static-pages-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/tcl/static-pages-procs-postgresql.xql,v diff -u -r1.7 -r1.8 --- openacs-4/packages/static-pages/tcl/static-pages-procs-postgresql.xql 19 Oct 2001 02:11:55 -0000 1.7 +++ openacs-4/packages/static-pages/tcl/static-pages-procs-postgresql.xql 23 Oct 2001 18:53:36 -0000 1.8 @@ -25,16 +25,16 @@ select static_page__new_folder ( - NULL, - :directory, -- name + NULL, -- folder_id + :directory, -- name :directory, -- label - 'Static pages folder', -- description - :parent_folder_id, -- parent_id - current_timestamp, - NULL, - NULL, - NULL - ); + 'Static pages folder', -- description + :parent_folder_id, -- parent_id + current_timestamp, -- creation_date + NULL, -- creation_user + NULL, -- creation_ip + NULL -- context_id + ); @@ -53,7 +53,7 @@ select static_page__new( :parent_folder_id, -- folder_id - :file, -- filename + :sp_filename, -- filename :page_title -- title ); @@ -76,8 +76,6 @@ begin perform static_page__delete_stale_items(:sync_session_id,:package_id); --- delete from sp_extant_folders where session_id = :sync_session_id; --- delete from sp_extant_files where session_id = :sync_session_id; return null; end; Index: openacs-4/packages/static-pages/tcl/static-pages-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/tcl/static-pages-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/static-pages/tcl/static-pages-procs.tcl 4 Sep 2001 17:04:10 -0000 1.4 +++ openacs-4/packages/static-pages/tcl/static-pages-procs.tcl 23 Oct 2001 18:53:36 -0000 1.5 @@ -43,7 +43,7 @@ @param folder_unchanged_proc The name of a Tcl proc to be called for each folder unchanged in the database. - @param fs_root The starting path in the filesystem. Files below this point will + @param fs_root The starting path in the filesystem. This is relative to the openacs install directory, Files below this point will be scanned. @param root_folder_id The id of the root folder in the static-pages system (and in @@ -115,10 +115,14 @@ # If the file isn't in the db: # Insert it. - set fs_filename $file + # set sp_filename to the file path relative to the OpenACS + # install dir, this is what gets inserted into the db - DaveB + set sp_filename [sp_get_relative_file_path $file] + + if [db_0or1row check_db_for_page { select static_page_id from static_pages - where filename = :fs_filename + where filename = :sp_filename }] { db_1row get_db_page { select content as file_from_db from cr_revisions @@ -175,7 +179,7 @@ set static_page_id [db_exec_plsql do_sp_new { begin :1 := static_page.new( - filename => :file, + filename => :sp_filename, title => :page_title, folder_id => :parent_folder_id ); @@ -305,6 +309,26 @@ " } +ad_proc -private sp_get_full_file_path { file } { + takes a relative path and returns the full file path +} { + set full_path [cr_fs_path STATIC_PAGES] + append full_path $file + return $full_path +} + +ad_proc -private sp_get_relative_file_path { file } { + Takes a full file path and returns the path relative to the + static-page storage directory, usualyl /web/openacs/www/ +} { + set relative_path [string range $file [string length [cr_fs_path STATIC_PAGES]] end] + + ns_log notice "**[cr_fs_path STATIC_PAGES]**" + ns_log notice "relative path:$relative_path" + return $relative_path +} + + ad_proc -private sp_get_page_info_query { page_id } { Returns a SQL query to get the page title and comment display policy. @@ -343,9 +367,10 @@ @creation-date 2001-01-23 } { set filename [ad_conn file] + set sp_filename [sp_get_relative_file_path $filename] + + set page_id [util_memoize [list sp_get_page_id $sp_filename]] - set page_id [util_memoize [list sp_get_page_id $filename]] - # If the page is in the db, serve it carefully; otherwise just dump it out. if { $page_id >= 0 } { set page_info [util_memoize [list sp_get_page_info_query $page_id]] Index: openacs-4/packages/static-pages/tcl/static-pages-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/tcl/static-pages-procs.xql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/static-pages/tcl/static-pages-procs.xql 4 Sep 2001 17:04:10 -0000 1.5 +++ openacs-4/packages/static-pages/tcl/static-pages-procs.xql 23 Oct 2001 18:53:36 -0000 1.6 @@ -15,7 +15,7 @@ select static_page_id from static_pages - where filename = :fs_filename + where filename = :sp_filename