From 3d5a7199208193ded7ea4edcdabee7a186cc98e1 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Tue, 19 Mar 2019 10:30:27 +0000 Subject: [PATCH] Bug 22544: Move upd_opac_new to Koha namespace Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- C4/NewsChannels.pm | 46 +---------------------------------- t/db_dependent/NewsChannels.t | 12 +-------- tools/koha-news.pl | 10 ++++---- 3 files changed, 7 insertions(+), 61 deletions(-) diff --git a/C4/NewsChannels.pm b/C4/NewsChannels.pm index 2126b40184..7d1a91a1e1 100644 --- a/C4/NewsChannels.pm +++ b/C4/NewsChannels.pm @@ -30,7 +30,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &GetNewsToDisplay - &add_opac_new &upd_opac_new + &add_opac_new ); } @@ -79,50 +79,6 @@ sub add_opac_new { return $retval; } -=head2 upd_opac_new - - $retval = upd_opac_new($hashref); - - $hashref should contains all the fields found in opac_news, - including idnew, since it is the key for the SQL UPDATE. - -=cut - -sub upd_opac_new { - my ($href_entry) = @_; - my $retval = 0; - - if ($href_entry) { - $href_entry->{number} = 0 if $href_entry->{number} !~ /^\d+$/; - # take the keys of hash entry and make a list, but... - my @fields = keys %{$href_entry}; - my @values; - $#values = -1; - my $field_string = q{}; - foreach my $field_name (@fields) { - # exclude idnew - if ( $field_name ne 'idnew' ) { - $field_string = $field_string . "$field_name = ?,"; - push @values,$href_entry->{$field_name}; - } - } - # put idnew at the end, so we know which record to update - push @values,$href_entry->{'idnew'}; - chop $field_string; # remove that excess , - - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("UPDATE opac_news SET $field_string WHERE idnew = ?;"); - $sth->execute(@values); - $retval = 1; - } - - #Log news entry modification - if (C4::Context->preference("NewsLog")) { - logaction('NEWS', 'MODIFY' , undef, $href_entry->{lang} . ' | ' . $href_entry->{content}); - } - return $retval; -} - =head2 GetNewsToDisplay $news = &GetNewsToDisplay($lang,$branch); diff --git a/t/db_dependent/NewsChannels.t b/t/db_dependent/NewsChannels.t index 60ec4fb961..3a3b66315a 100755 --- a/t/db_dependent/NewsChannels.t +++ b/t/db_dependent/NewsChannels.t @@ -6,7 +6,7 @@ use Koha::DateUtils; use Koha::Libraries; use Koha::News; -use Test::More tests => 9; +use Test::More tests => 7; BEGIN { use_ok('C4::NewsChannels'); @@ -125,16 +125,6 @@ $query = q{ SELECT idnew from opac_news WHERE published_on='2000-01-02'; }; my ( $idnew3 ) = $dbh->selectrow_array( $query ); -# Test upd_opac_new -$rv = upd_opac_new(); # intentionally bad parmeters -is( $rv, 0, 'Correctly failed on no parameter!' ); - -$new2 = '

Update! There is no news!

'; -$href_entry2->{content} = $new2; -$href_entry2->{idnew} = $idnew2; -$rv = upd_opac_new($href_entry2); -is( $rv, 1, 'Successfully updated second dummy news item!' ); - # Test GetNewsToDisplay my ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' ); ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay for LIB1!' ); diff --git a/tools/koha-news.pl b/tools/koha-news.pl index ab6c89c5d4..ce41b5419d 100755 --- a/tools/koha-news.pl +++ b/tools/koha-news.pl @@ -127,9 +127,9 @@ elsif ( $op eq 'add' ) { } } elsif ( $op eq 'edit' ) { - upd_opac_new( - { - idnew => $id, + my $news_item = Koha::News->find( $id ); + if ( $news_item ) { + $news_item->set({ title => $title, content => $content, lang => $lang, @@ -137,8 +137,8 @@ elsif ( $op eq 'edit' ) { published_on=> $published_on, number => $number, branchcode => $branchcode, - } - ); + })->store; + } print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl"); } elsif ( $op eq 'del' ) { -- 2.39.5