From fceb8c899f25014a7833fd3daaf1187d7fc10a57 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 3 Feb 2021 14:49:04 +0000 Subject: [PATCH] Bug 26734: (follow-up) Replace db update with backup and default The inline update of variable for the notice template was proving troublesome.. this patch replaces it was a backup of the existing notice followed by replacing the notice with the default. --- .../data/mysql/atomicupdate/bug_26734.perl | 178 ++++++++++++++---- 1 file changed, 139 insertions(+), 39 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_26734.perl b/installer/data/mysql/atomicupdate/bug_26734.perl index 5ff88aaa87..d7ddabad82 100644 --- a/installer/data/mysql/atomicupdate/bug_26734.perl +++ b/installer/data/mysql/atomicupdate/bug_26734.perl @@ -1,45 +1,145 @@ $DBversion = 'XXX'; -if( CheckVersion( $DBversion ) ) { +if ( CheckVersion($DBversion) ) { # ACCOUNT_CREDIT UPDATES - # replace patron variable with credit.patron - $dbh->do("UPDATE letter SET content = REPLACE(content, '[% patron', '[% credit.patron') WHERE code = 'ACCOUNT_CREDIT' "); - # replace library variable with credit.library.branchname - $dbh->do("UPDATE letter SET content = REPLACE(content, '[% library', '[% credit.library.branchname') WHERE code = 'ACCOUNT_CREDIT' "); - - # replace offsets variable with credit.offsets - $dbh->do("UPDATE letter SET content = REPLACE(content, ' offsets %]', ' credit.offsets %]') WHERE code = 'ACCOUNT_CREDIT' "); - # replace change_given variable with change - $dbh->do("UPDATE letter SET content = REPLACE(content, '[% change_given', '[% change') WHERE code = 'ACCOUNT_CREDIT' "); - - # replace accounts foreach with basic check - $dbh->do("UPDATE letter SET content = REPLACE(content, '[% FOREACH account IN accounts %]', '[% IF credit %]') WHERE code = 'ACCOUNT_CREDIT' "); - # replace account with credit - $dbh->do("UPDATE letter SET content = REPLACE(content, 'account.', 'credit.') WHERE code = 'ACCOUNT_CREDIT' "); - # replace amountcredit with amount >= 0 - $dbh->do("UPDATE letter SET content = REPLACE(content, '( credit.amountcredit )', '( credit.amount <= 0 )') WHERE code = 'ACCOUNT_CREDIT' "); + # backup existing notice to action_logs + my $credit_arr = $dbh->selectall_arrayref( + "SELECT lang FROM letter WHERE code = 'ACCOUNT_CREDIT'", { Slice => {} }); + my $c_sth = $dbh->prepare( +"INSERT INTO action_logs ( timestamp, module, action, info, interface ) VALUES ( NOW(), 'NOTICES', ?, (SELECT content FROM letter WHERE lang = ? AND code = 'ACCOUNT_CREDIT' ), 'cli' )" + ); + + for my $c ( @{$credit_arr} ) { + $c_sth->execute( 'ACCOUNT_CREDIT_' . $c->{lang}, $c->{lang} ); + } + + # replace notice with default + my $c_notice = q{ +[% USE Price %] +[% PROCESS 'accounts.inc' %] + +[% IF ( LibraryName ) %] + + + +[% END %] + + + + + + + + + + + + + + + + + + + + + + + + + + + [% IF ( credit.patron.account.balance >= 0 ) %] + + +
+

[% LibraryName | html %]

+
+

Fee receipt

+
+

[% Branches.GetName( credit.patron.branchcode ) | html %]

+
+ Received with thanks from [% credit.patron.firstname | html %] [% credit.patron.surname | html %]
+ Card number: [% credit.patron.cardnumber | html %]
+
DateDescription of chargesNoteAmount
[% credit.date | $KohaDates %] + [% PROCESS account_type_description account=credit %] + [%- IF credit.description %], [% credit.description | html %][% END %] + [% credit.note | html %][% credit.amount | $Price %]
Total outstanding dues as on date: [% ELSE %][% END %][% credit.patron.account.balance | $Price %]
+ }; + + my $c_insert = $dbh->prepare("UPDATE letter SET content = ? WHERE code = 'ACCOUNT_CREDIT'"); + $c_insert->execute($c_notice); # ACCOUNT_DEBIT UPDATES - # replace patron variable with debit.patron - $dbh->do("UPDATE letter SET content = REPLACE(content, '[% patron', '[% debit.patron') WHERE code = 'ACCOUNT_DEBIT' "); - # replace library variable with debit.library.branchname - $dbh->do("UPDATE letter SET content = REPLACE(content, '[% library', '[% debit.library.branchname') WHERE code = 'ACCOUNT_DEBIT' "); - # replace offsets variable with debit.offsets - $dbh->do("UPDATE letter SET content = REPLACE(content, ' offsets %]', ' debit.offsets %]') WHERE code = 'ACCOUNT_DEBIT' "); - - # replace accounts foreach with basic check - $dbh->do("UPDATE letter SET content = REPLACE(content, '[% FOREACH account IN accounts %]', '[% IF debit %]') WHERE code = 'ACCOUNT_DEBIT' "); - # replace account with debit - $dbh->do("UPDATE letter SET content = REPLACE(content, 'account.', 'debit.') WHERE code = 'ACCOUNT_DEBIT' "); - # replace amountcredit with amount >= 0 - $dbh->do("UPDATE letter SET content = REPLACE(content, '( debit.amountcredit )', '( debit.amount <= 0 )') WHERE code = 'ACCOUNT_DEBIT' "); - # replace amountoutstandingcredit with amount >= 0 - $dbh->do("UPDATE letter SET content = REPLACE(content, '( debit.amountoutstandingcredit )', '( debit.amountoutstanding <= 0 )') WHERE code = 'ACCOUNT_DEBIT' "); - - # replace total variable with debit.patron.account.balance - $dbh->do("UPDATE letter SET content = REPLACE(content, '[% total ', '[% debit.patron.account.balance ') WHERE code = 'ACCOUNT_DEBIT' "); - # replace totalcredit variable with debit.patron.account.balance <= 0 - $dbh->do("UPDATE letter SET content = REPLACE(content, 'totalcredit', 'debit.patron.account.balance <= 0') WHERE code = 'ACCOUNT_DEBIT' "); - - NewVersion( $DBversion, 26734, "Update notices to use standard variables"); + # backup existing notice to action_logs + my $debit_arr = $dbh->selectall_arrayref( + "SELECT lang FROM letter WHERE code = 'ACCOUNT_DEBIT'", { Slice => {} }); + my $d_sth = $dbh->prepare( +"INSERT INTO action_logs ( timestamp, module, action, info, interface ) VALUES ( NOW(), 'NOTICES', ?, (SELECT content FROM letter WHERE lang = ? AND code = 'ACCOUNT_DEBIT' ), 'cli' )" + ); + + for my $d ( @{$debit_arr} ) { + $d_sth->exedute( 'ACCOUNT_DEBIT_' . $d->{lang}, $d->{lang} ); + } + + # replace notice with default + my $d_notice = q{ +[% USE Price %] +[% PROCESS 'accounts.inc' %] + + [% IF ( LibraryName ) %] + + + + [% END %] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [% IF ( debit.patron.account.balance <= 0 ) %] + + +
+

[% LibraryName | html %]

+
+

INVOICE

+
+

[% Branches.GetName( debit.patron.branchcode ) | html %]

+
+ Bill to: [% debit.patron.firstname | html %] [% debit.patron.surname | html %]
+ Card number: [% debit.patron.cardnumber | html %]
+
DateDescription of chargesNoteAmountAmount outstanding
[% debit.date | $KohaDates%] + [% PROCESS account_type_description account=debit %] + [%- IF debit.description %], [% debit.description | html %][% END %] + [% debit.note | html %][% debit.amount | $Price %][% debit.amountoutstanding | $Price %]
Total outstanding dues as on date: [% ELSE %][% END %][% debit.patron.account.balance | $Price %]
+ }; + my $d_insert = $dbh->prepare("UPDATE letter SET content = ? WHERE code = 'ACCOUNT_DEBIT'"); + $d_insert->execute($d_notice); + + NewVersion( $DBversion, 26734, "Update notices to use defaults" ); } -- 2.20.1