Address Books cannot be owned by Visitor any longer. Changed newBySession to newByUserId.
This commit is contained in:
parent
aa41440181
commit
d67998888c
5 changed files with 52 additions and 12 deletions
|
|
@ -35,6 +35,8 @@ my $session = start(); # this line required
|
|||
# upgrade functions go here
|
||||
addWikiSubKeywords($session);
|
||||
addSynopsistoEachWikiPage($session);
|
||||
dropVisitorAddressBooks($session);
|
||||
alterAddressBookTable($session);
|
||||
|
||||
finish($session); # this line required
|
||||
|
||||
|
|
@ -79,6 +81,27 @@ sub addSynopsistoEachWikiPage {
|
|||
print "DONE!\n" unless $quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub dropVisitorAddressBooks {
|
||||
my $session = shift;
|
||||
print "\tDrop AddressBooks owned by Visitor... " unless $quiet;
|
||||
my $sth = $session->db->read(q|SELECT addressBookId FROM addressBook where userId='1'|);
|
||||
BOOK: while (my ($addressBookId) = $sth->array) {
|
||||
my $book = eval { WebGUI::Shop::AddressBook->new($session, $addressBookId); };
|
||||
next BOOK if Exception::Class->caught();
|
||||
$book->delete;
|
||||
}
|
||||
print "DONE!\n" unless $quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub alterAddressBookTable {
|
||||
my $session = shift;
|
||||
print "\tDrop sessionId from the Address Book database table... " unless $quiet;
|
||||
# and here's our code
|
||||
$session->db->write("ALTER TABLE addressBook DROP COLUMN sessionId");
|
||||
print "DONE!\n" unless $quiet;
|
||||
}
|
||||
|
||||
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -404,7 +404,7 @@ sub view {
|
|||
;
|
||||
|
||||
# instanciate address
|
||||
my $address = WebGUI::Shop::AddressBook->newBySession($self->session)->getAddress($form->get("addressId")) if ($form->get("addressId"));
|
||||
my $address = WebGUI::Shop::AddressBook->newByUserId($self->session)->getAddress($form->get("addressId")) if ($form->get("addressId"));
|
||||
|
||||
# build the form that the user needs to fill out with badge holder information
|
||||
$vars{formHeader} = WebGUI::Form::formHeader($session, {action => $self->getUrl})
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ sub www_address {
|
|||
my $session = shift;
|
||||
my $output = undef;
|
||||
my $method = "www_". ( $session->form->get("method") || "view");
|
||||
my $cart = WebGUI::Shop::AddressBook->newBySession($session);
|
||||
my $cart = WebGUI::Shop::AddressBook->newByUserId($session);
|
||||
|
||||
if ($cart->can($method)) {
|
||||
$output = $cart->$method();
|
||||
|
|
|
|||
|
|
@ -56,22 +56,31 @@ sub addAddress {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 create ( session )
|
||||
=head2 create ( session, userId )
|
||||
|
||||
Constructor. Creates a new address book for this user or session if no user is logged in.
|
||||
Constructor. Creates a new address book for this user.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 userId
|
||||
|
||||
The userId for the user. Throws an exception if it is Visitor. Defaults to the session
|
||||
user if omitted.
|
||||
|
||||
=cut
|
||||
|
||||
sub create {
|
||||
my ($class, $session) = @_;
|
||||
my ($class, $session, $userId) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $id = $session->db->setRow("addressBook", "addressBookId", {addressBookId=>"new", userId=>$session->user->userId, sessionId=>$session->getId});
|
||||
$userId ||= $session->user->userId;
|
||||
if ($userId eq '1') {
|
||||
WebGUI::Error::InvalidParam->throw(error=>"Visitor cannot have an address book.");
|
||||
}
|
||||
my $id = $session->db->setRow("addressBook", "addressBookId", {addressBookId=>"new", userId=>$userId});
|
||||
return $class->new($session, $id);
|
||||
}
|
||||
|
||||
|
|
@ -252,22 +261,30 @@ sub new {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 newBySession ( session )
|
||||
=head2 newByUserId ( session, userId )
|
||||
|
||||
Constructor. Creates a new address book for this user if they don't have one. If the user is not logged in creates an address book attached to the session if there isn't one for the session. In any case returns a reference to the address book.
|
||||
Constructor. Creates a new address book for this user if they don't have one. In any case returns a reference to the address book.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 userId
|
||||
|
||||
The userId for the user. Throws an exception if it is Visitor. Defaults to the session
|
||||
user if omitted.
|
||||
|
||||
=cut
|
||||
|
||||
sub newBySession {
|
||||
my ($class, $session) = @_;
|
||||
sub newByUserId {
|
||||
my ($class, $session, $userId) = @_;
|
||||
unless (defined $session && $session->isa("WebGUI::Session")) {
|
||||
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
|
||||
}
|
||||
my $userId = $session->user->userId;
|
||||
$userId ||= $session->user->userId;
|
||||
if ($userId eq '1') {
|
||||
WebGUI::Error::InvalidParam->throw(error=>"Visitor cannot have an address book.");
|
||||
}
|
||||
|
||||
# check to see if this user or his session already has an address book
|
||||
my @ids = $session->db->buildArray("select addressBookId from addressBook where (userId<>'1' and userId=?) or sessionId=?",[$session->user->userId, $session->getId]);
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ sub getAddressBook {
|
|||
my $self = shift;
|
||||
my $id = id $self;
|
||||
unless (exists $addressBookCache{$id}) {
|
||||
$addressBookCache{$id} = WebGUI::Shop::AddressBook->newBySession($self->session);
|
||||
$addressBookCache{$id} = WebGUI::Shop::AddressBook->newByUserId($self->session);
|
||||
}
|
||||
return $addressBookCache{$id};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue