Bug 23795: Convert opaccredits system preference to news block
[koha.git] / installer / data / mysql / atomicupdate / bug_23795-move-opaccredits-to-news.perl
1 $DBversion = 'XXX'; # will be replaced by the RM
2 if( CheckVersion( $DBversion ) ) {
3
4     # get list of installed translations
5     require C4::Languages;
6     my @langs;
7     my $tlangs = C4::Languages::getTranslatedLanguages();
8
9     foreach my $language ( @$tlangs ) {
10         foreach my $sublanguage ( @{$language->{'sublanguages_loop'}} ) {
11             push @langs, $sublanguage->{'rfc4646_subtag'};
12         }
13     }
14
15     # Get any existing value from the opaccredits system preference
16     my ($opaccredits) = $dbh->selectrow_array( q|
17         SELECT value FROM systempreferences WHERE variable='opaccredits';
18     |);
19     if( $opaccredits ){
20         foreach my $lang ( @langs ) {
21             print "Inserting opaccredits contents into $lang news item...\n";
22             # If there is a value in the opaccredits preference, insert it into opac_news
23             $dbh->do("INSERT INTO opac_news (branchcode, lang, title, content ) VALUES (NULL, ?, '', ?)", undef, "opaccredits_$lang", $opaccredits);
24         }
25     }
26     # Remove the opaccredits system preference
27     $dbh->do("DELETE FROM systempreferences WHERE variable='opaccredits'");
28     SetVersion ($DBversion);
29     print "Upgrade to $DBversion done (Bug 23795: Convert OpacCredits system preference to news block)\n";
30 }