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.11.2.10 -r1.11.2.11 --- openacs-4/packages/static-pages/tcl/static-pages-procs.tcl 20 Jan 2003 16:04:07 -0000 1.11.2.10 +++ openacs-4/packages/static-pages/tcl/static-pages-procs.tcl 22 Jan 2003 21:01:37 -0000 1.11.2.11 @@ -378,7 +378,6 @@ set mesg "$proc_name: Error reading file: '$file': [ns_quotehtml $errmsg]" ns_log Error $mesg if { ![empty_string_p $file_read_error_proc] } { - ns_log Notice "$proc_name: about to run file_read_error_proc:" uplevel $stack_depth [list $file_read_error_proc $file $static_page_id $mesg] } continue @@ -449,7 +448,6 @@ set mesg "$proc_name: Error reading file: '$file': [ns_quotehtml $errmsg]" ns_log Error $mesg if { ![empty_string_p $file_read_error_proc] } { - ns_log Notice "$proc_name: about to run file_read_error_proc:" uplevel $stack_depth [list $file_read_error_proc $file $static_page_id $mesg] } continue @@ -475,17 +473,33 @@ # locking. --atp@piskorski.com, 2001/08/27 01:20 EDT set mime_type [sp_maybe_create_new_mime_type $sp_filename] - set static_page_id [db_exec_plsql do_sp_new {}] - # Check if -blobs [list $file_contents] would be faster: - db_dml insert_file_contents {} -blob_files [list $file] - if { [string length $file_add_proc] > 0 } { - uplevel $stack_depth "$file_add_proc $file $static_page_id" - } - db_dml insert_file { - insert into sp_extant_files (session_id,static_page_id) - values (:sync_session_id,:static_page_id) - } + if { [catch { + set static_page_id [db_exec_plsql do_sp_new {}] + } errmsg] } { + # Something failed: + + set mesg "$proc_name: do_sp_new failed for file '$file' with error: [ns_quotehtml $errmsg]" + ns_log Error $mesg + if { ![empty_string_p $file_read_error_proc] } { + uplevel $stack_depth [list $file_read_error_proc $file $static_page_id $mesg] + } + continue + + } else { + # Everything is ok: + + # Check if -blobs [list $file_contents] would be faster: + db_dml insert_file_contents {} -blob_files [list $file] + + if { [string length $file_add_proc] > 0 } { + uplevel $stack_depth "$file_add_proc $file $static_page_id" + } + db_dml insert_file { + insert into sp_extant_files (session_id,static_page_id) + values (:sync_session_id,:static_page_id) + } + } } } } @@ -686,68 +700,91 @@ ad_proc sp_maybe_create_new_mime_type { file_name } { - This proc should be identical to fs_maybe_create_new_mime_type - from the file-storage package. However, we don't want to depend - on file-storage being loaded, so if it isn't, define our own - implementation here. --atp@piskorski.com, 2002/12/15 19:34 EST + Contrary to the name, this proc does not ever insert a + new MIME type into the cr_mime_types table the way the + fs_maybe_create_new_mime_type proc does. That File Storage proc + and the design cr_mime_types table it mucks with are fundamentally + flawed, and (c. Jan. 2003) there have been several major threads + in BBoard about that already: + + one, + two, + three. + + And the old side-effecting implementation that inserted into + cr_mime_types led to some of the problems discussed in + Bug 145. +

- The content repository expects the MIME type to already be defined - when you upload content. We use this procedure to add a new type - when we encounter something we haven't seen before. + The content repository insists that the MIME type already + be defined in cr_mime_types when you upload content. Therefore, + first we look for a MIME type for this file extension in + cr_mime_types. If we can't find a MIME type there, we might also + want to look in the AOLserver config file, but, that + would break things because the MIME type must be in + cr_mime_types. If you have MIME types defined in your AOLserve + config file but not in cr_mime_types, you should add them to + cr_mime_types. - @author Andrew Piskorski (atp@piskorski.com) - @creation-date 2002-12-15 -} { - set proc_name {sp_maybe_create_new_mime_type} - set func {fs_maybe_create_new_mime_type} +

+ If no more specific MIME type for the file extension is found, we + return the "*/*" unknown MIME type. - if { [nsv_exists api_proc_doc $func] || - ![empty_string_p [namespace eval :: [list info procs $func]]] - } { - # The file-storage version of this proc exists, use it: - return [eval [list $func $file_name]] +

+ Known Bugs: +

- db_dml new_mime_type { - insert into cr_mime_types - (mime_type, file_extension) - values - (:mime_type, :file_extension) - } - } - return $mime_type +

+ --atp@piskorski.com, 2003/01/22 15:16 EST + + @author Andrew Piskorski (atp@piskorski.com) + @creation-date 2002-12-15 +} { + set proc_name {sp_maybe_create_new_mime_type} + set mime_type_unknown {*/*} + + set file_extension [string trimleft [file extension $file_name] "."] + if {[empty_string_p $file_extension]} { + set mime_type $mime_type_unknown } + + if {![db_0or1row select_mime_type { + select mime_type + from cr_mime_types + where file_extension = :file_extension + }]} { + set mime_type $mime_type_unknown + + #set nsd_mime_type [ns_guesstype $file_name] + #if { ![string equal $mime_type $nsd_mime_type] } { + # ns_log Warning "$proc_name: For file extension '$file_extension', the only matching MIME type in cr_mime_types is '$mime_type', but AOLserver thinks the MIME type should be '$nsd_mime_type'." + #} + } + + return $mime_type }