View | Details | Raw Unified | Return to bug 22544
Collapse All | Expand All

(-)a/C4/NewsChannels.pm (-45 / +1 lines)
Lines 30-36 BEGIN { Link Here
30
    @ISA = qw(Exporter);
30
    @ISA = qw(Exporter);
31
    @EXPORT = qw(
31
    @EXPORT = qw(
32
        &GetNewsToDisplay
32
        &GetNewsToDisplay
33
        &add_opac_new &upd_opac_new
33
        &add_opac_new
34
    );
34
    );
35
}
35
}
36
36
Lines 79-128 sub add_opac_new { Link Here
79
    return $retval;
79
    return $retval;
80
}
80
}
81
81
82
=head2 upd_opac_new
83
84
    $retval = upd_opac_new($hashref);
85
86
    $hashref should contains all the fields found in opac_news,
87
    including idnew, since it is the key for the SQL UPDATE.
88
89
=cut
90
91
sub upd_opac_new {
92
    my ($href_entry) = @_;
93
    my $retval = 0;
94
95
    if ($href_entry) {
96
        $href_entry->{number} = 0 if $href_entry->{number} !~ /^\d+$/;
97
        # take the keys of hash entry and make a list, but...
98
        my @fields = keys %{$href_entry};
99
        my @values;
100
        $#values = -1;
101
        my $field_string = q{};
102
        foreach my $field_name (@fields) {
103
            # exclude idnew
104
            if ( $field_name ne 'idnew' ) {
105
                $field_string = $field_string . "$field_name = ?,";
106
                push @values,$href_entry->{$field_name};
107
            }
108
        }
109
        # put idnew at the end, so we know which record to update
110
        push @values,$href_entry->{'idnew'};
111
        chop $field_string; # remove that excess ,
112
113
        my $dbh = C4::Context->dbh;
114
        my $sth = $dbh->prepare("UPDATE opac_news SET $field_string WHERE idnew = ?;");
115
        $sth->execute(@values);
116
        $retval = 1;
117
    }
118
119
    #Log news entry modification
120
    if (C4::Context->preference("NewsLog")) {
121
            logaction('NEWS', 'MODIFY' , undef, $href_entry->{lang} . ' | ' . $href_entry->{content});
122
    }
123
    return $retval;
124
}
125
126
=head2 GetNewsToDisplay
82
=head2 GetNewsToDisplay
127
83
128
    $news = &GetNewsToDisplay($lang,$branch);
84
    $news = &GetNewsToDisplay($lang,$branch);
(-)a/t/db_dependent/NewsChannels.t (-11 / +1 lines)
Lines 6-12 use Koha::DateUtils; Link Here
6
use Koha::Libraries;
6
use Koha::Libraries;
7
use Koha::News;
7
use Koha::News;
8
8
9
use Test::More tests => 9;
9
use Test::More tests => 7;
10
10
11
BEGIN {
11
BEGIN {
12
    use_ok('C4::NewsChannels');
12
    use_ok('C4::NewsChannels');
Lines 125-140 $query = Link Here
125
q{ SELECT idnew from opac_news WHERE published_on='2000-01-02'; };
125
q{ SELECT idnew from opac_news WHERE published_on='2000-01-02'; };
126
my ( $idnew3 ) = $dbh->selectrow_array( $query );
126
my ( $idnew3 ) = $dbh->selectrow_array( $query );
127
127
128
# Test upd_opac_new
129
$rv = upd_opac_new();    # intentionally bad parmeters
130
is( $rv, 0, 'Correctly failed on no parameter!' );
131
132
$new2                 = '<p>Update! There is no news!</p>';
133
$href_entry2->{content}   = $new2;
134
$href_entry2->{idnew} = $idnew2;
135
$rv                   = upd_opac_new($href_entry2);
136
is( $rv, 1, 'Successfully updated second dummy news item!' );
137
138
# Test GetNewsToDisplay
128
# Test GetNewsToDisplay
139
my ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' );
129
my ( $opac_news_count, $arrayref_opac_news ) = GetNewsToDisplay( q{}, 'LIB1' );
140
ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay for LIB1!' );
130
ok( $opac_news_count >= 2, 'Successfully tested GetNewsToDisplay for LIB1!' );
(-)a/tools/koha-news.pl (-6 / +5 lines)
Lines 127-135 elsif ( $op eq 'add' ) { Link Here
127
    }
127
    }
128
}
128
}
129
elsif ( $op eq 'edit' ) {
129
elsif ( $op eq 'edit' ) {
130
    upd_opac_new(
130
    my $news_item = Koha::News->find( $id );
131
        {
131
    if ( $news_item ) {
132
            idnew          => $id,
132
        $news_item->set({
133
            title          => $title,
133
            title          => $title,
134
            content        => $content,
134
            content        => $content,
135
            lang           => $lang,
135
            lang           => $lang,
Lines 137-144 elsif ( $op eq 'edit' ) { Link Here
137
            published_on=> $published_on,
137
            published_on=> $published_on,
138
            number         => $number,
138
            number         => $number,
139
            branchcode     => $branchcode,
139
            branchcode     => $branchcode,
140
        }
140
        })->store;
141
    );
141
    }
142
    print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
142
    print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
143
}
143
}
144
elsif ( $op eq 'del' ) {
144
elsif ( $op eq 'del' ) {
145
- 

Return to bug 22544