head	1.2;
access;
symbols
	TIGRIS_1_1_0RC2:1.1.2.1
	TIGRIS_1_1_0RC1:1.1.2.1
	TIGRIS_1_1:1.1.2.1.0.2
	TIGRIS_1_0_8:1.1.2.1
	TIGRIS_1_0_8RC3:1.1.2.1
	TIGRIS_1_0_8RC2:1.1.2.1
	TIGRIS_1_0_8RC1:1.1.2.1
	TIGRIS_1_0_7:1.1.2.1
	TIGRIS_1_0_7RC3:1.1.2.1
	TIGRIS_1_0_7RC2:1.1.2.1
	TIGRIS_1_0_7RC1:1.1.2.1
	TIGRIS_1_0_6:1.1.2.1
	TIGRIS_1_0_6RC5:1.1.2.1
	TIGRIS_1_0_6RC4:1.1.2.1
	TIGRIS_1_0_6RC3:1.1.2.1
	TIGRIS_1_0_6RC2:1.1.2.1
	TIGRIS_1_0_6RC1:1.1.2.1
	TIGRIS_1_0_5:1.1.2.1
	TIGRIS_1_0_5RC6:1.1.2.1
	TIGRIS_1_0_5RC5:1.1.2.1
	TIGRIS_1_0_5RC4:1.1.2.1
	TIGRIS_1_0_5RC3:1.1.2.1
	TIGRIS_1_0_5RC2:1.1.2.1
	TIGRIS_1_0_5RC1:1.1.2.1
	TIGRIS_1_0_4:1.1.2.1
	TIGRIS_1_0:1.1.0.2;
locks; strict;
comment	@# @;


1.2
date	2001.05.09.01.38.33;	author kmaples;	state Exp;
branches;
next	1.1;

1.1
date	2001.05.02.04.02.49;	author kmaples;	state Exp;
branches
	1.1.2.1;
next	;

1.1.2.1
date	2001.05.02.19.54.30;	author kmaples;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Removed __END__ token, since configure.pl gets all persnikety about it.
@
text
@#!/usr/bin/perl -w
# 
# -*- Perl -*- script which tries to fix/update old manually  
# administered issues databases by reading in the HELM_USER table,  
# getting the EMAIL address that the user registered under, and 
# looking for issuezilla accounts that were registered under that 
# email address.  It attempts to account for disabled accounts
# for both source and target addresses, and will not attempt
# an update if there's the possibility of conflict between the 
# two.
#
# $Id: issuzilla_helm_user_reconcile.pl.in,v 1.1 2001/05/02 04:02:49 kmaples Exp $

use DBI;

BEGIN
{
    unshift(@@INC, "$ENV{SANDBOX}/scripts");
}
use HelmDB;

my $dbh = HelmDB::connect('mysql', $ENV{DATABASE_ADMIN_USER},
	$ENV{DATABASE_ADMIN_PASSWORD});

# $HELM_USER{EMAIL} = [REAL_NAME, LOGIN_NAME];
my %HELM_USER;
my @@ISSUES_DATABASES;
my $DOMAIN = '__DOMAIN__';

# Preliminary info:
print "Getting list of issues databases ... \n";
my @@dbs = HelmDB::runQuery($dbh, 'SHOW DATABASES');
foreach(@@dbs){ 
	$_ = $_->[0]; 
	push(@@ISSUES_DATABASES, $_) if m/^$ENV{IZ_DATABASE_NAME}/;
}

# Get helm user information:
print "Getting list of HELM users ... \n";
my $rv   = HelmDB::runSQL(
	$dbh, "USE $ENV{'DATABASE_NAME'}");
my @@usrs = HelmDB::runQuery(
	$dbh, 'SELECT EMAIL, REAL_NAME, LOGIN_NAME FROM HELM_USER');
foreach(@@usrs){
	my ($k, $r, $l) = @@{$_};
	next unless $k && $l;
	$HELM_USER{$k} = [$r, $l];	
}

