# packages/lorsm/www/export/index.vuh ad_page_contract { Export IMS Content Packages from the Content Repository @author Ernie Ghiglione (ErnieG@mm.st) @creation-date 2004-04-15 @arch-tag 59c959a1-a9ce-450d-a33e-5221db50abd7 @cvs-id $Id: index.vuh,v 1.3 2009/04/21 16:47:19 emmar Exp $ } -query { {folder_id:integer,optional} } set user_id [ad_conn user_id] # check write permisssion to export the course # Based on Yun's file system exports if {[exists_and_not_null folder_id]} { permission::require_write_permission -object_id $folder_id -creation_user $user_id set download_name [fs::get_file_system_safe_object_name -object_id $folder_id] set download_name [util_text_to_url -no_resolve -text $download_name] # We get rid of spaces since they are annoying regsub -all { } $download_name {_} download_name set tmp_dir $download_name set ext "zip" if {![empty_string_p $ext]} { append download_name ".${ext}" } ad_returnredirect "${folder_id}/${download_name}" ad_script_abort } # convenient way to get the values out of a list foreach {folder_id download_name} [split [ad_conn path_info] /] {break} if {![fs::object_p -object_id $folder_id]} { ad_return_complaint 1 "Object \#$folder_id is not a file storage object." ad_script_abort } set user_id [ad_conn user_id] if {$user_id == 0} { set user_id "" } # publish the object to the file system set in_path [ns_tmpnam] file mkdir $in_path set file [fs::publish_object_to_file_system -object_id $folder_id -path $in_path -user_id $user_id] set file_name [file tail $file] # create a temp dir to put the archive in set out_path [ns_tmpnam] file mkdir $out_path set out_file [file join ${out_path} ${download_name}] # get the archive command #set cmd [fs::get_archive_command -in_file $file_name -out_file $out_file] set cmd "zip -r '$out_file' *" # create the archive with_catch errmsg { exec bash -c "cd \"$file\" && $cmd; cd -" } { # some day we'll do something useful here error $errmsg } # return the archive to the connection. ns_returnfile 200 application/octet-stream $out_file # clean everything up exec rm -fr $in_path exec rm -fr $out_path