Index: openacs.org-dev/www/bboard-migr/subs-forum-migr.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/www/bboard-migr/subs-forum-migr.tcl,v diff -u -r1.1 -r1.2 --- openacs.org-dev/www/bboard-migr/subs-forum-migr.tcl 10 Jul 2002 19:29:04 -0000 1.1 +++ openacs.org-dev/www/bboard-migr/subs-forum-migr.tcl 29 Jul 2002 09:03:13 -0000 1.2 @@ -1,14 +1,18 @@ #hardcode if you're not in the correct package instance... +# which package are we using +#set bboard_package "bboard" +set bboard_package "forums" + #set package_id [ad_conn package_id] -set package_id 3189 +set package_id 3061 set olddb [ns_db gethandle acs32] set n_tried_old 0 set selection [ns_db select $olddb " -select user_id, topic_id from bboard_email_alerts +select user_id, topic_id, frequency from bboard_email_alerts order by topic_id"] set forum_mapping_sql " @@ -25,53 +29,82 @@ #note: no migr_map neccessary for subscriptions # or even possible -- covered by user and topic map -set mapped_subs_sql " -select forum_id || '-' || subscriber_id as new_map_id - from bboard_forum_subscribers -where forum_id = :new_forum_id -and subscriber_id = :new_user_id" +if {[string equal $bboard_package "bboard"]} { + set mapped_subs_sql " + select forum_id || '-' || subscriber_id as new_map_id + from bboard_forum_subscribers + where forum_id = :new_forum_id + and subscriber_id = :new_user_id" -set map_subs_sql " -insert into bboard_forum_subscribers -(forum_id, subscriber_id) values -(:new_forum_id, :new_user_id)" + set map_subs_sql " + insert into bboard_forum_subscribers + (forum_id, subscriber_id) values + (:new_forum_id, :new_user_id)" -set nil [set new [list]] -set output "" +} else { + # assume it's the new "forums" package -db_transaction { -while { [ns_db getrow $olddb $selection] } { - set_variables_after_query - - #also lookup forum and user mapping - db_1row q $forum_mapping_sql - db_1row q $user_mapping_sql + set type_id [notification::type::get_type_id -short_name forums_forum_notif] + set delivery_method_id [notification::get_delivery_method_id -name "email"] - incr n_tried_old + set mapped_subs_sql " + select request_id as new_map_id + from notification_requests + where type_id = :type_id + and user_id = :new_user_id + and object_id = :new_forum_id +" +} - if [db_0or1row r $mapped_subs_sql] { - ##already mapped, sets new_map_id - set new_id $new_map_id - set action "nil" - } else { - #it's new; insert it. - db_dml q $map_subs_sql - set new_id "$new_forum_id-$new_user_id" - set action "new" - } - set html " - forum-user: $new_id -
" +set nil [set new [list]] +set output "" - lappend $action $html - - append output "$action: $html" + while { [ns_db getrow $olddb $selection] } { + set_variables_after_query + +db_transaction { + #also lookup forum and user mapping + db_1row q $forum_mapping_sql + db_1row q $user_mapping_sql + + incr n_tried_old + + if [db_0or1row r $mapped_subs_sql] { + ##already mapped, sets new_map_id + set new_id $new_map_id + set action "nil" + } else { + #it's new; insert it. + if {[string equal $bboard_package "bboard"]} { + #TODO: add notification frequency migr code (olah) + db_dml q $map_subs_sql + } else { + # assume it's the new "forums" package + if {[string equal $frequency "Monday/Thursday"]} { + set frequency "every other day" + } + set interval_id [notification::get_interval_id $frequency] + set request_id [notification::request::new -type_id $type_id \ + -user_id :new_user_id -object_id :new_forum_id \ + -interval_id $interval_id \ + -delivery_method_id $delivery_method_id -format "text"] + } + set new_id "$new_forum_id-$new_user_id" + set action "new" + } + + set html " + forum-user: $new_id +
" + lappend $action $html + + append output "$action: $html" + } on_error { + set output "

Error:

$errmsg


$output" + } } -} on_error { - set output "

Error:

$errmsg


$output" -} ns_db releasehandle $olddb