my @@conflicting_accts;

# Begin the real work:
foreach(@@ISSUES_DATABASES){
	print "Checking issues db: $_\n";
	my $current_issues_db = $_;
	my $rv = HelmDB::runSQL($dbh, "USE $current_issues_db");
	
	foreach(keys(%HELM_USER)){
		print "  checking for user email: $_\n";
		my @@tmp;
		my $helm_email = $_;
		my ($helm_realname, $helm_username)	= @@{$HELM_USER{$_}};

		my $new_helm_name = join('@@', $helm_username, $DOMAIN);
		my $disabled_pfx = 'ex-';

		my $helm_disabled_email    = $disabled_pfx . $helm_email;
		my $new_disabled_helm_name = $disabled_pfx . $new_helm_name;
		
		my $user_has_new_account;
		my $user_has_old_account;
		
		# sqlify the relevant values:
		foreach($helm_email, $helm_disabled_email,
			$new_helm_name, $new_disabled_helm_name){			
			$dbh->quote($_) 
		};
		
		# If there exists a new account, disabled or not, mark it;
		# we won't do anything with it, but if there's a conflicting
		# account, we want to know about it:
		@@tmp = HelmDB::runQuery($dbh, 
			qq[
				SELECT login_name
				FROM profiles 
				WHERE login_name IN 
				('$new_helm_name', '$new_disabled_helm_name')
			]);
		if($tmp[0]->[0]){
			$user_has_new_account = $tmp[0]->[0];
		}

		# If match, then update w/ helm info:
		@@tmp = HelmDB::runQuery($dbh,
			qq[
				SELECT userid, login_name 
				FROM profiles 
				WHERE login_name 
				IN ('$helm_email', '$helm_disabled_email');
			]);

		if($tmp[0]->[1]){
			$user_has_old_account = $tmp[0]->[1];
		}
		
		if($user_has_new_account && $user_has_old_account){
			push(@@conflicting_accts,
				"$current_issues_db:$user_has_new_account:$user_has_old_account");
			print "WARNING: there are conflicting accounts for user\n";
			print "$new_helm_name (disabled or not) - skipping\n";
			next;			
		} elsif($user_has_new_account){
			next;
		}

		# There really shouldn't be more that one record, but in the
		# interest of completeness, we'll iterate over the return:
		foreach(@@tmp){			
			my ($id, $login_name) = @@{ $_ };
			if($id && $login_name){
				print "    updating account info for $login_name\n";
				# Check to see if this acct. was disabled
				my $newname = ($login_name =~ m/^$disabled_pfx/) 
					? $new_disabled_helm_name : $new_helm_name;			
				
				$rv = HelmDB::runSQL($dbh, qq[
					UPDATE profiles SET
					login_name = '$newname',
					realname   = '$helm_realname'
					WHERE userid = $id
				]);

			}				
		}
	}
}

$dbh->disconnect();

if(@@conflicting_accts){
	print "\n";
	print "The following databases had accounts which couldn't be\n";
	print "upated, because conflicts were found:\n\n";
	foreach(@@conflicting_accts){
		print $_ . "\n";
	}
}



@


1.1
log
@Added script which tries to enable as many old bugzilla/issuezilla user
accounts as it can based on info from the HELM_USER table.
@
text
@d12 1
a12 1
# $Id: $
a147 1
__END__
@


1.1.2.1
log
@Modified migration scripts to change the bugs@@ user to issues@@; added a script
which attempts to reconcile existing helm accounts with older issuezilla
accounts upon upgrade from versions prior to 0.8.4; removed the sql statement
which attempted a brute-force transformation of user accounts in favor of
the aforementioned script; added data validation tools in helm/tests; added
the shared perl db library that these scripts use (HelmDB.pm) in previous
commit.
@
text
@d12 1
a12 1
# $Id: issuzilla_helm_user_reconcile.pl.in,v 1.1 2001/05/02 04:02:49 kmaples Exp $
@

