From a233f06574f5ca6417245cba58162af1360bf327 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Jan 2017 08:29:23 +0100 Subject: [PATCH] Bug 17960: Rename opac_news.new with opac_news.content The field opac_news.new is very confusing and should be renamed. If you want to access it via Koha::NewsItem you will have trouble: use Koha::News; my $news_item = Koha::News->next; say $news_item->new; => Attempt to bless into a reference at /home/vagrant/kohaclone/Koha/Object.pm line 78. This patchset is going to rename this DB field to opac_news_content instead. Since the opac_news.new can be used in notice templates, we need to warn the user during the update DB process that some templates must be updated. Test plan: 0/ Apply the first patch "Add a test to highlight the issue" and confirm that the test fail 1/ Apply this second patch 2/ Execute the DB entry 3/ Confirm that you get a warning if at least one of your notice templates is using opac_news.new 4/ Confirm that the test new pass 5/ Add/update and delete a news 6/ Confirm that the RSS new feed still works as expected Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens Signed-off-by: Kyle M Hall --- .../data/mysql/atomicupdate/bug_17960.perl | 18 ++++++++++++++++++ installer/data/mysql/kohastructure.sql | 2 +- .../prog/en/modules/tools/koha-news.tt | 6 +++--- .../bootstrap/en/modules/opac-news-rss.tt | 2 +- t/db_dependent/Koha/News.t | 2 +- t/db_dependent/NewsChannels.t | 12 ++++++------ tools/koha-news.pl | 6 +++--- 7 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_17960.perl diff --git a/installer/data/mysql/atomicupdate/bug_17960.perl b/installer/data/mysql/atomicupdate/bug_17960.perl new file mode 100644 index 0000000000..003787de21 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_17960.perl @@ -0,0 +1,18 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + + if ( column_exists('opac_news', 'new' ) ) { + $dbh->do(q|ALTER TABLE opac_news CHANGE COLUMN new content text NOT NULL|); + } + + my ( $used_in_templates ) = $dbh->selectrow_array(q| + SELECT COUNT(*) FROM letter WHERE content LIKE "%<>%"; + |); + if ( $used_in_templates ) { + print "WARNING - It seems that you are using the opac_news.new column in your notice templates\n"; + print "Since it has now been renamed with opac_news.content, you should update them.\n"; + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 17960 - Rename opac_news with opac_news.content)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index cc57e3d9fa..7f405c966e 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1834,7 +1834,7 @@ CREATE TABLE `opac_news` ( -- data from the news tool `idnew` int(10) unsigned NOT NULL auto_increment, -- unique identifier for the news article `branchcode` varchar(10) default NULL, -- branch code users to create branch specific news, NULL is every branch. `title` varchar(250) NOT NULL default '', -- title of the news article - `new` text NOT NULL, -- the body of your news article + `content` text NOT NULL, -- the body of your news article `lang` varchar(25) NOT NULL default '', -- location for the article (koha is the staff client, slip is the circulation receipt and language codes are for the opac) `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- pulibcation date and time `expirationdate` date default NULL, -- date the article is set to expire or no longer be visible 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 13d8e9440a..dd1ae8404e 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 @@ -161,8 +161,8 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %] [% END %] -
  • - +
  • +
  • @@ -254,7 +254,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %] [% opac_new.title %] [% opac_new.author_title %] [% opac_new.author_firstname %] [% opac_new.author_surname %] - [% opac_new.new %] + [% opac_new.content %] Edit diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-news-rss.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-news-rss.tt index ac952f599b..aa18011a05 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-news-rss.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-news-rss.tt @@ -8,7 +8,7 @@ [% FOREACH newsitem IN koha_news %] [% newsitem.title |html %] - [% newsitem.new |html %] + [% newsitem.content |html %] [% OPACBaseURL %]/cgi-bin/koha/opac-main.pl#newsitem[% newsitem.idnew |html %] [% END %] diff --git a/t/db_dependent/Koha/News.t b/t/db_dependent/Koha/News.t index 09095b4f49..debae2606e 100644 --- a/t/db_dependent/Koha/News.t +++ b/t/db_dependent/Koha/News.t @@ -47,7 +47,7 @@ is( Koha::News->search->count, $nb_of_news + 2, 'The 2 news should have been add my $retrieved_news_item_1 = Koha::News->find( $new_news_item_1->idnew ); is( $retrieved_news_item_1->title, $new_news_item_1->title, 'Find a news_item by id should return the correct news_item' ); -is( $retrieved_news_item_1->new, $new_news_item_1->new, 'This test is failing because ->new is not a valid accessor'); +is( $retrieved_news_item_1->content, $new_news_item_1->content, 'The content method return the content of the news'); $retrieved_news_item_1->delete; is( Koha::News->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' ); diff --git a/t/db_dependent/NewsChannels.t b/t/db_dependent/NewsChannels.t index 812a366cd4..ce1524723e 100644 --- a/t/db_dependent/NewsChannels.t +++ b/t/db_dependent/NewsChannels.t @@ -72,7 +72,7 @@ my ( $title1, $new1, $lang1, $expirationdate1, $number1 ) = ( 'News Title', '

    We have some exciting news!

    ', q{}, '2999-12-30', 1 ); my $href_entry1 = { title => $title1, - new => $new1, + content => $new1, lang => $lang1, expirationdate => $expirationdate1, timestamp => $timestamp1, @@ -87,7 +87,7 @@ my ( $title2, $new2, $lang2, $expirationdate2, $number2 ) = ( 'News Title2', '

    We have some exciting news!

    ', q{}, '2999-12-31', 1 ); my $href_entry2 = { title => $title2, - new => $new2, + content => $new2, lang => $lang2, expirationdate => $expirationdate2, timestamp => $timestamp2, @@ -102,7 +102,7 @@ my ( $title3, $new3, $lang3, $number3 ) = ( 'News Title3', '

    News without expiration date

    ', q{}, 1 ); my $href_entry3 = { title => $title3, - new => $new3, + content => $new3, lang => $lang3, timestamp => $timestamp3, number => $number3, @@ -130,7 +130,7 @@ $rv = upd_opac_new(); # intentionally bad parmeters is( $rv, 0, 'Correctly failed on no parameter!' ); $new2 = '

    Update! There is no news!

    '; -$href_entry2->{new} = $new2; +$href_entry2->{content} = $new2; $href_entry2->{idnew} = $idnew2; $rv = upd_opac_new($href_entry2); is( $rv, 1, 'Successfully updated second dummy news item!' ); @@ -145,7 +145,7 @@ is_deeply( get_opac_new($idnew1), { title => $title1, - new => $new1, + content => $new1, lang => $lang1, expirationdate => $expirationdate1, timestamp => $timestamp1, @@ -168,7 +168,7 @@ is_deeply( get_opac_new($idnew2), { title => $title2, - new => $new2, + content => $new2, lang => $lang2, expirationdate => $expirationdate2, timestamp => $timestamp2, diff --git a/tools/koha-news.pl b/tools/koha-news.pl index 53b943d1f8..61c3ec606f 100755 --- a/tools/koha-news.pl +++ b/tools/koha-news.pl @@ -38,7 +38,7 @@ my $cgi = new CGI; my $id = $cgi->param('id'); my $title = $cgi->param('title'); -my $new = $cgi->param('new'); +my $content = $cgi->param('content'); my $expirationdate; if ( $cgi->param('expirationdate') ) { $expirationdate = output_pref({ dt => dt_from_string( scalar $cgi->param('expirationdate') ), dateformat => 'iso', dateonly => 1 }); @@ -107,7 +107,7 @@ elsif ( $op eq 'add' ) { add_opac_new( { title => $title, - new => $new, + content => $content, lang => $lang, expirationdate => $expirationdate, timestamp => $timestamp, @@ -127,7 +127,7 @@ elsif ( $op eq 'edit' ) { { idnew => $id, title => $title, - new => $new, + content => $content, lang => $lang, expirationdate => $expirationdate, timestamp => $timestamp, -- 2.39.5