From 090ad73ed14916a2ad3790c85daa877ca3aaff95 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 20 Nov 2025 21:58:57 +0000 Subject: [PATCH] Bug 9750: DB updates --- installer/data/mysql/atomicupdate/bug_9750.pl | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100755 installer/data/mysql/atomicupdate/bug_9750.pl diff --git a/installer/data/mysql/atomicupdate/bug_9750.pl b/installer/data/mysql/atomicupdate/bug_9750.pl new file mode 100755 index 00000000000..fceda63662d --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_9750.pl @@ -0,0 +1,120 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); +use Koha::AdditionalContents; + +return { + bug_number => "9750", + description => "Add serials routing list to notices", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + # Do you stuffs here + $dbh->do( + q{ + INSERT IGNORE INTO letter + (module, code, branchcode, name, is_html, title, content, message_transport_type, lang) + VALUES ('serial','ROUTING_LIST','','Serials routing list',1,'','\n\n\n\n\n\n\n\n\n\n[% FOREACH borrower IN borrowers %]\n\n\n\n[% END %]\n\n\n\n

[% branch.branchname %]

Title: [% biblio.title %]
[% serial.serialseq %] ([% serial.planneddate | $KohaDates %])
Names:
[% borrower.firstname %] [% borrower.surname %]
Notes: [% serial.routingnotes %]
\n','print','default'); + } + ); + say_success( $out, "Added ROUTING_LIST letter" ); + + #get RoutingListNote from additional_contents + my $routing_notes = Koha::AdditionalContents->search( + { + location => 'RoutingListNote', + } + ); + + my $translate_notices = C4::Context->preference('TranslateNotices'); + + while ( my $note = $routing_notes->next ) { + my $branchcode = $note->branchcode || ''; + my $localizations = $note->translated_contents->as_list; # Add ->as_list here + + if ($translate_notices) { + + #deal with each language + foreach my $localization (@$localizations) { + my $lang = $localization->lang; + my $content = $localization->content; + next unless $content; + + _append_routing_note( $dbh, $branchcode, $lang, $content ); + } + } else { + + #TranslateNotices, only move the default + my ($default_localization) = grep { $_->lang eq 'default' } @$localizations; + if ( $default_localization && $default_localization->content ) { + _append_routing_note( $dbh, $branchcode, 'default', $default_localization->content ); + } + } + } + + say_success( $out, "Added ROUTING_LIST letter and migrated routing notes" ); + + # Delete the RoutingListNote additional contents after migration + $dbh->do( + q{ + DELETE FROM additional_contents + WHERE location = 'RoutingListNote' + } + ); + + say_success( + $out, + "Added ROUTING_LIST letter, migrated routing notes, and removed RoutingListNote additional contents" + ); + }, +}; + +sub _append_routing_note { + my ( $dbh, $branchcode, $lang, $content ) = @_; + + # Check if letter exists for this branch/lang + my $exists = $dbh->selectrow_array( + q{ + SELECT COUNT(*) FROM letter + WHERE module = 'serial' AND code = 'ROUTING_LIST' + AND branchcode = ? AND lang = ? + }, + undef, + $branchcode, + $lang + ); + + if ($exists) { + + # Append to existing letter + $dbh->do( + q{ + UPDATE letter + SET content = CONCAT(content, ?) + WHERE module = 'serial' AND code = 'ROUTING_LIST' + AND branchcode = ? AND lang = ? + }, + undef, + "\n
\n$content\n
", + $branchcode, + $lang + ); + } else { + + # Copy default letter and append note + $dbh->do( + q{ + INSERT INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type, lang) + SELECT module, code, ?, name, is_html, title, CONCAT(content, ?), message_transport_type, ? + FROM letter + WHERE module = 'serial' AND code = 'ROUTING_LIST' + AND branchcode = '' AND lang = 'default' + LIMIT 1 + }, + undef, + $branchcode, + "\n
\n$content\n
", + $lang + ); + } +} -- 2.39.5