Index: openacs-4/contrib/packages/bcms/sql/postgresql/bcms-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/sql/postgresql/bcms-create.sql,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/bcms/sql/postgresql/bcms-create.sql 22 Sep 2003 07:32:52 -0000 1.4 +++ openacs-4/contrib/packages/bcms/sql/postgresql/bcms-create.sql 4 Oct 2003 08:53:05 -0000 1.5 @@ -247,3 +247,98 @@ end if; end;' language 'plpgsql'; + +-- patched root folder with resolve_index fixed +create or replace function content_item__get_id (varchar,integer,boolean) +returns integer as ' +declare + get_id__item_path alias for $1; + get_id__root_folder_id alias for $2; -- default null + get_id__resolve_index alias for $3; -- default ''f'' + v_item_path varchar; + v_root_folder_id cr_items.item_id%TYPE; + get_id__parent_id integer; + child_id integer; + start_pos integer default 1; + end_pos integer; + counter integer default 1; + item_name varchar; +begin + + v_root_folder_id := coalesce(get_id__root_folder_id, + content_item_globals.c_root_folder_id); + + -- If the request path is the root, then just return the root folder + if get_id__item_path = ''/'' then + if get_id__resolve_index = ''t'' then + + -- if the item is a folder and has an index page, then return + + if content_folder__is_folder(v_root_folder_id) = ''t'' and + content_folder__get_index_page(v_root_folder_id) is not null then + + v_root_folder_id := content_folder__get_index_page(v_root_folder_id); + end if; + + end if; + return v_root_folder_id; + end if; + + -- Remove leading, trailing spaces, leading slashes + v_item_path := rtrim(ltrim(trim(get_id__item_path), ''/''), ''/''); + + get_id__parent_id := v_root_folder_id; + + -- if parent_id is a symlink, resolve it + get_id__parent_id := content_symlink__resolve(get_id__parent_id); + + LOOP + + end_pos := instr(v_item_path, ''/'', 1, counter); + + if end_pos = 0 then + item_name := substr(v_item_path, start_pos); + else + item_name := substr(v_item_path, start_pos, end_pos - start_pos); + counter := counter + 1; + end if; + + select + item_id into child_id + from + cr_items + where + parent_id = get_id__parent_id + and + name = item_name; + + if NOT FOUND then + return null; + end if; + + exit when end_pos = 0; + + get_id__parent_id := child_id; + + -- if parent_id is a symlink, resolve it + get_id__parent_id := content_symlink__resolve(get_id__parent_id); + + start_pos := end_pos + 1; + + end loop; + + if get_id__resolve_index = ''t'' then + + -- if the item is a folder and has an index page, then return + + if content_folder__is_folder(child_id ) = ''t'' and + content_folder__get_index_page(child_id) is not null then + + child_id := content_folder__get_index_page(child_id); + end if; + + end if; + + return child_id; + +end;' language 'plpgsql'; Index: openacs-4/contrib/packages/bcms/tcl/bcms-item-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/tcl/bcms-item-procs-postgresql.xql,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/bcms/tcl/bcms-item-procs-postgresql.xql 22 Sep 2003 07:32:52 -0000 1.4 +++ openacs-4/contrib/packages/bcms/tcl/bcms-item-procs-postgresql.xql 4 Oct 2003 08:53:05 -0000 1.5 @@ -45,7 +45,7 @@ i.tree_sortkey, to_char(last_modified,'YYYY-MM-DD HH:MM AM') as last_modified $addtnl_select - from cr_items i + from cr_items i, cr_revisionsx r $addtnl_from where i.parent_id = :parent_id Index: openacs-4/contrib/packages/bcms/tcl/bcms-item-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/tcl/bcms-item-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/bcms/tcl/bcms-item-procs.tcl 22 Sep 2003 07:32:52 -0000 1.4 +++ openacs-4/contrib/packages/bcms/tcl/bcms-item-procs.tcl 4 Oct 2003 08:53:05 -0000 1.5 @@ -122,7 +122,6 @@ ad_proc -public bcms::item::list_items { -parent_id:required {-revision latest} - {-content_type content_revision} {-multirow_name bcms_list_items} {-return_list:boolean false} {-additional_columns} @@ -133,7 +132,6 @@ @param parent_id id of the which contents you wish to list, normally a folder @param revision returns items that have live or latest revision under the parent_id - @param content_type @param multirow_name you can supply your own multirow name @param return_list if supplied a list of ns_sets otherwise it returns a multirow uses the multirow_name if given @@ -159,9 +157,7 @@ # if additional revision data must be returned, set the additional columns here # for revisions. - # lets get the view for the content type - db_1row get_table_name "SQL" - set addtnl_from ", ${table_name}x r" + set addtnl_from "" switch -exact $revision { latest { lappend addtnl_where_list "i.latest_revision = r.revision_id" } @@ -174,11 +170,6 @@ } } - # pick a particular content type - if [info exists content_type] { - lappend addtnl_where_list "content_type = :content_type" - } - # show only a subset of item_id if [info exists show_only] { lappend addtnl_where_list "i.item_id in ($show_only)" @@ -344,7 +335,7 @@ {-root_id:required} {-url:required} {-revision} - {-resolve_index:boolean false} + {-resolve_index:boolean} } { get the content item details based from the url. @@ -375,6 +366,8 @@ array unset yourarray. } { + if {$resolve_index_p} { set resolve_index true } else { set resolve_index false } + set item_id [db_exec_plsql get_item_id "SQL"] if [string equal $item_id ""] { Index: openacs-4/contrib/packages/bcms/tcl/bcms-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/tcl/bcms-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/bcms/tcl/bcms-procs.tcl 4 Aug 2003 11:19:46 -0000 1.2 +++ openacs-4/contrib/packages/bcms/tcl/bcms-procs.tcl 4 Oct 2003 08:53:05 -0000 1.3 @@ -143,6 +143,7 @@ {-page_body ""} {-creation_user_id} {-creation_user_ip} + {-content_type content_revision} } { creates a new page and its first revision @@ -161,7 +162,7 @@ if {![info exists creation_ip]} { set creation_ip [ad_conn peeraddr] } db_transaction { - set page_id [bcms::item::create_item -item_name $page_name -parent_id $folder_id -content_type content_revision \ + set page_id [bcms::item::create_item -item_name $page_name -parent_id $folder_id -content_type $content_type \ -storage_type text -creation_user_id $creation_user_id -creation_ip $creation_ip] set revision_id [bcms::revision::add_revision -item_id $page_id \ @@ -173,3 +174,49 @@ return $page_id } + +ad_proc -public bcms::upload_file { + {-file_name:required} + {-folder_id:required} + {-title:required} + {-description ""} + {-upload_file:required} + {-creation_user_id} + {-creation_user_ip} + {-content_type content_revision} +} { + uploads a new file and its first revision + + @param file_name name of the file which will be used for the url + @param folder_id the folder_id which the file will be under + @param mime_type mime_type of the file + @param title title of the file + @param description description of the file + @param upload_file the file you want to upload + @param creation_user_id user_id creating this page + @param creation_user_ip ip address which this page is created + + @returns the file_id of the newly created file +} { + if {![info exists creation_user_id]} { set creation_user_id [ad_conn user_id] } + if {![info exists creation_ip]} { set creation_ip [ad_conn peeraddr] } + + # get the file properties + set upload_filename [template::util::file::get_property filename $upload_file] + set upload_tmpfile [template::util::file::get_property tmp_filename $upload_file] + set upload_mime_type [template::util::file::get_property mime_type $upload_file] + + db_transaction { + set file_id [bcms::item::create_item -item_name $file_name -parent_id $folder_id -content_type $content_type \ + -storage_type file -creation_user_id $creation_user_id -creation_ip $creation_ip] + + set revision_id [bcms::revision::upload_file_revision -item_id $file_id \ + -title $title -description $description \ + -upload_filename $upload_filename -upload_tmpfile $upload_tmpfile -mime_type $upload_mime_type \ + -creation_user_id $creation_user_id -creation_ip $creation_ip] + + } + + return $file_id + +} Index: openacs-4/contrib/packages/bcms/tcl/bcms-revision-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/tcl/bcms-revision-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/bcms/tcl/bcms-revision-procs.tcl 22 Sep 2003 07:32:52 -0000 1.4 +++ openacs-4/contrib/packages/bcms/tcl/bcms-revision-procs.tcl 4 Oct 2003 08:53:05 -0000 1.5 @@ -6,13 +6,13 @@ @creation-date 06 Oct 2002 @cvs-id $Id$ -TODO: refactor the creation_user_id "" to something ad_conn TODO: add back the lob support } namespace eval bcms::revision {} +# TODO merge with upload_file_revision ad_proc -public bcms::revision::add_revision { {-item_id:required} {-title:required} @@ -22,13 +22,39 @@ {-content ""} {-creation_user_id} {-creation_ip} + {-additional_properties} } { - Adds a new revision to a content item stored in the cr_revision.content column. - Normally you will use your own proc patterned after this proc + Adds a new revision, you pass additional properties/columns for your custom + content type + + @param item_id item_id of this revision is adding to + @param title title of the revision + @param content_type content_type of the item, if not passed it will determine the content_type + @param mime_type mime type of this revision + @param description description of the revision + @param content content of the revision + @param creation_user_id user_id creating this item + @param creation_user_ip ip address which this item is created + @param additional_properites a list of additional properties / columns to insert format: {property value ... property value} + + @returns revision_id of newly created revision } { if {![info exists creation_user_id]} { set creation_user_id [ad_conn user_id] } if {![info exists creation_ip]} { set creation_ip [ad_conn peeraddr] } + # create the additional properties + set addtnl_properties "" + set addtnl_values "" + set addtnl_properties_list {} + set addtnl_values_list {} + foreach {property value} $additional_properties { + lappend addtnl_properties_list $property + lappend addtnl_values_list :__$property + set __$property $value + } + set addtnl_properties ",[join $addtnl_properties_list ","]" + set addtnl_values ",[join $addtnl_values_list ","]" + if ![info exists content_type] { set content_type [bcms::item::get_content_type -item_id $item_id] } @@ -39,32 +65,41 @@ db_dml insert_revision "SQL" } - ns_log notice "bcms::revision::revision_create_in_text created new revision $revision_id" + ns_log notice "bcms::revision::add_revision created new revision $revision_id" return $revision_id } ad_proc -public bcms::revision::upload_file_revision { {-item_id:required} - {-revision_id} - {-title ""} + {-title:required} {-content_type} {-description ""} {-upload_tmpfile:required} {-upload_filename:required} {-mime_type "application/octet-stream"} - {-creation_user_id ""} - {-creation_ip ""} + {-creation_user_id} + {-creation_ip} + {-additional_properties} } { Adds a new revision to a content item stored in file system at acs_root/content-repository-content-files. - Normally you will use your own proc patterned after this proc - TODO: think about merging this with edit_revision since - now its also used for editing - also lets just accept the upload_file and get the tmpfile and mimetype - inside the proc + @param item_id item_id of this revision is adding to + @param title title of the revision + @param content_type content_type of the item, if not passed it will determine the content_type + @param mime_type mime type of this revision + @param description description of the revision + @param upload_tmpfile + @param upload_filename + @param creation_user_id user_id creating this item + @param creation_user_ip ip address which this item is created + @param additional_properites a list of additional properties / columns to insert format: {property value ... property value} + } { + if {![info exists creation_user_id]} { set creation_user_id [ad_conn user_id] } + if {![info exists creation_ip]} { set creation_ip [ad_conn peeraddr] } + if ![info exists content_type] { set content_type [bcms::item::get_content_type -item_id $item_id] } @@ -79,6 +114,19 @@ db_dml new_mime_type "SQL" } + # create the additional properties + set addtnl_properties "" + set addtnl_values "" + set addtnl_properties_list {} + set addtnl_values_list {} + foreach {property value} $additional_properties { + lappend addtnl_properties_list $property + lappend addtnl_values_list :__$property + set __$property $value + } + set addtnl_properties ",[join $addtnl_properties_list ","]" + set addtnl_values ",[join $addtnl_values_list ","]" + db_transaction { # if we are editing a existing revision then lets get the next object_id if ![info exists revision_id] { @@ -94,8 +142,7 @@ # since we are using the file system we will set content to the filename in the fs set content $tmp_filename - if $insert_revision_p { - # we do not need to reinsert an existing revision + if {$insert_revision_p} { db_dml insert_revision "SQL" } db_dml update_file_size "SQL" Index: openacs-4/contrib/packages/bcms/tcl/bcms-revision-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/tcl/bcms-revision-procs.xql,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/bcms/tcl/bcms-revision-procs.xql 27 Aug 2003 17:23:27 -0000 1.2 +++ openacs-4/contrib/packages/bcms/tcl/bcms-revision-procs.xql 4 Oct 2003 08:53:05 -0000 1.3 @@ -5,16 +5,16 @@ insert into ${table_name}i - (revision_id, object_type, creation_user, creation_date, creation_ip, title, description, item_id, text, mime_type) - values (:revision_id, :content_type, :creation_user_id, now(), :creation_ip, :title, :description, :item_id, :content, :mime_type) + (revision_id, object_type, creation_user, creation_date, creation_ip, title, description, item_id, text, mime_type $addtnl_properties) + values (:revision_id, :content_type, :creation_user_id, now(), :creation_ip, :title, :description, :item_id, :content, :mime_type $addtnl_values) insert into ${table_name}i - (object_type, creation_user, creation_date, creation_ip, title, description, item_id, revision_id, text, mime_type) - values (:content_type, :creation_user_id, now(), :creation_ip, :title, :description, :item_id, :revision_id, :content, :mime_type) + (object_type, creation_user, creation_date, creation_ip, title, description, item_id, revision_id, text, mime_type $addtnl_properties) + values (:content_type, :creation_user_id, now(), :creation_ip, :title, :description, :item_id, :revision_id, :content, :mime_type $addtnl_values)