Bug 24511: Update variable names to avoid confusion
authorNick Clemens <nick@bywatersolutions.com>
Fri, 24 Jan 2020 14:58:25 +0000 (14:58 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 27 Jan 2020 10:14:15 +0000 (10:14 +0000)
To test:
1 - Create a report
    SELECT borrowernumber, firstname, surname, email, emailpro FROM borrowers WHERE surname='acosta'
2 - Create or edit patron with surname acosta to have a separate email and emailpro
3 - perl misc/cronjobs/patron_emailer --notice HOLDS --module reserves --verbose --email emailpro --report ## --from 'me@you.us'
4 - Note email is used, not email pro
5 - Apply patch
6 - Repeat, correct eamil is used

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
C4/Reports/Guided.pm
t/db_dependent/Reports/Guided.t

index 84fd843..61aa804 100644 (file)
@@ -984,7 +984,7 @@ sub EmailReport {
     my $params     = shift;
     my $report_id  = $params->{report_id};
     my $from       = $params->{from};
-    my $email      = $params->{email};
+    my $email_col  = $params->{email} || 'email';
     my $module     = $params->{module};
     my $code       = $params->{code};
     my $branch     = $params->{branch} || "";
@@ -1017,12 +1017,12 @@ sub EmailReport {
         my $email;
         my $err_count = scalar @errors;
         push ( @errors, { NO_BOR_COL => $counter } ) unless defined $row->{borrowernumber};
-        push ( @errors, { NO_EMAIL_COL => $counter } ) unless ( (defined $email && defined $row->{$email}) || defined $row->{email} );
+        push ( @errors, { NO_EMAIL_COL => $counter } ) unless ( defined $row->{$email_col} );
         push ( @errors, { NO_FROM_COL => $counter } ) unless defined ( $from || $row->{from} );
         push ( @errors, { NO_BOR => $row->{borrowernumber} } ) unless Koha::Patrons->find({borrowernumber=>$row->{borrowernumber}});
 
         my $from_address = $from || $row->{from};
-        my $to_address = $email ? $row->{$email} : $row->{email};
+        my $to_address = $row->{$email_col};
         push ( @errors, { NOT_PARSE => $counter } ) unless my $content = _process_row_TT( $row, $template );
         $counter++;
         next if scalar @errors > $err_count; #If any problems, try next
index 4488d4c..0d8d01d 100644 (file)
@@ -361,12 +361,12 @@ count(h.reservedate) AS 'holds'
 
 subtest 'Email report test' => sub {
 
-    plan tests => 9;
+    plan tests => 12;
 
-    my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com' } })->{ borrowernumber };
-    my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef } })->{ borrowernumber };
-    my $id3 = $builder->build({ source => 'Borrower',value => { surname => 'norman', email => 'a@b.com' } })->{ borrowernumber };
-    my $report1 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT surname,borrowernumber,email FROM borrowers WHERE borrowernumber IN ($id1,$id2,$id3)" } })->{ id };
+    my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com', emailpro => 'b@c.com' } })->{ borrowernumber };
+    my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef, emailpro => 'd@e.com' } })->{ borrowernumber };
+    my $id3 = $builder->build({ source => 'Borrower',value => { surname => 'norman', email => 'a@b.com', emailpro => undef } })->{ borrowernumber };
+    my $report1 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT surname,borrowernumber,email,emailpro FROM borrowers WHERE borrowernumber IN ($id1,$id2,$id3)" } })->{ id };
     my $report2 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT potato FROM mashed" } })->{ id };
 
     my $letter1 = $builder->build({
@@ -411,6 +411,11 @@ subtest 'Email report test' => sub {
     is( $emails->[0]{letter}->{content}, "mailer", "Message has expected content");
     is( $emails->[1]{letter}->{content}, "norman", "Message has expected content");
 
+    ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module} , code => $letter1->{code}, from => 'the@future.ooh', email => 'emailpro' });
+    is_deeply( $errors, [{'NO_EMAIL_COL'=>3}],"We report missing email in emailpro column");
+    is( $emails->[0]->{to_address}, 'b@c.com', "Message uses correct email");
+    is( $emails->[1]->{to_address}, 'd@e.com', "Message uses correct email");
+
 };
 
 $schema->storage->txn_rollback;