Bugzilla – Attachment 128546 Details for
Bug 19966
Add ability to pass objects directly to slips and notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19966: Add ability to pass objects directly to slips and notices
Bug-19966-Add-ability-to-pass-objects-directly-to-.patch (text/plain), 5.03 KB, created by
Martin Renvoize (ashimema)
on 2021-12-15 08:49:57 UTC
(
hide
)
Description:
Bug 19966: Add ability to pass objects directly to slips and notices
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-12-15 08:49:57 UTC
Size:
5.03 KB
patch
obsolete
>From df7b67d863bd5ae20cc10ea86caf4af229cb3d82 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Fri, 23 Jul 2021 08:07:59 -0400 >Subject: [PATCH] Bug 19966: Add ability to pass objects directly to slips and > notices > >Koha spends an incredible amount of time on parsing and processing parameters >passed in to slips and notices. It would be immensely more efficient to be able >to pass objects directly to GetPreparedLetter so it doesn't need to do any >fetching / processing on them. > >Test plan: >1) Apply this patch >2) prove t/db_dependent/Letters/TemplateToolkit.t > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > C4/Letters.pm | 31 ++++++++++++++---------- > t/db_dependent/Letters/TemplateToolkit.t | 14 ++++++++++- > 2 files changed, 31 insertions(+), 14 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index c36553ac9a..d0d1133762 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -638,12 +638,13 @@ sub GetPreparedLetter { > $letter->{'content-type'} = 'text/html; charset="UTF-8"' if $letter->{is_html}; > } > >+ my $objects = $params{objects} || {}; > my $tables = $params{tables} || {}; > my $substitute = $params{substitute} || {}; > my $loops = $params{loops} || {}; # loops is not supported for historical notices syntax > my $repeat = $params{repeat}; >- %$tables || %$substitute || $repeat || %$loops >- or carp( "ERROR: nothing to substitute - both 'tables', 'loops' and 'substitute' are empty" ), >+ %$tables || %$substitute || $repeat || %$loops || %$objects >+ or carp( "ERROR: nothing to substitute - all of 'objects', 'tables', 'loops' and 'substitute' are empty" ), > return; > my $want_librarian = $params{want_librarian}; > >@@ -718,20 +719,23 @@ sub GetPreparedLetter { > > $letter->{content} = _process_tt( > { >- content => $letter->{content}, >- tables => $tables, >- loops => $loops, >+ content => $letter->{content}, >+ lang => $lang, >+ loops => $loops, >+ objects => $objects, > substitute => $substitute, >- lang => $lang >+ tables => $tables, > } > ); > > $letter->{title} = _process_tt( > { >- content => $letter->{title}, >- tables => $tables, >- loops => $loops, >+ content => $letter->{title}, >+ lang => $lang, >+ loops => $loops, >+ objects => $objects, > substitute => $substitute, >+ tables => $tables, > } > ); > >@@ -1616,9 +1620,10 @@ sub _set_message_status { > sub _process_tt { > my ( $params ) = @_; > >- my $content = $params->{content}; >- my $tables = $params->{tables}; >- my $loops = $params->{loops}; >+ my $content = $params->{content}; >+ my $tables = $params->{tables}; >+ my $loops = $params->{loops}; >+ my $objects = $params->{objects}; > my $substitute = $params->{substitute} || {}; > my $lang = defined($params->{lang}) && $params->{lang} ne 'default' ? $params->{lang} : 'en'; > my ($theme, $availablethemes); >@@ -1645,7 +1650,7 @@ sub _process_tt { > } > ) or die Template->error(); > >- my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute }; >+ my $tt_params = { %{ _get_tt_params( $tables ) }, %{ _get_tt_params( $loops, 'is_a_loop' ) }, %$substitute, %$objects }; > > $content = add_tt_filters( $content ); > $content = qq|[% USE KohaDates %][% USE Remove_MARC_punctuation %]$content|; >diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t >index 127a98bd11..37bbf742ac 100755 >--- a/t/db_dependent/Letters/TemplateToolkit.t >+++ b/t/db_dependent/Letters/TemplateToolkit.t >@@ -19,7 +19,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 28; >+use Test::More tests => 29; > use Test::MockModule; > use Test::Warn; > >@@ -44,6 +44,7 @@ use Koha::Serial; > use Koha::Subscription; > use Koha::Suggestion; > use Koha::Checkout; >+use Koha::Patrons; > use Koha::Notice::Messages; > use Koha::Notice::Templates; > use Koha::Patron::Modification; >@@ -139,6 +140,17 @@ $prepared_letter = GetPreparedLetter( > is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref for content' ); > is( $prepared_letter->{title}, $patron->{firstname}, 'Patron object used correctly with arrayref for title' ); > >+$prepared_letter = GetPreparedLetter( >+ ( >+ module => 'test', >+ letter_code => 'TEST_PATRON', >+ objects => { >+ borrower => scalar Koha::Patrons->find( $patron->{borrowernumber} ), >+ }, >+ ) >+); >+is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly as object' ); >+ > $sth->execute( "TEST_BIBLIO", "[% biblio.title %]", "[% biblio.id %]" ); > $prepared_letter = GetPreparedLetter( > ( >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 19966
:
70470
|
71998
|
72013
|
123106
| 128546