Use donorId rather than supporterId as main handle
Since we converted to making this a more general donor database, change the handle used for an individual in the database from supporterId to donorId. Note that I left addSupporter() method name untouched because it does automatically assume you mean a supporter, not a mere donor. Later, an addDonor() method should likely be added.
This commit is contained in:
		
							parent
							
								
									95ef1fce28
								
							
						
					
					
						commit
						9de60c3c5e
					
				
					 2 changed files with 48 additions and 48 deletions
				
			
		|  | @ -237,7 +237,7 @@ Arguments: | |||
| 
 | ||||
| =over | ||||
| 
 | ||||
| =item $supporterId | ||||
| =item $donorId | ||||
| 
 | ||||
|    Valid supporter id number currently in the database.  die() will occur if | ||||
|    the id number is not in the database already as a supporter id. | ||||
|  | @ -256,9 +256,9 @@ returned; it means the preferred email address wasn't selected for some reason. | |||
| =cut | ||||
| 
 | ||||
| sub setPreferredEmailAddress($$$) { | ||||
|   my($self, $supporterId, $emailAddress) = @_; | ||||
|   my($self, $donorId, $emailAddress) = @_; | ||||
| 
 | ||||
|   die "setPreferredEmailAddress: invalid supporter id, $supporterId" unless $self->_verifyId($supporterId); | ||||
|   die "setPreferredEmailAddress: invalid supporter id, $donorId" unless $self->_verifyId($donorId); | ||||
|   die "setPreferredEmailAddress: email address not defined" unless defined $emailAddress; | ||||
|   die "setPreferredEmailAddress: invalid email address, $emailAddress" | ||||
|     unless Mail::RFC822::Address::valid($emailAddress); | ||||
|  | @ -266,7 +266,7 @@ sub setPreferredEmailAddress($$$) { | |||
|   my $ems = $self->dbh()->selectall_hashref("SELECT ea.email_address, ea.id, sem.preferred " . | ||||
|                                             "FROM email_address ea, donor_email_address_mapping sem " . | ||||
|                                             "WHERE ea.id = sem.email_address_id AND ". | ||||
|                                             "sem.donor_id = " . $self->dbh->quote($supporterId, 'SQL_INTEGER'), | ||||
|                                             "sem.donor_id = " . $self->dbh->quote($donorId, 'SQL_INTEGER'), | ||||
|                                             'email_address'); | ||||
|   # Shortcut: it was already set | ||||
|   return $ems->{$emailAddress}{id} if (defined $ems->{$emailAddress} and $ems->{$emailAddress}{preferred}); | ||||
|  | @ -284,7 +284,7 @@ sub setPreferredEmailAddress($$$) { | |||
|   if ($anotherPreferred) { | ||||
|     $self->dbh->do("UPDATE donor_email_address_mapping " . | ||||
|                      "SET preferred = " . $self->dbh->quote(0, 'SQL_BOOLEAN') . " " . | ||||
|                      "WHERE donor_id = " . $self->dbh->quote($supporterId, 'SQL_INTEGER')); | ||||
|                      "WHERE donor_id = " . $self->dbh->quote($donorId, 'SQL_INTEGER')); | ||||
|   } | ||||
|   $self->dbh->do("UPDATE donor_email_address_mapping " . | ||||
|                  "SET preferred = " . $self->dbh->quote(1, 'SQL_BOOLEAN') . " " . | ||||
|  | @ -300,7 +300,7 @@ Arguments: | |||
| 
 | ||||
| =over | ||||
| 
 | ||||
| =item $supporterId | ||||
| =item $donorId | ||||
| 
 | ||||
|    Valid supporter id number currently in the database.  die() will occur if | ||||
|    the id number is not in the database already as a supporter id. | ||||
|  | @ -319,16 +319,16 @@ returned; it means the preferred email address wasn't selected for some reason. | |||
| =cut | ||||
| 
 | ||||
| sub getPreferredEmailAddress($$) { | ||||
|   my($self, $supporterId) = @_; | ||||
|   my($self, $donorId) = @_; | ||||
| 
 | ||||
|   die "setPreferredEmailAddress: invalid supporter id, $supporterId" unless $self->_verifyId($supporterId); | ||||
|   die "setPreferredEmailAddress: invalid supporter id, $donorId" unless $self->_verifyId($donorId); | ||||
| 
 | ||||
|   my $ems = $self->dbh()->selectall_hashref("SELECT email_address FROM email_address em, donor_email_address_mapping sem " . | ||||
|                                             "WHERE preferred AND sem.email_address_id = em.id AND " . | ||||
|                                             "sem.donor_id = " . $self->dbh->quote($supporterId, 'SQL_INTEGER'), | ||||
|                                             "sem.donor_id = " . $self->dbh->quote($donorId, 'SQL_INTEGER'), | ||||
|                                             'email_address'); | ||||
|   my $rowCount = scalar keys %{$ems}; | ||||
|   die "setPreferredEmailAddress: DATABASE INTEGRITY ERROR: more than one email address is preferred for supporter, \"$supporterId\"" | ||||
|   die "setPreferredEmailAddress: DATABASE INTEGRITY ERROR: more than one email address is preferred for supporter, \"$donorId\"" | ||||
|     if $rowCount > 1; | ||||
| 
 | ||||
|   if ($rowCount != 1) { | ||||
|  | @ -566,7 +566,7 @@ Arguments: | |||
| 
 | ||||
| =over | ||||
| 
 | ||||
| =item $supporterId | ||||
| =item $donorId | ||||
| 
 | ||||
|    Valid donor_id number currently in the database.  die() will occur if | ||||
|    the id number is not in the database already as a supporter id. | ||||
|  | @ -589,7 +589,7 @@ Returns: | |||
| 
 | ||||
| =item undef | ||||
| 
 | ||||
|       if the C<$requestType> is not found for C<$supporterId> (or, as above, | ||||
|       if the C<$requestType> is not found for C<$donorId> (or, as above, | ||||
|       the C<$requestType> is found but has been fufilled and | ||||
|       C<$ignoreFulfilledRequests>. | ||||
| 
 | ||||
|  | @ -645,17 +645,17 @@ If the request has been fufilled, the following keys will also ahve values. | |||
| =cut | ||||
| 
 | ||||
| sub getRequest($$;$) { | ||||
|   my($self, $supporterId, $requestType, $ignoreFulfilledRequests) = @_; | ||||
|   my($self, $donorId, $requestType, $ignoreFulfilledRequests) = @_; | ||||
| 
 | ||||
|   die "getRequest: undefined supporterId" unless defined $supporterId; | ||||
|   die "getRequest: supporterId, \"$supporterId\" not found in supporter database" | ||||
|     unless $self->_verifyId($supporterId); | ||||
|   die "getRequest: undefined donorId" unless defined $donorId; | ||||
|   die "getRequest: donorId, \"$donorId\" not found in supporter database" | ||||
|     unless $self->_verifyId($donorId); | ||||
| 
 | ||||
|   die "getRequest: undefined requestType" unless defined $requestType; | ||||
| 
 | ||||
|   my $req = $self->dbh()->selectall_hashref("SELECT r.id, r.request_type_id, r.request_configuration_id, r.date_requested, r.notes, rt.type " . | ||||
|                                             "FROM request r, request_type rt WHERE r.request_type_id = rt.id AND " . | ||||
|                                             "r.donor_id = " . $self->dbh->quote($supporterId, 'SQL_INTEGER') . | ||||
|                                             "r.donor_id = " . $self->dbh->quote($donorId, 'SQL_INTEGER') . | ||||
|                                             " AND rt.type = " . $self->dbh->quote($requestType), | ||||
|                                             'type'); | ||||
|   return undef unless (defined $req and defined $req->{$requestType} and defined $req->{$requestType}{'id'}); | ||||
|  | @ -700,7 +700,7 @@ A hash reference, the following keys are considered: | |||
| 
 | ||||
| =over | ||||
| 
 | ||||
| =item supporterId | ||||
| =item donorId | ||||
| 
 | ||||
|    Valid donor_id number currently in the database.  die() will occur if | ||||
|    the id number is not in the database already as a supporter id. | ||||
|  | @ -739,10 +739,10 @@ Returns the id value of the request entry. | |||
| 
 | ||||
| sub addRequest($$) { | ||||
|   my($self, $params) = @_; | ||||
|   die "addRequest: undefined supporterId" unless defined $params->{supporterId}; | ||||
|   my $supporterId = $params->{supporterId}; | ||||
|   die "addRequest: supporterId, \"$supporterId\" not found in supporter database" | ||||
|     unless $self->_verifyId($supporterId); | ||||
|   die "addRequest: undefined donorId" unless defined $params->{donorId}; | ||||
|   my $donorId = $params->{donorId}; | ||||
|   die "addRequest: donorId, \"$donorId\" not found in supporter database" | ||||
|     unless $self->_verifyId($donorId); | ||||
| 
 | ||||
|   $self->_beginWork; | ||||
|   eval { | ||||
|  | @ -764,7 +764,7 @@ sub addRequest($$) { | |||
| 
 | ||||
|   my $sth = $self->dbh->prepare("INSERT INTO request(donor_id, request_type_id, request_configuration_id, notes, date_requested) " . | ||||
|                                              "VALUES(?,            ?,               ?,                        ?,      date('now'))"); | ||||
|   $sth->execute($supporterId, $params->{requestTypeId}, $params->{requestConfigurationId}, $params->{notes}); | ||||
|   $sth->execute($donorId, $params->{requestTypeId}, $params->{requestConfigurationId}, $params->{notes}); | ||||
|   my $id = $self->dbh->last_insert_id("","","",""); | ||||
|   $self->_commit; | ||||
|   return $id; | ||||
|  | @ -783,7 +783,7 @@ A hash reference, the following keys are considered: | |||
| 
 | ||||
| =over | ||||
| 
 | ||||
| =item supporterId | ||||
| =item donorId | ||||
| 
 | ||||
|    Valid donor_id number currently in the database.  die() will occur if | ||||
|    the id number is not in the database already as a supporter id. | ||||
|  | @ -793,7 +793,7 @@ A hash reference, the following keys are considered: | |||
|    requestType of the request to be fulfilled.  die() will occur if this is | ||||
|    undefined.  undef is returned if there is no unfulfilled request of | ||||
|    requestType in the database for supporter identified by | ||||
|    C<$params->{supporterId}> | ||||
|    C<$params->{donorId}> | ||||
| 
 | ||||
| =item who | ||||
| 
 | ||||
|  | @ -815,14 +815,14 @@ Returns the id value of the fulfillment entry. | |||
| 
 | ||||
| sub fulfillRequest($$) { | ||||
|   my($self, $params) = @_; | ||||
|   die "fulfillRequest: undefined supporterId" unless defined $params->{supporterId}; | ||||
|   my $supporterId = $params->{supporterId}; | ||||
|   die "fulfillRequest: supporterId, \"$supporterId\" not found in supporter database" | ||||
|     unless $self->_verifyId($supporterId); | ||||
|   die "fulfillRequest: undefined donorId" unless defined $params->{donorId}; | ||||
|   my $donorId = $params->{donorId}; | ||||
|   die "fulfillRequest: donorId, \"$donorId\" not found in supporter database" | ||||
|     unless $self->_verifyId($donorId); | ||||
|   die "fulfillRequest: undefined who" unless defined $params->{who}; | ||||
|   die "fulfillRequest: undefined requestType" unless defined $params->{requestType}; | ||||
| 
 | ||||
|   my $req = $self->getRequest($supporterId, $params->{requestType}); | ||||
|   my $req = $self->getRequest($donorId, $params->{requestType}); | ||||
|   return undef if not defined $req; | ||||
|   my $requestId = $req->{requestId}; | ||||
|   return undef if not defined $requestId; | ||||
|  |  | |||
|  | @ -249,15 +249,15 @@ foreach my $size (@sizeList) { | |||
| 
 | ||||
| =cut | ||||
| 
 | ||||
| dies_ok { $sp->addRequest({}); }  "addRequest: dies if supporterId not specified."; | ||||
| dies_ok { $sp->addRequest({}); }  "addRequest: dies if donorId not specified."; | ||||
| 
 | ||||
| dies_ok { $sp->addRequest({ supporterId => $drapperId }); } | ||||
| dies_ok { $sp->addRequest({ donorId => $drapperId }); } | ||||
|         "addRequest: dies if requestTypeId / requestType not specified."; | ||||
| 
 | ||||
| dies_ok { $sp->addRequest({ supporterId => 0, requestTypeId => $tShirt0RequestTypeId }); } | ||||
|         "addRequest: dies if supporterId invalid."; | ||||
| dies_ok { $sp->addRequest({ donorId => 0, requestTypeId => $tShirt0RequestTypeId }); } | ||||
|         "addRequest: dies if donorId invalid."; | ||||
| 
 | ||||
| dies_ok { $sp->addRequest({ supporterId => $drapperId, requestTypeId => 0 }); } | ||||
| dies_ok { $sp->addRequest({ donorId => $drapperId, requestTypeId => 0 }); } | ||||
|         "addRequest: dies if requestTypeId invalid."; | ||||
| 
 | ||||
| is($sp->{__NESTED_TRANSACTION_COUNTER__}, 0, "addRequest: assure proper beginWork/commit matching."); | ||||
|  | @ -265,7 +265,7 @@ is($sp->{__NESTED_TRANSACTION_COUNTER__}, 0, "addRequest: assure proper beginWor | |||
| my $emailListRequestId; | ||||
| 
 | ||||
| lives_ok { $emailListRequestId = | ||||
|              $sp->addRequest({ supporterId => $drapperId, requestType => "join-announce-email-list" }); } | ||||
|              $sp->addRequest({ donorId => $drapperId, requestType => "join-announce-email-list" }); } | ||||
|         "addRequest: succeeds with a requestType but no configuration parameter."; | ||||
| 
 | ||||
| ok( (defined $emailListRequestId and looks_like_number($emailListRequestId) and $emailListRequestId > 0), | ||||
|  | @ -278,7 +278,7 @@ ok((defined $joinEmailListRequestId and looks_like_number($joinEmailListRequestI | |||
| my $tshirtSmallRequestId; | ||||
| 
 | ||||
| lives_ok { $tshirtSmallRequestId = | ||||
|              $sp->addRequest({ supporterId => $drapperId, requestType => "t-shirt-small-only", | ||||
|              $sp->addRequest({ donorId => $drapperId, requestType => "t-shirt-small-only", | ||||
|                                requestConfiguration => 'Small', | ||||
|                                notes => 'he probably needs a larger size but this shirt has none'}); } | ||||
|         "addRequest: succeeds with a requestType and requestConfiguration and a note."; | ||||
|  | @ -288,7 +288,7 @@ ok( (defined $tshirtSmallRequestId and looks_like_number($tshirtSmallRequestId) | |||
| 
 | ||||
| my $tShirt0RequestId; | ||||
| lives_ok { $tShirt0RequestId = | ||||
|              $sp->addRequest({ supporterId => $drapperId, requestTypeId => $tShirt0RequestTypeId, | ||||
|              $sp->addRequest({ donorId => $drapperId, requestTypeId => $tShirt0RequestTypeId, | ||||
|                                requestConfigurationId => $tShirt0Data->{$tShirt0RequestTypeId}{'MenL'} }); } | ||||
|         "addRequest: succeeds with a requestTypeId and requestConfigurationId with no a note."; | ||||
| 
 | ||||
|  | @ -306,23 +306,23 @@ my $fulfillRequestId; | |||
| 
 | ||||
| dies_ok { $fulfillRequestId = $sp->fulfillRequest( { requestType => "t-shirt-small-only", who => 'joe', | ||||
|                                                     how => "in-person delivery" }); } | ||||
|      "fulfillRequest: dies if supporterId not specified"; | ||||
|      "fulfillRequest: dies if donorId not specified"; | ||||
| 
 | ||||
| dies_ok { $fulfillRequestId = $sp->fulfillRequest( { supporterId => $drapperId + 1000, | ||||
| dies_ok { $fulfillRequestId = $sp->fulfillRequest( { donorId => $drapperId + 1000, | ||||
|                                             requestType => "t-shirt-small-only", who => 'joe', | ||||
|                                                     how => "in-person delivery" }); } | ||||
|      "fulfillRequest: dies if supporterId not found in database"; | ||||
|      "fulfillRequest: dies if donorId not found in database"; | ||||
| 
 | ||||
| dies_ok { $fulfillRequestId = $sp->fulfillRequest( { supporterId => $drapperId,  who => 'joe', | ||||
| dies_ok { $fulfillRequestId = $sp->fulfillRequest( { donorId => $drapperId,  who => 'joe', | ||||
|                                                     how => "in-person delivery" }); } | ||||
|      "fulfillRequest: dies if requestType not specified"; | ||||
| 
 | ||||
| dies_ok { $fulfillRequestId = $sp->fulfillRequest( { supporterId => $drapperId, | ||||
| dies_ok { $fulfillRequestId = $sp->fulfillRequest( { donorId => $drapperId, | ||||
|                                                    requestType => "t-shirt-small-only", | ||||
|                                                     how => "in-person delivery" }); } | ||||
|      "fulfillRequest: dies if who not specified"; | ||||
| 
 | ||||
| lives_ok { $fulfillRequestId = $sp->fulfillRequest( { supporterId => $drapperId, | ||||
| lives_ok { $fulfillRequestId = $sp->fulfillRequest( { donorId => $drapperId, | ||||
|                                             requestType => "t-shirt-small-only", who => 'joe', | ||||
|                                                     how => "in-person delivery" }); } | ||||
|      "fulfillRequest: succeeds for existing request"; | ||||
|  | @ -338,7 +338,7 @@ is_deeply($val, { $fulfillRequestId => { id => $fulfillRequestId, date => $today | |||
|           "fulfillRequest: databse entry from successful return is correct"); | ||||
| 
 | ||||
| my $badFR; | ||||
| lives_ok { $badFR = $sp->fulfillRequest( { supporterId => $drapperId, who => 'john', | ||||
| lives_ok { $badFR = $sp->fulfillRequest( { donorId => $drapperId, who => 'john', | ||||
|                                                    requestType => "does-not-exist", | ||||
|                                                     how => "in-person delivery" }); } | ||||
|      "fulfillRequest: attempt to fulfill a request never made does not die..."; | ||||
|  | @ -352,7 +352,7 @@ is($sp->getRequestType("does-not-exist"), undef, | |||
| 
 | ||||
| my $lookedUpFulfillmentId; | ||||
| 
 | ||||
| lives_ok { $lookedUpFulfillmentId = $sp->fulfillRequest( { supporterId => $drapperId, | ||||
| lives_ok { $lookedUpFulfillmentId = $sp->fulfillRequest( { donorId => $drapperId, | ||||
|                                             requestType => "t-shirt-small-only", who => 'peggy', | ||||
|                                                     how => "left in his office." }); } | ||||
|      "fulfillRequest: attempt to fulfill an already-fulfill request does not die ..."; | ||||
|  | @ -364,9 +364,9 @@ is($lookedUpFulfillmentId, $fulfillRequestId, | |||
| 
 | ||||
| =cut | ||||
| 
 | ||||
| dies_ok { $sp->getRequest(undef, undef); }  "getRequest: dies if supporterId not specified."; | ||||
| dies_ok { $sp->getRequest(undef, undef); }  "getRequest: dies if donorId not specified."; | ||||
| 
 | ||||
| dies_ok { $sp->getRequest(0, "t-shirt-small-only"); } "getRequest: dies if supporterId invalid."; | ||||
| dies_ok { $sp->getRequest(0, "t-shirt-small-only"); } "getRequest: dies if donorId invalid."; | ||||
| 
 | ||||
| dies_ok { $sp->getRequest($drapperId, undef); } | ||||
|         "getRequest: dies if requestType not specified."; | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn