|
Line 0
Link Here
|
|
|
1 |
use Modern::Perl; |
| 2 |
|
| 3 |
{ |
| 4 |
bug_number => "24223", |
| 5 |
description => "Move contents of OpacNav system preference into additional contents", |
| 6 |
up => sub { |
| 7 |
my ($args) = @_; |
| 8 |
my ($dbh, $out) = @$args{qw(dbh out)}; |
| 9 |
|
| 10 |
# get list of installed translations |
| 11 |
require C4::Languages; |
| 12 |
my @langs; |
| 13 |
my $tlangs = C4::Languages::getTranslatedLanguages(); |
| 14 |
|
| 15 |
foreach my $language ( @$tlangs ) { |
| 16 |
foreach my $sublanguage ( @{$language->{'sublanguages_loop'}} ) { |
| 17 |
push @langs, $sublanguage->{'rfc4646_subtag'}; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
# There must be a "default" entry in addition to language-specific ones |
| 22 |
push @langs, "default"; |
| 23 |
|
| 24 |
# Get any existing value from the OpacNav system preference |
| 25 |
my ($opacnav) = $dbh->selectrow_array( q| |
| 26 |
SELECT value FROM systempreferences WHERE variable='OpacNav'; |
| 27 |
|); |
| 28 |
if( $opacnav ){ |
| 29 |
# If there is a value in the OpacNav preference, insert it into additional_contents |
| 30 |
my $code = ''; |
| 31 |
foreach my $lang ( @langs ) { |
| 32 |
say $out "Inserting OpacNav contents into $lang news item..."; |
| 33 |
$dbh->do( "INSERT INTO additional_contents ( category, code, location, branchcode, title, content, lang, published_on ) VALUES ('html_customizations', '', 'OpacNav', NULL, ?, ?, ?, CAST(NOW() AS date) )", undef, "OpacNav $lang", $opacnav, $lang ); |
| 34 |
my $idnew = $dbh->last_insert_id(undef, undef, 'additional_contents', undef); |
| 35 |
if( $code eq '' ){ |
| 36 |
$code = "News_$idnew"; |
| 37 |
} |
| 38 |
$dbh->do(q|UPDATE additional_contents SET code=? WHERE idnew = ?|, undef, $code, $idnew); |
| 39 |
} |
| 40 |
|
| 41 |
# Remove the OpacNav system preference |
| 42 |
$dbh->do("DELETE FROM systempreferences WHERE variable='OpacNav'"); |
| 43 |
say $out "Bug 24223 update done"; |
| 44 |
} else { |
| 45 |
say $out "No OpacNav preference found. Update has already been run."; |
| 46 |
} |
| 47 |
|
| 48 |
}, |
| 49 |
} |