ac0389f2b96c370efa083d2032c9a20a9a737370
[koha-equinox.git] / installer / data / mysql / atomicupdate / bug_23794-move-opacmainuserblock-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 OpacMainUserBlock system preference
16     my ($opacmainuserblock) = $dbh->selectrow_array( q|
17         SELECT value FROM systempreferences WHERE variable='OpacMainUserBlock';
18     |);
19     if( $opacmainuserblock ){
20         foreach my $lang ( @langs ) {
21             print "Inserting OpacMainUserBlock contents into $lang news item...\n";
22             # If there is a value in the OpacMainUserBlock preference, insert it into opac_news
23             $dbh->do("INSERT INTO opac_news (branchcode, lang, title, content ) VALUES (NULL, ?, '', ?)", undef, "OpacMainUserBlock_$lang", $opacmainuserblock);
24         }
25     }
26     # Remove the OpacMainUserBlock system preference
27     $dbh->do("DELETE FROM systempreferences WHERE variable='OpacMainUserBlock'");
28     SetVersion ($DBversion);
29     print "Upgrade to $DBversion done (Bug 23794: Move contents of OpacMainUserBlock preference to Koha news system)\n";
30 }