Bug 24511: Update variable names to avoid confusion

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>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2020-01-24 14:58:25 +00:00 committed by Joy Nelson
parent ed1b52a15d
commit 24f68264d4
2 changed files with 13 additions and 8 deletions

View 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

View 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;