Implementation of addPostalAddress().
All tests related to addPostalAddress now pass. ok 28 - addPostalAddress: dies for undefined id ok 29 - addPostalAddress: dies for non-numeric id ok 30 - addPostalAddress: postal address undefined fails ok 31 - addPostalAddress: type is not added when other input paramaters are invalid ok 32 - addPostalAddress: addPostalAddress of a valid formatted_address works. ok 33 - addPostalAddress: id returned is sane.
This commit is contained in:
		
							parent
							
								
									e3cf1665d9
								
							
						
					
					
						commit
						05654fe11f
					
				
					 1 changed files with 32 additions and 1 deletions
				
			
		|  | @ -259,7 +259,38 @@ Returns the id value of the postal_address table entry. | |||
| sub addPostalAddress($$$$) { | ||||
|   my($self, $id, $formattedPostalAddress, $addressType) = @_; | ||||
| 
 | ||||
|   return undef; | ||||
|   die "addPostalAddress: invalid id, $id" unless $self->_verifyId($id); | ||||
|   die "addPostalAddress: the formatted postal address must be defined" | ||||
|     unless defined $formattedPostalAddress; | ||||
| 
 | ||||
|   $self->_beginWork(); | ||||
| 
 | ||||
|   my $addressTypeId; | ||||
|   eval { | ||||
|     $addressTypeId = $self->addAddressType($emailAddressType); | ||||
|   }; | ||||
|   if ($@ or not defined $addressTypeId) { | ||||
|     my $err = $@; | ||||
|     $err = "addPostalAddress: unable to addAddressType"  if (not defined $err); | ||||
|     $self->_rollback(); | ||||
|     die $@ if $@; | ||||
|   } | ||||
|   my $sth = $self->dbh->prepare("INSERT INTO postal_address(formatted_address, type_id, date_encountered)" . | ||||
|                                 "VALUES(                    ?,             ?,       date('now'))"); | ||||
| 
 | ||||
|   $sth->execute($formattedPostalAddress, $addressTypeId); | ||||
|   my $addressId = $self->dbh->last_insert_id("","","",""); | ||||
|   $sth->finish(); | ||||
| 
 | ||||
|   $sth = $self->dbh->prepare("INSERT INTO supporter_postal_address_mapping" . | ||||
|                                       "(supporter_id, postal_address_id) " . | ||||
|                                 "VALUES(           ?, ?)"); | ||||
|   $sth->execute($id, $addressId); | ||||
|   $sth->finish(); | ||||
| 
 | ||||
|   $self->_commit(); | ||||
| 
 | ||||
|   return $addressId; | ||||
| } | ||||
| ###################################################################### | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn