From 3764a805519acac76622d78d0aeb15d002f32027 Mon Sep 17 00:00:00 2001 From: Martin Kamerbeek Date: Tue, 19 Nov 2002 15:39:21 +0000 Subject: [PATCH] Check if authentication table exists. --- sbin/convertDBtoPA.pl | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/sbin/convertDBtoPA.pl b/sbin/convertDBtoPA.pl index 2907e63f9..e9590e62b 100644 --- a/sbin/convertDBtoPA.pl +++ b/sbin/convertDBtoPA.pl @@ -4,34 +4,37 @@ BEGIN { $configFile = "WebGUI.conf"; $webguiRoot = ".."; unshift (@INC, $webguiRoot."/lib"); -} - -print "\n\n\nThis program converts the old userauthentication system to the new (pluggable) one.\n" . - "It does NOT delete the old system so you can always go back to a stable WebGUI release.\n". - "If you don't want this functionality you should delete the 'ldapURL', 'connectDN' and the 'identifier' columns ". - "from the users table\n\n"; - -print "Opening WebGUI Session..."; + print "\n". + "This program converts the old userauthentication system to the new (pluggable)\n". + "one. It does NOT delete the old system so you can always use an older stable\n". + "WebGUI release. If you don't want to return to the primitive days without\n". + "pluggable authentication, you should delete the 'ldapURL', 'connectDN' and the\n". + "'identifier' columns from the users table\n\n"; +} use strict; use WebGUI; use WebGUI::SQL; use WebGUI::Session; +use WebGUI::Utility; -# Open a session for easy use of WebGUI::SQL +#--- Open a session for easy use of WebGUI::SQL -------------------------- +print "Opening WebGUI Session..."; WebGUI::Session::open($webguiRoot, $configFile); print "Ready\n\n"; -# Create the authentication table -my $sql; +#--- Check if the authentication table already exists -------------------- +my @tables = WebGUI::SQL->buildArray("show tables"); +die "Table 'authentication' already exists!\n" if isIn('authentication', @tables); + +#--- Create the authentication table ------------------------------------- print "Creating authentication table..."; my $sql = "create table authentication (userId int(11) not null, authMethod varchar(30) not null, fieldName varchar(128) not null, fieldData text, primary key (userId, authMethod, fieldName))"; WebGUI::SQL->write($sql); print "OK\n\n"; -# And go convert +#--- And go convert ------------------------------------------------------ my $sth = WebGUI::SQL->read("select * from users"); - while (my %hash = $sth->hash) { print "Converting user $hash{username} (id: $hash{userId})"; WebGUI::SQL->write("insert into authentication values ($hash{userId}, 'LDAP', 'ldapUrl', ". quote($hash{ldapUrl}) .")");