more session related bug fixes

This commit is contained in:
JT Smith 2006-01-14 21:30:49 +00:00
parent c8f1327be0
commit b1ab07d24f
6 changed files with 38 additions and 38 deletions

View file

@ -801,6 +801,9 @@ perl -pi.bak -e 's!WebGUI\:\:Paginator\-\>new\(!WebGUI::Paginator->new(\$self->s
WebGUI::Product now accepts session in the constructor.
perl -pi.bak -e 's!WebGUI\:\:Product\-\>new\(!WebGUI::Product->new(\$self->session,!g' fileNameGoesHere
perl -pi.bak -e 's!WebGUI\:\:Product\-\>getByOptionId\(!WebGUI::Product->getByOptionId(\$self->session,!g' fileNameGoesHere
perl -pi.bak -e 's!WebGUI\:\:Product\-\>getByParameterId\(!WebGUI::Product->getByParameterId(\$self->session,!g' fileNameGoesHere
perl -pi.bak -e 's!WebGUI\:\:Product\-\>getByVariantId\(!WebGUI::Product->getByVariantId(\$self->session,!g' fileNameGoesHere
5.23.20 WebGUI::ProfileCategory and WebGUI::ProfileField Refactored

View file

@ -198,10 +198,14 @@ sub commit {
#-------------------------------------------------------------------
=head2 connect ( dsn, user, pass, session )
=head2 connect ( session, dsn, user, pass )
Constructor. Connects to the database using DBI.
=head2 session
A reference to the active WebGUI::Session object.
=head2 dsn
The Database Service Name of the database you wish to connect to. It looks like 'DBI:mysql:dbname;host=localhost'.
@ -214,18 +218,14 @@ The username to use to connect to the database defined by dsn.
The password to use to connect to the database defined by dsn.
=head2 session
A reference to the active WebGUI::Session object.
=cut
sub connect {
my $class = shift;
my $session = shift;
my $dsn = shift;
my $user = shift;
my $pass = shift;
my $session = shift;
my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError=>0,AutoCommit=>1 }) or $session->errorHandler->fatal("Couldn't connect to database.");
if ( $dsn =~ /Oracle/ ) { # Set Oracle specific attributes
$dbh->{LongReadLen} = 512 * 1024;

View file

@ -165,7 +165,7 @@ Returns a WebGUI::SQL object, which is connected to the WebGUI database.
sub db {
my $self = shift;
unless (exists $self->{_db}) {
$self->{_db} = $self->db->connect($self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"), $self);
$self->{_db} = WebGUI::SQL->connect($self,$self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"));
}
return $self->{_db};
}
@ -184,7 +184,7 @@ sub dbSlave {
foreach (1..3) {
my $slave = $self->config->get("dbslave".$_);
if (exists $slave->{dsn}) {
push(@{$self->{_slave}},$self->db->connect($slave->{dsn},$slave->{user},$slave->{pass}, $self));
push(@{$self->{_slave}},$self->db->connect($self, $slave->{dsn},$slave->{user},$slave->{pass}));
}
}
}
@ -530,17 +530,16 @@ sub user {
my $self = shift;
my $option = shift;
if (defined $option) {
$self->{_var}{userId} = $option->{userId} || $option->{user}->userId;
$self->db->setRow("userSession","sessionId", $self->{_var});
if ($self->setting("passiveProfilingEnabled")) {
$self->db->write("update passiveProfileLog set userId = ".$self->db->quote($self->{_var}{userId})." where sessionId = ".$self->db->quote($self->getId));
my $userId = $option->{userId} || $option->{user}->userId;
if ($self->setting->get("passiveProfilingEnabled")) {
$self->db->write("update passiveProfileLog set userId = ".$self->db->quote($userId)." where sessionId = ".$self->db->quote($self->getId));
}
delete $self->{_stow};
$self->{_user} = $option->{user} || WebGUI::User->new($self, $self->{_var}{userId});
$self->{_user} = $option->{user} || WebGUI::User->new($self, $userId);
} elsif (!exists $self->{_user}) {
$self->{_user} = WebGUI::User->new($self, $self->var->get('userId'));
}
$self->{_request}->user($self->{_user}->username) if ($self->{_request});
$self->request->user($self->{_user}->username) if ($self->request);
return $self->{_user};
}

View file

@ -56,10 +56,9 @@ These methods are available from this class:
sub _create {
my $session = shift;
my $userId = shift || $session->id->generate();
$session->db->write("insert into users (userId,dateCreated) values (".$session->db->quote($userId).",".$session->datetime->time().")");
require WebGUI::Grouping;
WebGUI::Group->new([2])->addUsers([$userId]);
WebGUI::Group->new([7])->addUsers([$userId]);
$session->db->write("insert into users (userId,dateCreated) values (".$session->db->quote($userId).",".time().")");
WebGUI::Group->new($session,[2])->addUsers([$userId]);
WebGUI::Group->new($session,[7])->addUsers([$userId]);
return $userId;
}
@ -85,7 +84,7 @@ sub addToGroups {
my $expireOffset = shift;
$self->uncache;
foreach my $groupId (@{$groups}) {
WebGUI::Group->new($groupId)->addUsers([$self->userId],$expireOffset);
WebGUI::Group->new($self->session,$groupId)->addUsers([$self->userId],$expireOffset);
}
}
@ -142,7 +141,7 @@ sub delete {
$self->session->db->write("delete from users where userId=".$self->session->db->quote($self->{_userId}));
$self->session->db->write("delete from userProfileData where userId=".$self->session->db->quote($self->{_userId}));
foreach my $groupId (@{$self->session->user->getGroups($self->userId)}) {
WebGUI::Group->new($groupId)->deleteUsers([$self->userId]);
WebGUI::Group->new($self->session,$groupId)->deleteUsers([$self->userId]);
}
$self->session->db->write("delete from messageLog where userId=".$self->session->db->quote($self->{_userId}));
my $authMethod = WebGUI::Operation::Auth::getInstance($self->authMethod,$self->{_userId});
@ -166,7 +165,7 @@ sub deleteFromGroups {
my $groups = shift;
$self->uncache;
foreach my $groupId (@{$groups}) {
WebGUI::Group->new($groupId)->deleteUsers([$self->userId]);
WebGUI::Group->new($self->session,$groupId)->deleteUsers([$self->userId]);
}
}
@ -273,7 +272,7 @@ sub isInGroup {
}
}
### Get data for auxillary checks.
my $group = WebGUI::Group->new($gid);
my $group = WebGUI::Group->new($self->session,$gid);
### Check IP Address
if ($group->get("ipFilter")) {
my $ipFilter = $group->get("ipFilter");

View file

@ -1,5 +1,5 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
@ -12,22 +12,20 @@
use strict;
use lib '../lib';
use Getopt::Long;
use WebGUI::Session;
use WebGUI::Utility;
# ---- END DO NOT EDIT ----
use WebGUI::User;
use WebGUI::SQL;
use Test::More tests => 33; # increment this value for each test you create
my $session = initialize(); # this line is required
# put your tests here
my $user;
my $lastUpdate;
#Let's try to create a new user and make sure we get an object back
my $userCreationTime = time();
ok(defined ($user = WebGUI::User->new("new")), 'new("new") -- object reference is defined');
ok(defined ($user = WebGUI::User->new($session,"new")), 'new("new") -- object reference is defined');
#New does not return undef if something breaks, so we'll see if the _profile hash was set.
ok(scalar %{$user->{_profile}} > 0, 'new("new") -- profile property contains at least one key');
@ -78,7 +76,7 @@ my $oldKarma = $user->karma;
$user->karma('69', 'peter gibbons', 'test karma');
is($user->karma, $oldKarma+69, 'karma() -- get/set add amount');
my ($source, $description) = WebGUI::SQL->quickArray("select source, description from karmaLog where userId=".quote($user->userId));
my ($source, $description) = $session->db->quickArray("select source, description from karmaLog where userId=".$session->db->quote($user->userId));
is($source, 'peter gibbons', 'karma() -- get/set source');
is($description, 'test karma', 'karma() -- get/set description');
@ -97,46 +95,46 @@ is($user->lastUpdated, $lastUpdate, 'lastUpdated() -- referringAffiliate');
my @groups = qw|2 4|;
$user->addToGroups(\@groups);
my ($result) = WebGUI::SQL->quickArray("select count(*) from groupings where groupId=".quote('2')." and userId=".quote($user->userId));
my ($result) = $session->db->quickArray("select count(*) from groupings where groupId=".$session->db->quote('2')." and userId=".$session->db->quote($user->userId));
ok($result, 'addToGroups() -- added to first test group');
($result) = WebGUI::SQL->quickArray("select count(*) from groupings where groupId=".quote('4')." and userId=".quote($user->userId));
($result) = $session->db->quickArray("select count(*) from groupings where groupId=".$session->db->quote('4')." and userId=".$session->db->quote($user->userId));
ok($result, 'addToGroups() -- added to second test group');
#Let's delete this user from our test groups
$user->deleteFromGroups(\@groups);
($result) = WebGUI::SQL->quickArray("select count(*) from groupings where groupId=".quote('2')." and userId=".quote($user->userId));
($result) = $session->db->quickArray("select count(*) from groupings where groupId=".$session->db->quote('2')." and userId=".$session->db->quote($user->userId));
is($result, '0', 'deleteFromGroups() -- removed from first test group');
($result) = WebGUI::SQL->quickArray("select count(*) from groupings where groupId=".quote('4')." and userId=".quote($user->userId));
($result) = $session->db->quickArray("select count(*) from groupings where groupId=".$session->db->quote('4')." and userId=".$session->db->quote($user->userId));
is($result, '0', 'deleteFromGroups() -- removed from second test group');
#Let's delete this user
my $userId = $user->userId;
$user->delete;
my ($count) = WebGUI::SQL->quickArray("select count(*) from users where userId=".quote($userId));
my ($count) = $session->db->quickArray("select count(*) from users where userId=".$session->db->quote($userId));
is($count, '0', 'delete() -- users table');
($count) = WebGUI::SQL->quickArray("select count(*) from userProfileData where userId=".quote($userId));
($count) = $session->db->quickArray("select count(*) from userProfileData where userId=".$session->db->quote($userId));
is($count, '0', 'delete() -- userProfileData table');
($count) = WebGUI::SQL->quickArray("select count(*) from messageLog where userId=".quote($userId));
($count) = $session->db->quickArray("select count(*) from messageLog where userId=".$session->db->quote($userId));
is($count, '0', 'delete() -- messageLog table');
#Let's test new with an override uid
$user = WebGUI::User->new("new", "ROYSUNIQUEUSERID000001");
$user = WebGUI::User->new($session, "new", "ROYSUNIQUEUSERID000001");
is($user->userId, "ROYSUNIQUEUSERID000001", 'new() -- override user id');
$user->delete;
#Let's test new to retrieve an existing user
$user = WebGUI::User->new(3);
$user = WebGUI::User->new($session,3);
is($user->username, "Admin", 'new() -- retrieve existing user');
$user = "";
#Let's test new to retrieve default user visitor with no params passed in
$user = WebGUI::User->new;
$user = WebGUI::User->new($session);
is($user->userId, '1', 'new() -- returns visitor with no args');
$user = "";

View file

@ -12,6 +12,7 @@
use strict;
use lib '../lib';
use Getopt::Long;
use WebGUI::Session;
# ---- END DO NOT EDIT ----