#!/usr/bin/tclsh package require helga puts "This script will migrate your Helga users from an install of Helga v0.2 to a local install of Helga v1.0." puts "You must be a site administrator to perform project migration. Please enter your v1.0 Helga login information." if { [catch hlogin out] } { puts $out exit 1 } if { [catch "::helga::user::checkPermissions admin /" out] } { puts "Error: You are not a site administrator and therefore may not perform user migration. Please contact a site adminstrator to do this for you." exit 1 } puts "Before we do anything, we're going to back up your v1.0 database in its current state." set sqlFileName "$::HELGASITEROOT/tmp/$::SQLDB.backup.[clock seconds].sql" puts -nonewline "Backing up db to $sqlFileName..." exec mysqldump --user=helgaAdmin --password=$::ADMINSQLPASS $::SQLDB > $sqlFileName puts "done." puts "Now: the first step in the migration process is to temporarily copy your old database to your local v1.0 MySQL setup, under the database name \"helga_old\"." if { [::helga::db::databaseExists helga_old] } { puts "Error: Database \"helga_old\" already exists. This may be left over from a failed migration, or maybe someone else is currently migrating an old project. This database must be removed before the script can continue." exit 1 } ::mysql::exec $::db "CREATE DATABASE `helga_old`" puts "Please provide information for your old database." puts -nonewline "Host Name: " flush stdout gets stdin sourceHostName puts -nonewline "Database Name: " flush stdout gets stdin sourceDbName puts -nonewline "User Name: " flush stdout gets stdin sourceDbUser set cmd "exec mysqldump -h $sourceHostName -u $sourceDbUser -p $sourceDbName | mysql --user=helgaAdmin --password=$::ADMINSQLPASS helga_old" eval $cmd puts "Database copied. Proceeding." ::helga::db::use helga_old set sql "SELECT `username`,`password`,`full_name`,`email`,`im_aim`,`htmlmail`,`url`,`cell` FROM `users`" set result [::helga::db::select $sql] ::helga::db::use foreach row $result { if { [::helga::assets::assetExists /users/[lindex $row 0]] } { puts "Skipping user [lindex $row 0], already exists." } else { puts -nonewline "Adding user [lindex $row 0]..." flush stdout set newUser [hadd user -name [lindex $row 0] -fullname [lindex $row 2]] set newUserId [::helga::assets::getAssetIdFromName $newUser] set passsql "UPDATE `users` SET `password` = '[lindex $row 1]' WHERE `assetId` = $newUserId" ::helga::db::update $passsql hset email [lindex $row 3] -name $newUser hset aim [lindex $row 4] -name $newUser hset htmlmail [lindex $row 5] -name $newUser hset url [lindex $row 6] -name $newUser hset phone [lindex $row 7] -name $newUser puts "done." } } ::mysql::exec $::db "DROP DATABASE `helga_old`" puts "Done migrating users."