Index: openacs.org-dev/www/bboard-migr/user-migr.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/www/bboard-migr/user-migr.tcl,v diff -u -r1.2 -r1.3 --- openacs.org-dev/www/bboard-migr/user-migr.tcl 12 Jul 2002 12:53:35 -0000 1.2 +++ openacs.org-dev/www/bboard-migr/user-migr.tcl 15 Jul 2002 13:26:44 -0000 1.3 @@ -1,13 +1,16 @@ set olddb [ns_db gethandle acs32] -# NOTE: only migrates minimum: email, name, passwd, url +# NOTE: only migrates minimum: email, name, passwd, url, registration_date # for posting users +# added where and order by clauses (olah) set selection [ns_db select $olddb " select last_name, first_names, email, password, url, user_id as old_user_id, registration_date from users + where user_state ='authorized' + order by user_id "] set n_tried_old 0 @@ -21,39 +24,54 @@ from migr_user_map where old_user_id=:old_user_id" -set nil [set new [set map [list]]] +set nil [set new [set map [set update [list]]]] set output "" db_transaction { while { [ns_db getrow $olddb $selection] } { set_variables_after_query incr n_tried_old if [db_0or1row tt $new_user_sql] { + # a user with this email address is already on the new system. + # if the accompanying user_id is not already in the mapping table, we insert a row. + # (we check this because someone may register with the new site + # before we even run this script and will thus not exist in the mapping table.) if [db_0or1row r $mapped_user_sql] { + # this user_id has been mapped before, i.e, has been migrated. set new_id $new_map_id set action "nil" } else { + # user has registered with the new site and is therefore not yet + # in the mapping table. db_dml q "insert into migr_user_map (old_user_id, new_user_id) values ($old_user_id, $new_lookup_id)" set new_id $new_lookup_id set action "map" } + } elseif {[empty_string_p $first_names] || [empty_string_p $last_name] || [empty_string_p $email]} { + # we safeguard against empty columns in the users table. set action "nil" } elseif {[db_0or1row tr $mapped_user_sql]} { - set new_created_id [ad_user_new $email $first_names $last_name $password - "" "" $url "t" "approved" $new_map_id $registration_date] + # this email address is not on the new system but the user_id has been + # mapped before. the user probably changed email address since the last + # pass of this script... let's create a new user (or should we update the email address). + + set new_created_id [ad_user_new $email $first_names $last_name $password "" "" $url "t" "approved" $new_map_id $registration_date] + #set new_created_id [ad_user_new $email $first_names $last_name $password "" "" $url "t" "approved" "" $registration_date] set new_id $new_map_id set action "update" + } else { + # this email address is not on the new system, nor has the user_id been + # mapped before. let's create this previously unseen user and register + # the event in the mapping table. + set new_created_id [ad_user_new $email $first_names $last_name $password "" "" $url "t" "approved" "" $registration_date] db_dml q "insert into migr_user_map (old_user_id, new_user_id) values ($old_user_id, $new_created_id)" - -# set new_created_id newtest - set new_id $new_created_id set action "new" } @@ -74,11 +92,23 @@ ns_return 200 text/html " Migratonicuserfama -

Migrating Users

-

Unsorted Output:

$output

Sorted Output:

-

[llength $nil] nil -- users already created & mapped

[join $nil]

-

[llength $map] map -- users already created, but unmapped

[join $map]

-

[llength $new] new -- uncreated and unmapped

[join $new]

+

Migrating Users

+ + + + + +
+

Unsorted Output:

+

$n_tried_old actions

+ $output +
+

Sorted Output:

+

[llength $nil] nil -- users already created & mapped

[join $nil] +

[llength $map] map -- users already created, but unmapped

[join $map] +

[llength $update] update -- uncreated, but mapped

[join $update] +

[llength $new] new -- uncreated and unmapped

[join $new] +
"