From 0bdfedc13e63f3e70ace2eac37b04307cd39d75b 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. Test plan 1/ Run the database update 2/ Check that the templates have been replaced by the defaults (for all languages enabled) 3/ Check that a backup of the original notices was made by naviagating to view the action log (/tools/viewlog.pl) and selecting 'all modules' + 'all actions' Signed-off-by: Kyle M Hall Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- .../data/mysql/atomicupdate/bug_26734.perl | 184 ++++++++++++++---- 1 file changed, 145 insertions(+), 39 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_26734.perl b/installer/data/mysql/atomicupdate/bug_26734.perl index 5ff88aaa87..faabb6b91b 100644 --- a/installer/data/mysql/atomicupdate/bug_26734.perl +++ b/installer/data/mysql/atomicupdate/bug_26734.perl @@ -1,45 +1,151 @@ $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(q{ + INSERT INTO action_logs ( timestamp, module, action, object, info, interface ) + SELECT NOW(), 'NOTICES', 'UPGRADE', id, content, 'cli' + FROM letter + WHERE lang = ? AND code = 'ACCOUNT_CREDIT' + }); + + for my $c ( @{$credit_arr} ) { + $c_sth->execute( $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 = ?, is_html = 1 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(q{ + INSERT INTO action_logs ( timestamp, module, action, object, info, interface ) + SELECT NOW(), 'NOTICES', 'UPGRADE', id, content, 'cli' + FROM letter + WHERE lang = ? AND code = 'ACCOUNT_DEBIT' + }); + + for my $d ( @{$debit_arr} ) { + $d_sth->execute( $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 = ?, is_html = 1 WHERE code = 'ACCOUNT_DEBIT'"); + $d_insert->execute($d_notice); + + NewVersion( $DBversion, 26734, "Update notices to use defaults" ); } -- 2.39.5