|
Line 0
Link Here
|
| 0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
use Koha::Installer::Output qw(say_warning say_success say_info); |
| 3 |
use Koha::AdditionalContents; |
| 4 |
|
| 5 |
return { |
| 6 |
bug_number => "9750", |
| 7 |
description => "Add serials routing list to notices", |
| 8 |
up => sub { |
| 9 |
my ($args) = @_; |
| 10 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
| 11 |
|
| 12 |
# Do you stuffs here |
| 13 |
$dbh->do( |
| 14 |
q{ |
| 15 |
INSERT IGNORE INTO letter |
| 16 |
(module, code, branchcode, name, is_html, title, content, message_transport_type, lang) |
| 17 |
VALUES ('serial','ROUTING_LIST','','Serials routing list',1,'','<table>\n<tr>\n<td colspan="2"><h3>[% branch.branchname %]</h3></td>\n</tr>\n<tr>\n<td colspan="2"><strong>Title:</strong> [% biblio.title %]<br />[% serial.serialseq %] ([% serial.planneddate | $KohaDates %])</td>\n</tr>\n<tr>\n<td><strong>Names:</strong></td>\n</tr>\n[% FOREACH borrower IN borrowers %]\n<tr>\n<td>[% borrower.firstname %] [% borrower.surname %]</td>\n</tr>\n[% END %]\n<tr>\n<td colspan="2"><strong>Notes:</strong> [% serial.routingnotes %]</td>\n</tr>\n</table>\n','print','default'); |
| 18 |
} |
| 19 |
); |
| 20 |
say_success( $out, "Added ROUTING_LIST letter" ); |
| 21 |
|
| 22 |
#get RoutingListNote from additional_contents |
| 23 |
my $routing_notes = Koha::AdditionalContents->search( |
| 24 |
{ |
| 25 |
location => 'RoutingListNote', |
| 26 |
} |
| 27 |
); |
| 28 |
|
| 29 |
my $translate_notices = C4::Context->preference('TranslateNotices'); |
| 30 |
|
| 31 |
while ( my $note = $routing_notes->next ) { |
| 32 |
my $branchcode = $note->branchcode || ''; |
| 33 |
my $localizations = $note->translated_contents->as_list; # Add ->as_list here |
| 34 |
|
| 35 |
if ($translate_notices) { |
| 36 |
|
| 37 |
#deal with each language |
| 38 |
foreach my $localization (@$localizations) { |
| 39 |
my $lang = $localization->lang; |
| 40 |
my $content = $localization->content; |
| 41 |
next unless $content; |
| 42 |
|
| 43 |
_append_routing_note( $dbh, $branchcode, $lang, $content ); |
| 44 |
} |
| 45 |
} else { |
| 46 |
|
| 47 |
#TranslateNotices, only move the default |
| 48 |
my ($default_localization) = grep { $_->lang eq 'default' } @$localizations; |
| 49 |
if ( $default_localization && $default_localization->content ) { |
| 50 |
_append_routing_note( $dbh, $branchcode, 'default', $default_localization->content ); |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
say_success( $out, "Added ROUTING_LIST letter and migrated routing notes" ); |
| 56 |
|
| 57 |
# Delete the RoutingListNote additional contents after migration |
| 58 |
$dbh->do( |
| 59 |
q{ |
| 60 |
DELETE FROM additional_contents |
| 61 |
WHERE location = 'RoutingListNote' |
| 62 |
} |
| 63 |
); |
| 64 |
|
| 65 |
say_success( |
| 66 |
$out, |
| 67 |
"Added ROUTING_LIST letter, migrated routing notes, and removed RoutingListNote additional contents" |
| 68 |
); |
| 69 |
}, |
| 70 |
}; |
| 71 |
|
| 72 |
sub _append_routing_note { |
| 73 |
my ( $dbh, $branchcode, $lang, $content ) = @_; |
| 74 |
|
| 75 |
# Check if letter exists for this branch/lang |
| 76 |
my $exists = $dbh->selectrow_array( |
| 77 |
q{ |
| 78 |
SELECT COUNT(*) FROM letter |
| 79 |
WHERE module = 'serial' AND code = 'ROUTING_LIST' |
| 80 |
AND branchcode = ? AND lang = ? |
| 81 |
}, |
| 82 |
undef, |
| 83 |
$branchcode, |
| 84 |
$lang |
| 85 |
); |
| 86 |
|
| 87 |
if ($exists) { |
| 88 |
|
| 89 |
# Append to existing letter |
| 90 |
$dbh->do( |
| 91 |
q{ |
| 92 |
UPDATE letter |
| 93 |
SET content = CONCAT(content, ?) |
| 94 |
WHERE module = 'serial' AND code = 'ROUTING_LIST' |
| 95 |
AND branchcode = ? AND lang = ? |
| 96 |
}, |
| 97 |
undef, |
| 98 |
"\n<div id=\"routingnotes\">\n$content\n</div>", |
| 99 |
$branchcode, |
| 100 |
$lang |
| 101 |
); |
| 102 |
} else { |
| 103 |
|
| 104 |
# Copy default letter and append note |
| 105 |
$dbh->do( |
| 106 |
q{ |
| 107 |
INSERT INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type, lang) |
| 108 |
SELECT module, code, ?, name, is_html, title, CONCAT(content, ?), message_transport_type, ? |
| 109 |
FROM letter |
| 110 |
WHERE module = 'serial' AND code = 'ROUTING_LIST' |
| 111 |
AND branchcode = '' AND lang = 'default' |
| 112 |
LIMIT 1 |
| 113 |
}, |
| 114 |
undef, |
| 115 |
$branchcode, |
| 116 |
"\n<div id=\"routingnotes\">\n$content\n</div>", |
| 117 |
$lang |
| 118 |
); |
| 119 |
} |
| 120 |
} |