From 8f7f472469fbea2fc1fb38bb0c84d58bebc1a4f7 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 11 Dec 2019 16:24:50 +0000 Subject: [PATCH] Bug 23794: Convert OpacMainUserBlock system preference to news block Content-Type: text/plain; charset=utf-8 This patch builds on Bug 22318 to move the OpacMainUserBlock system preference into the Koha news system, making it possible to have language- and library-specific content. To test you should have some content in the OpacMainUserBlock system preference. Apply the patch and run the database update process. - Go to the OPAC and confirm that the content which was previously in the OpacMainUserBlock system preference now displays correctly where it was before. - In the staff client, go to Tools -> News and verify that the content from OpacMainUserBlock is now stored in news items. There should be one entry for each of the enabled translations in your system, for instance 'opacmainuserblock_en', 'opacmainuserblock_fr-FR', 'opacmainuserblock_cs-CZ' - Go to Administration -> System preferences and confirm that the OpacMainUserBlock preference has been removed. Signed-off-by: Bernardo Gonzalez Kriegel Works like a charm. Don't forget to run ./translate update/install for your language(s) after the patch Signed-off-by: Marcel de Rooy --- C4/Auth.pm | 1 - .../bug_23794-move-opacmainuserblock-to-news.perl | 30 ++++++++++++++++++++++ installer/data/mysql/sysprefs.sql | 1 - .../prog/en/modules/admin/preferences/opac.pref | 6 ----- .../prog/en/modules/tools/koha-news.tt | 2 +- .../opac-tmpl/bootstrap/en/modules/opac-main.tt | 9 +++++-- 6 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_23794-move-opacmainuserblock-to-news.perl diff --git a/C4/Auth.pm b/C4/Auth.pm index 1f79ef6187..6889c2532c 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -572,7 +572,6 @@ sub get_template_and_user { OpacBrowser => C4::Context->preference("OpacBrowser"), OpacCloud => C4::Context->preference("OpacCloud"), OpacKohaUrl => C4::Context->preference("OpacKohaUrl"), - OpacMainUserBlock => "" . C4::Context->preference("OpacMainUserBlock"), OpacNav => "" . C4::Context->preference("OpacNav"), OpacNavBottom => "" . C4::Context->preference("OpacNavBottom"), OpacPasswordChange => C4::Context->preference("OpacPasswordChange"), diff --git a/installer/data/mysql/atomicupdate/bug_23794-move-opacmainuserblock-to-news.perl b/installer/data/mysql/atomicupdate/bug_23794-move-opacmainuserblock-to-news.perl new file mode 100644 index 0000000000..ac0389f2b9 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_23794-move-opacmainuserblock-to-news.perl @@ -0,0 +1,30 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + # get list of installed translations + require C4::Languages; + my @langs; + my $tlangs = C4::Languages::getTranslatedLanguages(); + + foreach my $language ( @$tlangs ) { + foreach my $sublanguage ( @{$language->{'sublanguages_loop'}} ) { + push @langs, $sublanguage->{'rfc4646_subtag'}; + } + } + + # Get any existing value from the OpacMainUserBlock system preference + my ($opacmainuserblock) = $dbh->selectrow_array( q| + SELECT value FROM systempreferences WHERE variable='OpacMainUserBlock'; + |); + if( $opacmainuserblock ){ + foreach my $lang ( @langs ) { + print "Inserting OpacMainUserBlock contents into $lang news item...\n"; + # If there is a value in the OpacMainUserBlock preference, insert it into opac_news + $dbh->do("INSERT INTO opac_news (branchcode, lang, title, content ) VALUES (NULL, ?, '', ?)", undef, "OpacMainUserBlock_$lang", $opacmainuserblock); + } + } + # Remove the OpacMainUserBlock system preference + $dbh->do("DELETE FROM systempreferences WHERE variable='OpacMainUserBlock'"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (Bug 23794: Move contents of OpacMainUserBlock preference to Koha news system)\n"; +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index ead29651f5..5bcc474ddf 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -409,7 +409,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OpacLoginInstructions', '', '60|10', 'Instructions to display on the OPAC login form when a patron is not logged in', 'Textarea'), ('OpacMaintenance','0','','If ON, enables maintenance warning in OPAC','YesNo'), ('OpacMaintenanceNotice','','','A user-defined block of HTML to appear on screen when OpacMaintenace is enabled','Textarea'), -('OpacMainUserBlock','Welcome to Koha...\r\n
','70|10','A user-defined block of HTML in the main content area of the opac main page','Textarea'), ('OpacMaxItemsToDisplay','50','','Max items to display at the OPAC on a biblio detail','Integer'), ('OpacMoreSearches', '', NULL, 'Add additional elements to the OPAC more searches bar', 'Textarea'), ('OPACMySummaryHTML','','70|10','Enter the HTML that will appear in a column on the \'my summary\' and \'my reading history\' tabs when a user is logged in to the OPAC. Enter {BIBLIONUMBER}, {TITLE}, {AUTHOR}, or {ISBN} in place of their respective variables in the HTML. Leave blank to disable.','Textarea'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 550c0bafc1..7169962c84 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -241,12 +241,6 @@ OPAC: syntax: css class: code - - - "Show the following HTML in its own column on the main page of the OPAC:" - - pref: OpacMainUserBlock - type: textarea - syntax: text/html - class: code - - - "Show the following HTML on the left hand column of the main page and patron account on the OPAC (generally navigation links):" - pref: OpacNav type: textarea diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt index a3ff180cd4..062f0e1642 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt @@ -331,7 +331,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %] [% END %] [% FOREACH lang_lis IN lang_list %] - [% FOREACH location IN [ '', 'OpacNavRight', 'opacheader' ] %] + [% FOREACH location IN [ '', 'OpacNavRight', 'opacheader', 'OpacMainUserBlock' ] %] [% IF ( location == '' ) %] [% SET location_lang = lang_lis.language %] [% location = BLOCK %]OPAC news[% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt index dc307471e4..e9b4e34616 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -5,6 +5,8 @@ [% USE Categories %] [% USE Price %] [% USE KohaNews %] +[% SET OpacNavRight = KohaNews.get( location => "OpacNavRight", lang => lang, library => branchcode ) %] +[% SET OpacMainUserBlock = KohaNews.get( location => "OpacMainUserBlock", lang => lang, library => branchcode ) %] [% INCLUDE 'doc-head-open.inc' %] [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog [% INCLUDE 'doc-head-close.inc' %] @@ -42,7 +44,6 @@ [% END %] - [% SET OpacNavRight = KohaNews.get( location => "OpacNavRight", lang => lang, library => branchcode ) %] [% IF ( OpacNav || OpacNavBottom ) && (Koha.Preference( 'opacuserlogin' ) == 1 || OpacNavRight) %]
[% ELSIF (Koha.Preference( 'opacuserlogin' ) == 1 || OpacNavRight) %] @@ -150,7 +151,11 @@
[% END %] - [% IF ( OpacMainUserBlock ) %]
[% OpacMainUserBlock | $raw %]
[% END %] + [% IF ( OpacMainUserBlock ) %] +
+ [% PROCESS koha_news_block news => OpacMainUserBlock %] +
+ [% END %] [% END %] -- 2.11.0