From 194cdef333e85c49f998cb38b72c4278b4128d88 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 24 Jan 2020 14:58:25 +0000 Subject: [PATCH] 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 Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- C4/Reports/Guided.pm | 6 +++--- t/db_dependent/Reports/Guided.t | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm index 84fd843c7f..61aa804628 100644 --- a/C4/Reports/Guided.pm +++ b/C4/Reports/Guided.pm @@ -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 diff --git a/t/db_dependent/Reports/Guided.t b/t/db_dependent/Reports/Guided.t index 4488d4c5d4..0d8d01d15c 100644 --- a/t/db_dependent/Reports/Guided.t +++ b/t/db_dependent/Reports/Guided.t @@ -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; -- 2.39.5