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

(-)a/C4/Images.pm (-235 lines)
Lines 1-235 Link Here
1
package C4::Images;
2
3
# Copyright (C) 2011 C & P Bibliography Services
4
# Jared Camins-Esakov <jcamins@cpbibliograpy.com>
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
use Modern::Perl;
22
23
use C4::Context;
24
use GD;
25
use Koha::Exceptions;
26
27
use vars qw($debug $noimage @ISA @EXPORT);
28
29
BEGIN {
30
31
    require Exporter;
32
    @ISA    = qw(Exporter);
33
    @EXPORT = qw(
34
      &PutImage
35
      &RetrieveImage
36
      &ListImagesForBiblio
37
      &DelImage
38
    );
39
    $debug = $ENV{KOHA_DEBUG} || $ENV{DEBUG} || 0;
40
41
    $noimage = pack( "H*",
42
            '47494638396101000100800000FFFFFF'
43
          . '00000021F90401000000002C00000000'
44
          . '010001000002024401003B' );
45
}
46
47
=head2 PutImage
48
49
    PutImage({ biblionumber => $biblionumber, itemnumber => $itemnumber, src_image => $srcimage, replace => $replace });
50
51
Stores binary image data and thumbnail in database, optionally replacing existing images for the given biblio or item.
52
53
=cut
54
55
sub PutImage {
56
    my ( $params ) = @_;
57
58
    my $biblionumber = $params->{biblionumber};
59
    my $itemnumber   = $params->{itemnumber};
60
    my $srcimage     = $params->{src_image};
61
    my $replace      = $params->{replace};
62
63
    Koha::Exceptions::WrongParameter->throw(
64
        'PutImage cannot be called with both biblionumber and itemnumber')
65
      if $biblionumber and $itemnumber;
66
67
    Koha::Exceptions::WrongParameter->throw(
68
        'PutImage must be called with "replace" if itemnumber is passed. Only 1 cover per item is allowed.')
69
      if $itemnumber and not $replace;
70
71
72
    return -1 unless defined($srcimage);
73
74
    if ($biblionumber && $replace) {
75
        foreach ( ListImagesForBiblio($biblionumber) ) {
76
            DelImage($_);
77
        }
78
    }
79
80
    my $dbh = C4::Context->dbh;
81
    my $query =
82
"INSERT INTO biblioimages (biblionumber, itemnumber, mimetype, imagefile, thumbnail) VALUES (?,?,?,?,?);";
83
    my $sth = $dbh->prepare($query);
84
85
    my $mimetype = 'image/png'
86
      ; # GD autodetects three basic image formats: PNG, JPEG, XPM; we will convert all to PNG which is lossless...
87
88
    # Check the pixel size of the image we are about to import...
89
    my $thumbnail = _scale_image( $srcimage, 140, 200 )
90
      ;    # MAX pixel dims are 140 X 200 for thumbnail...
91
    my $fullsize = _scale_image( $srcimage, 600, 800 )
92
      ;    # MAX pixel dims are 600 X 800 for full-size image...
93
    $debug and warn "thumbnail is " . length($thumbnail) . " bytes.";
94
95
    $sth->execute( $biblionumber, $itemnumber, $mimetype, $fullsize->png(),
96
        $thumbnail->png() );
97
    my $dberror = $sth->errstr;
98
    warn sprintf("Error returned inserting %s.%s.", ($biblionumber || $itemnumber, $mimetype)) if $sth->errstr;
99
    undef $thumbnail;
100
    undef $fullsize;
101
    return $dberror;
102
}
103
104
=head2 RetrieveImage
105
    my ($imagedata, $error) = RetrieveImage($imagenumber);
106
107
Retrieves the specified image.
108
109
=cut
110
111
sub RetrieveImage {
112
    my ($imagenumber) = @_;
113
114
    my $dbh = C4::Context->dbh;
115
    my $query =
116
'SELECT biblionumber, itemnumber, imagenumber, mimetype, imagefile, thumbnail FROM biblioimages WHERE imagenumber = ?';
117
    my $sth = $dbh->prepare($query);
118
    $sth->execute($imagenumber);
119
    my $imagedata = $sth->fetchrow_hashref;
120
    if ( !$imagedata ) {
121
        $imagedata->{'thumbnail'} = $noimage;
122
        $imagedata->{'imagefile'} = $noimage;
123
    }
124
    if ( $sth->err ) {
125
        warn "Database error!" if $debug;
126
    }
127
    return $imagedata;
128
}
129
130
=head2 ListImagesForBiblio
131
    my (@images) = ListImagesForBiblio($biblionumber);
132
133
Gets a list of all images associated with a particular biblio.
134
135
=cut
136
137
sub ListImagesForBiblio {
138
    my ($biblionumber) = @_;
139
140
    my @imagenumbers;
141
    my $dbh   = C4::Context->dbh;
142
    my $query = 'SELECT imagenumber FROM biblioimages WHERE biblionumber = ?';
143
    my $sth   = $dbh->prepare($query);
144
    $sth->execute($biblionumber);
145
    while ( my $row = $sth->fetchrow_hashref ) {
146
        push @imagenumbers, $row->{'imagenumber'};
147
    }
148
    return @imagenumbers;
149
}
150
151
=head2 GetImageForItem
152
    my $image  = GetImageForItem($itemnumber);
153
154
Gets the image associated with a particular item.
155
156
=cut
157
158
sub GetImageForItem {
159
    my ($itemnumber) = @_;
160
161
    my $dbh   = C4::Context->dbh;
162
    return $dbh->selectrow_array(
163
        'SELECT imagenumber FROM biblioimages WHERE itemnumber = ?',
164
        undef, $itemnumber );
165
}
166
167
=head2 DelImage
168
169
    my ($dberror) = DelImage($imagenumber);
170
171
Removes the image with the supplied imagenumber.
172
173
=cut
174
175
sub DelImage {
176
    my ($imagenumber) = @_;
177
    warn "Imagenumber passed to DelImage is $imagenumber" if $debug;
178
    my $dbh   = C4::Context->dbh;
179
    my $query = "DELETE FROM biblioimages WHERE imagenumber = ?;";
180
    my $sth   = $dbh->prepare($query);
181
    $sth->execute($imagenumber);
182
    my $dberror = $sth->errstr;
183
    warn "Database error!" if $sth->errstr;
184
    return $dberror;
185
}
186
187
sub _scale_image {
188
    my ( $image, $maxwidth, $maxheight ) = @_;
189
    my ( $width, $height ) = $image->getBounds();
190
    $debug and warn "image is $width pix X $height pix.";
191
    if ( $width > $maxwidth || $height > $maxheight ) {
192
193
#        $debug and warn "$filename exceeds the maximum pixel dimensions of $maxwidth X $maxheight. Resizing...";
194
        my $percent_reduce;  # Percent we will reduce the image dimensions by...
195
        if ( $width > $maxwidth ) {
196
            $percent_reduce =
197
              sprintf( "%.5f", ( $maxwidth / $width ) )
198
              ;    # If the width is oversize, scale based on width overage...
199
        }
200
        else {
201
            $percent_reduce =
202
              sprintf( "%.5f", ( $maxheight / $height ) )
203
              ;    # otherwise scale based on height overage.
204
        }
205
        my $width_reduce  = sprintf( "%.0f", ( $width * $percent_reduce ) );
206
        my $height_reduce = sprintf( "%.0f", ( $height * $percent_reduce ) );
207
        $debug
208
          and warn "Reducing image by "
209
          . ( $percent_reduce * 100 )
210
          . "\% or to $width_reduce pix X $height_reduce pix";
211
        my $newimage = GD::Image->new( $width_reduce, $height_reduce, 1 )
212
          ;        #'1' creates true color image...
213
        $newimage->copyResampled( $image, 0, 0, 0, 0, $width_reduce,
214
            $height_reduce, $width, $height );
215
        return $newimage;
216
    }
217
    else {
218
        return $image;
219
    }
220
}
221
222
=head2 NoImage
223
224
    C4::Images->NoImage;
225
226
Returns the gif to be used when there is no image matching the request, and
227
its mimetype (image/gif).
228
229
=cut
230
231
sub NoImage {
232
    return $noimage, 'image/gif';
233
}
234
235
1;
(-)a/Koha/Biblio.pm (+15 lines)
Lines 779-784 sub custom_cover_image_url { Link Here
779
    return $url;
779
    return $url;
780
}
780
}
781
781
782
=head3 cover_images
783
784
Return the cover images associated with this biblio.
785
786
=cut
787
788
sub cover_images {
789
    my ( $self ) = @_;
790
791
    my $cover_images_rs = $self->_result->cover_images;
792
    return unless $cover_images_rs;
793
    return Koha::CoverImages->_new_from_dbic($cover_images_rs);
794
}
795
796
782
=head3 to_api
797
=head3 to_api
783
798
784
    my $json = $biblio->to_api;
799
    my $json = $biblio->to_api;
(-)a/Koha/CoverImage.pm (+116 lines)
Line 0 Link Here
1
package Koha::CoverImage;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
use GD;
22
23
use Koha::Database;
24
25
use base qw(Koha::Object);
26
27
=head1 NAME
28
29
Koha::CoverImage - Koha CoverImage Object class
30
31
=head1 API
32
33
=head2 Class methods
34
35
=head3 new
36
37
my $cover_image = Koha::CoverImage->new(
38
    {
39
        biblionumber => $biblionumber,
40
        itemnumber   => $itemnumber,
41
        src_image    => $image,
42
        mimetype     => $mimetype,
43
    }
44
);
45
46
biblionumber and/or itemnumber must be passed, otherwise the image will not be
47
linked to anything.
48
49
src_image must contain the GD image, the fullsize and thumbnail images will be generated
50
and stored in the database.
51
52
=cut
53
54
sub new {
55
    my ( $class, $params ) = @_;
56
57
    my $src_image = delete $params->{src_image};
58
59
    if ( $src_image ) {
60
          ; # GD autodetects three basic image formats: PNG, JPEG, XPM; we will convert all to PNG which is lossless...
61
62
        # Check the pixel size of the image we are about to import...
63
        my $thumbnail = $class->_scale_image( $src_image, 140, 200 )
64
          ;    # MAX pixel dims are 140 X 200 for thumbnail...
65
        my $fullsize = $class->_scale_image( $src_image, 600, 800 )
66
          ;    # MAX pixel dims are 600 X 800 for full-size image...
67
68
        $params->{mimetype} = 'image/png';
69
        $params->{imagefile} = $fullsize->png();
70
        $params->{thumbnail} = $thumbnail->png();
71
    }
72
73
    return $class->SUPER::new($params);
74
}
75
76
sub _scale_image {
77
    my ( $self, $image, $maxwidth, $maxheight ) = @_;
78
    my ( $width, $height ) = $image->getBounds();
79
    if ( $width > $maxwidth || $height > $maxheight ) {
80
81
        my $percent_reduce;  # Percent we will reduce the image dimensions by...
82
        if ( $width > $maxwidth ) {
83
            $percent_reduce =
84
              sprintf( "%.5f", ( $maxwidth / $width ) )
85
              ;    # If the width is oversize, scale based on width overage...
86
        }
87
        else {
88
            $percent_reduce =
89
              sprintf( "%.5f", ( $maxheight / $height ) )
90
              ;    # otherwise scale based on height overage.
91
        }
92
        my $width_reduce  = sprintf( "%.0f", ( $width * $percent_reduce ) );
93
        my $height_reduce = sprintf( "%.0f", ( $height * $percent_reduce ) );
94
        my $newimage = GD::Image->new( $width_reduce, $height_reduce, 1 )
95
          ;        #'1' creates true color image...
96
        $newimage->copyResampled( $image, 0, 0, 0, 0, $width_reduce,
97
            $height_reduce, $width, $height );
98
        return $newimage;
99
    }
100
    else {
101
        return $image;
102
    }
103
}
104
105
106
=head2 Internal methods
107
108
=head3 _type
109
110
=cut
111
112
sub _type {
113
    return 'CoverImage';
114
}
115
116
1;
(-)a/Koha/CoverImages.pm (+71 lines)
Line 0 Link Here
1
package Koha::CoverImages;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::CoverImage;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Cities - Koha CoverImage Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 no_image
39
40
Returns the gif to be used when there is no image.
41
Its mimetype is image/gif.
42
43
=cut
44
45
sub no_image {
46
    my $no_image = pack( "H*",
47
            '47494638396101000100800000FFFFFF'
48
          . '00000021F90401000000002C00000000'
49
          . '010001000002024401003B' );
50
    return Koha::CoverImage->new(
51
        {
52
            mimetype  => 'image/gif',
53
            imagefile => $no_image,
54
            thumbnail => $no_image,
55
        }
56
    );
57
}
58
59
=head3 _type
60
61
=cut
62
63
sub _type {
64
    return 'CoverImage';
65
}
66
67
sub object_class {
68
    return 'Koha::CoverImage';
69
}
70
71
1;
(-)a/Koha/Item.pm (+16 lines)
Lines 36-41 use C4::Log qw( logaction ); Link Here
36
36
37
use Koha::Checkouts;
37
use Koha::Checkouts;
38
use Koha::CirculationRules;
38
use Koha::CirculationRules;
39
use Koha::CoverImages;
39
use Koha::Item::Transfer::Limits;
40
use Koha::Item::Transfer::Limits;
40
use Koha::Item::Transfers;
41
use Koha::Item::Transfers;
41
use Koha::ItemTypes;
42
use Koha::ItemTypes;
Lines 784-789 sub renewal_branchcode { Link Here
784
    return $branchcode;
785
    return $branchcode;
785
}
786
}
786
787
788
=head3 cover_image
789
790
Return the cover image associated with this item.
791
792
=cut
793
794
sub cover_image {
795
    my ( $self ) = @_;
796
797
    my $cover_image_rs = $self->_result->cover_images;
798
    return unless $cover_image_rs;
799
    # So far we allow only 1 cover image per item
800
    return Koha::CoverImages->_new_from_dbic($cover_image_rs)->next;
801
}
802
787
=head3 _set_found_trigger
803
=head3 _set_found_trigger
788
804
789
    $self->_set_found_trigger
805
    $self->_set_found_trigger
(-)a/catalogue/detail.pl (-5 / +5 lines)
Lines 36-48 use C4::External::Amazon; Link Here
36
use C4::Search;        # enabled_staff_search_views
36
use C4::Search;        # enabled_staff_search_views
37
use C4::Tags qw(get_tags);
37
use C4::Tags qw(get_tags);
38
use C4::XSLT;
38
use C4::XSLT;
39
use C4::Images;
40
use Koha::DateUtils;
39
use Koha::DateUtils;
41
use C4::HTML5Media;
40
use C4::HTML5Media;
42
use C4::CourseReserves qw(GetItemCourseReservesInfo);
41
use C4::CourseReserves qw(GetItemCourseReservesInfo);
43
use C4::Acquisition qw(GetOrdersByBiblionumber);
42
use C4::Acquisition qw(GetOrdersByBiblionumber);
44
use Koha::AuthorisedValues;
43
use Koha::AuthorisedValues;
45
use Koha::Biblios;
44
use Koha::Biblios;
45
use Koha::CoverImages;
46
use Koha::Illrequests;
46
use Koha::Illrequests;
47
use Koha::Items;
47
use Koha::Items;
48
use Koha::ItemTypes;
48
use Koha::ItemTypes;
Lines 408-415 foreach my $item (@items) { Link Here
408
    }
408
    }
409
409
410
    if ( C4::Context->preference("LocalCoverImages") == 1 ) {
410
    if ( C4::Context->preference("LocalCoverImages") == 1 ) {
411
        $item->{imagenumber} =
411
        my $cover_image = $item_object->cover_image;
412
          C4::Images::GetImageForItem( $item->{itemnumber} );
412
        $item->{imagenumber} = $cover_image ? $cover_image->imagenumber : undef;
413
    }
413
    }
414
414
415
    if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
415
    if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
Lines 531-538 if (C4::Context->preference("FRBRizeEditions")==1) { Link Here
531
}
531
}
532
532
533
if ( C4::Context->preference("LocalCoverImages") == 1 ) {
533
if ( C4::Context->preference("LocalCoverImages") == 1 ) {
534
    my @images = ListImagesForBiblio($biblionumber);
534
    my $images = $biblio->cover_images;
535
    $template->{VARS}->{localimages} = \@images;
535
    $template->param( localimages => $biblio->cover_images );
536
}
536
}
537
537
538
# HTML5 Media
538
# HTML5 Media
(-)a/catalogue/image.pl (-29 / +26 lines)
Lines 27-33 use Modern::Perl; Link Here
27
27
28
use CGI qw ( -utf8 );    #qw(:standard escapeHTML);
28
use CGI qw ( -utf8 );    #qw(:standard escapeHTML);
29
use C4::Context;
29
use C4::Context;
30
use C4::Images;
30
use Koha::CoverImages;
31
use Koha::Biblios;
32
use Koha::Exceptions;
31
33
32
$| = 1;
34
$| = 1;
33
35
Lines 57-99 imagenumber, a random image is selected. Link Here
57
59
58
=cut
60
=cut
59
61
60
my ( $image, $mimetype ) = C4::Images->NoImage;
62
my ( $image );
61
if ( C4::Context->preference("LocalCoverImages") ) {
63
if ( C4::Context->preference("LocalCoverImages") ) {
62
    if ( defined $data->param('imagenumber') ) {
64
    my $imagenumber = $data->param('imagenumber');
65
    my $biblionumber = $data->param('biblionumber');
66
    if ( defined $imagenumber ) {
63
        $imagenumber = $data->param('imagenumber');
67
        $imagenumber = $data->param('imagenumber');
68
        $image = Koha::CoverImages->find($imagenumber);
64
    }
69
    }
65
    elsif ( defined $data->param('biblionumber') ) {
70
    elsif ( defined $biblionumber ) {
66
        my @imagenumbers = ListImagesForBiblio( $data->multi_param('biblionumber') );
71
        my $biblio = Koha::Biblios->find($biblionumber);
67
        if (@imagenumbers) {
72
        Koha::Exceptions::ObjectNotFound->throw( 'No bibliographic record for biblionumber ' . $biblionumber ) unless $biblio;
68
            $imagenumber = $imagenumbers[0];
73
        my $cover_images = $biblio->cover_images;
69
        }
74
        if ( $cover_images->count ) {
70
        else {
75
            $image = $cover_images->next;
76
        } else {
71
            warn "No images for this biblio" if $DEBUG;
77
            warn "No images for this biblio" if $DEBUG;
72
        }
78
        }
73
    }
79
    }
74
    else {
75
        $imagenumber = shift;
76
    }
77
78
    if ($imagenumber) {
79
        warn "imagenumber passed in: $imagenumber" if $DEBUG;
80
        my $imagedata = RetrieveImage($imagenumber);
81
        if ($imagedata) {
82
            if ( $data->param('thumbnail') ) {
83
                $image = $imagedata->{'thumbnail'};
84
            }
85
            else {
86
                $image = $imagedata->{'imagefile'};
87
            }
88
            $mimetype = $imagedata->{'mimetype'};
89
        }
90
    }
91
}
80
}
81
82
$image ||= Koha::CoverImages->no_image;
83
84
my $image_data =
85
    $data->param('thumbnail')
86
  ? $image->thumbnail
87
  : $image->imagefile;
88
92
print $data->header(
89
print $data->header(
93
    -type            => $mimetype,
90
    -type            => $image->mimetype,
94
    -expires         => '+30m',
91
    -expires         => '+30m',
95
    -Content_Length  => length($image)
92
    -Content_Length  => length($image_data)
96
), $image;
93
), $image_data;
97
94
98
=head1 AUTHOR
95
=head1 AUTHOR
99
96
(-)a/catalogue/imageviewer.pl (-6 / +7 lines)
Lines 24-30 use C4::Auth; Link Here
24
use C4::Biblio;
24
use C4::Biblio;
25
use C4::Items;
25
use C4::Items;
26
use C4::Output;
26
use C4::Output;
27
use C4::Images;
28
use C4::Search;
27
use C4::Search;
29
28
30
use Koha::Biblios;
29
use Koha::Biblios;
Lines 68-86 if( $query->cookie("searchToOrder") ){ Link Here
68
67
69
if ( C4::Context->preference("LocalCoverImages") ) {
68
if ( C4::Context->preference("LocalCoverImages") ) {
70
    if ( $itemnumber ) {
69
    if ( $itemnumber ) {
71
        my $image = C4::Images::GetImageForItem($itemnumber);
70
        my $item = Koha::Items->find($itemnumber);
71
        my $image = $item->cover_image;
72
        $template->param(
72
        $template->param(
73
            LocalCoverImages => 1,
73
            LocalCoverImages => 1,
74
            images           => [$image],
74
            images           => [$image],
75
            imagenumber      => $imagenumber,
75
            imagenumber      => ($image ? $image->imagenumber : undef),
76
        );
76
        );
77
77
78
    } else {
78
    } else {
79
        my @images = ListImagesForBiblio($biblionumber);
79
        my $images = $biblio->cover_images->as_list;
80
80
        $template->param(
81
        $template->param(
81
            LocalCoverImages => 1,
82
            LocalCoverImages => 1,
82
            images           => \@images,
83
            images           => $images,
83
            imagenumber      => $imagenumber || $images[0] || '',
84
            imagenumber      => (@$images ? $images->[0]->imagenumber : undef),
84
        );
85
        );
85
    }
86
    }
86
}
87
}
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 3382-3388 CREATE TABLE `cover_images` ( -- local cover images Link Here
3382
 `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- image creation/update time
3382
 `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- image creation/update time
3383
 PRIMARY KEY (`imagenumber`),
3383
 PRIMARY KEY (`imagenumber`),
3384
 CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3384
 CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3385
 CONSTRAINT `bibliocoverimage_fk2` FOREIGN KEY (`itemnumber`) REFERENCES `item` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
3385
 CONSTRAINT `bibliocoverimage_fk2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
3386
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3386
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3387
3387
3388
--
3388
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (-15 / +13 lines)
Lines 169-184 Link Here
169
            <div class="col-xs-3" id="bookcoverimg">
169
            <div class="col-xs-3" id="bookcoverimg">
170
                <div id="cover-slides">
170
                <div id="cover-slides">
171
                    [% IF ( LocalCoverImages ) %]
171
                    [% IF ( LocalCoverImages ) %]
172
                        [% IF ( localimages.0 ) %]
172
                        [% IF localimages.count %]
173
                            [% FOREACH image IN localimages %]
173
                            [% FOREACH image IN localimages %]
174
                                [% IF image %]
174
                                <div class="cover-image local-coverimg">
175
                                    <div class="cover-image local-coverimg">
175
                                    <a href="/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=[% biblionumber | uri %]&amp;imagenumber=[% image.imagenumber | uri %]">
176
                                        <a href="/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=[% biblionumber | uri %]&amp;imagenumber=[% image | uri %]">
176
                                        <img src="/cgi-bin/koha/catalogue/image.pl?thumbnail=1&amp;imagenumber=[% image.imagenumber | uri %]" alt="Local cover image" />
177
                                            <img src="/cgi-bin/koha/catalogue/image.pl?thumbnail=1&amp;imagenumber=[% image | uri %]" alt="Local cover image" />
177
                                    </a>
178
                                        </a>
178
                                    <div class="hint">Local cover image</div>
179
                                        <div class="hint">Local cover image</div>
179
                                </div>
180
                                    </div>
181
                                [% END %]
182
                            [% END %]
180
                            [% END %]
183
                        [% END %]
181
                        [% END %]
184
                    [% END %]
182
                    [% END %]
Lines 248-256 Link Here
248
[% IF suggestions.count %]<li><a href="#suggestion_details">Suggestion details</a></li>[% END %]
246
[% IF suggestions.count %]<li><a href="#suggestion_details">Suggestion details</a></li>[% END %]
249
[% IF ( FRBRizeEditions ) %][% IF ( XISBNS ) %]<li><a href="#editions">Editions</a></li>[% END %][% END %]
247
[% IF ( FRBRizeEditions ) %][% IF ( XISBNS ) %]<li><a href="#editions">Editions</a></li>[% END %][% END %]
250
[% IF ( LocalCoverImages ) %]
248
[% IF ( LocalCoverImages ) %]
251
    [% IF ( localimages || CAN_user_tools_upload_local_cover_images ) %]
249
    [% IF ( localimages.count || CAN_user_tools_upload_local_cover_images ) %]
252
        <li>
250
        <li>
253
            <a href="#images">Images ([% localimages.size() || 0 | html %])</a>
251
            <a href="#images">Images ([% localimages.count || 0 | html %])</a>
254
        </li>
252
        </li>
255
    [% END %]
253
    [% END %]
256
[% END %]
254
[% END %]
Lines 871-884 Note that permanent location is a code, and location may be an authval. Link Here
871
869
872
[% IF ( LocalCoverImages ) %]
870
[% IF ( LocalCoverImages ) %]
873
    <div id="images">
871
    <div id="images">
874
        [% IF ( localimages.0 ) %]
872
        [% IF localimages.count %]
875
            <p>Click on an image to view it in the image viewer</p>
873
            <p>Click on an image to view it in the image viewer</p>
876
            <ul class="thumbnails">
874
            <ul class="thumbnails">
877
                [% FOREACH image IN localimages %]
875
                [% FOREACH image IN localimages %]
878
                    [% IF image %]
876
                    [% IF image %]
879
                        <li id="imagenumber-[% image | html %]" class="thumbnail">
877
                        <li id="imagenumber-[% image.imagenumber | html %]" class="thumbnail">
880
                            <a href="/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=[% biblionumber | uri %]&amp;imagenumber=[% image | uri %]">
878
                            <a href="/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=[% biblionumber | uri %]&amp;imagenumber=[% image.imagenumber | uri %]">
881
                                <img src="/cgi-bin/koha/catalogue/image.pl?thumbnail=1&amp;imagenumber=[% image | uri %]" />
879
                                <img src="/cgi-bin/koha/catalogue/image.pl?thumbnail=1&amp;imagenumber=[% image.imagenumber | uri %]" />
882
                            </a>
880
                            </a>
883
                            [% IF CAN_user_tools_upload_local_cover_images %]
881
                            [% IF CAN_user_tools_upload_local_cover_images %]
884
                                <a href="#" class="remove"><i class="fa fa-trash"></i> Delete image</a>
882
                                <a href="#" class="remove"><i class="fa fa-trash"></i> Delete image</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/imageviewer.tt (-15 / +13 lines)
Lines 40-46 Link Here
40
<h4>[% biblio.author | html %]</h4>
40
<h4>[% biblio.author | html %]</h4>
41
41
42
[% IF ( LocalCoverImages == 1 ) %]
42
[% IF ( LocalCoverImages == 1 ) %]
43
    [% IF ( images.size > 0 ) %]
43
    [% IF images.size %]
44
        <div class="row">
44
        <div class="row">
45
            <div class="col-md-8">
45
            <div class="col-md-8">
46
                <div id="largeCover">
46
                <div id="largeCover">
Lines 55-75 Link Here
55
55
56
            <div class="col-md-4">
56
            <div class="col-md-4">
57
                <ul class="thumbnails">
57
                <ul class="thumbnails">
58
                    [% FOREACH img IN images %]
58
                    [% FOREACH image IN images %]
59
                        [% IF img %]
59
                            <li id="imagenumber-[% image.imagenumber | html %]" class="thumbnail">
60
                            <li id="imagenumber-[% img | html %]" class="thumbnail">
60
                            <a class="show_cover" data-coverimg="[% image.imagenumber | html %]" href="/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=[% biblionumber | html %]&amp;imagenumber=[% image.imagenumber | html %]">
61
                                <a class="show_cover" data-coverimg="[% img | html %]" href="/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=[% biblionumber | html %]&amp;imagenumber=[% img | html %]">
61
                                [% IF loop.first %]
62
                                    [% IF ( imagenumber == img ) %]
62
                                    <img class="selected" id="thumbnail_[% image.imagenumber | html %]" src="/cgi-bin/koha/catalogue/image.pl?imagenumber=[% image.imagenumber | html %]&amp;thumbnail=1" alt="Thumbnail" />
63
                                        <img class="selected" id="thumbnail_[% img | html %]" src="/cgi-bin/koha/catalogue/image.pl?imagenumber=[% img | html %]&amp;thumbnail=1" alt="Thumbnail" />
63
                                [% ELSE %]
64
                                    [% ELSE %]
64
                                    <img id="thumbnail_[% image.imagenumber | html %]" src="/cgi-bin/koha/catalogue/image.pl?imagenumber=[% image.imagenumber | html %]&amp;thumbnail=1" alt="Thumbnail" />
65
                                        <img id="thumbnail_[% img | html %]" src="/cgi-bin/koha/catalogue/image.pl?imagenumber=[% img | html %]&amp;thumbnail=1" alt="Thumbnail" />
66
                                    [% END %]
67
                                </a>
68
                                [% IF CAN_user_tools_upload_local_cover_images %]
69
                                    <a href="#" class="remove" data-coverimg="[% img | html %]"><i class="fa fa-trash"></i> Delete image</a>
70
                                [% END %]
65
                                [% END %]
71
                            </li>
66
                            </a>
72
                        [% END # /IF img %]
67
                            [% IF CAN_user_tools_upload_local_cover_images %]
68
                                <a href="#" class="remove" data-coverimg="[% image.imagenumber | html %]"><i class="fa fa-trash"></i> Delete image</a>
69
                            [% END %]
70
                        </li>
73
                    [% END # /FOREACH img %]
71
                    [% END # /FOREACH img %]
74
                </ul> <!-- /ul.thumbnails -->
72
                </ul> <!-- /ul.thumbnails -->
75
            </div> <!-- /.col-md-4 -->
73
            </div> <!-- /.col-md-4 -->
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (-5 / +3 lines)
Lines 575-581 Link Here
575
                            </li>
575
                            </li>
576
                        [% END %]
576
                        [% END %]
577
577
578
                        [% IF ( OPACLocalCoverImages && localimages.size ) %]
578
                        [% IF ( OPACLocalCoverImages && localimages.count ) %]
579
                            <li id="tab_images"><a href="#images">Images</a></li>
579
                            <li id="tab_images"><a href="#images">Images</a></li>
580
                        [% END %]
580
                        [% END %]
581
581
Lines 1010-1022 Link Here
1010
                            </div>
1010
                            </div>
1011
                        [% END # / IF HTML5MediaEnabled %]
1011
                        [% END # / IF HTML5MediaEnabled %]
1012
1012
1013
                        [% IF ( OPACLocalCoverImages && localimages.size ) %]
1013
                        [% IF ( OPACLocalCoverImages && localimages.count ) %]
1014
                            <div id="images">
1014
                            <div id="images">
1015
                                <p>Click on an image to view it in the image viewer</p>
1015
                                <p>Click on an image to view it in the image viewer</p>
1016
                                [% FOREACH image IN localimages %]
1016
                                [% FOREACH image IN localimages %]
1017
                                    [% IF image %]
1017
                                    <a class="localimage" href="/cgi-bin/koha/opac-imageviewer.pl?biblionumber=[% biblio.biblionumber | html %]&amp;imagenumber=[% image.imagenumber | html %]"><img alt="" src="/cgi-bin/koha/opac-image.pl?thumbnail=1&amp;imagenumber=[% image.imagenumber | html %]" /></a>
1018
                                        <a class="localimage" href="/cgi-bin/koha/opac-imageviewer.pl?biblionumber=[% biblio.biblionumber | html %]&amp;imagenumber=[% image | html %]"><img alt="" src="/cgi-bin/koha/opac-image.pl?thumbnail=1&amp;imagenumber=[% image | html %]" /></a>
1019
                                    [% END %]
1020
                                [% END %]
1018
                                [% END %]
1021
                            </div><!-- / #images -->
1019
                            </div><!-- / #images -->
1022
                        [% END # / IF OPACLocalCoverImages && localimages.size %]
1020
                        [% END # / IF OPACLocalCoverImages && localimages.size %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-imageviewer.tt (-11 / +11 lines)
Lines 97-117 Link Here
97
                        </div> <!-- / .span12 -->
97
                        </div> <!-- / .span12 -->
98
98
99
                        [% IF OPACLocalCoverImages == 1 %]
99
                        [% IF OPACLocalCoverImages == 1 %]
100
                            <div class="col-lg-3">
100
                            [% IF images.count %]
101
                                <div id="thumbnails">
101
                                <div class="col-lg-3">
102
                                    [% FOREACH img IN images %]
102
                                    <div id="thumbnails">
103
                                        [% IF img %]
103
                                        [% FOREACH image IN images %]
104
                                            <a href="/cgi-bin/koha/opac-imageviewer.pl?biblionumber=[% biblionumber | url %]&amp;imagenumber=[% img | uri %]" onclick="showCover([% img | html %]); return false;">
104
                                            <a href="/cgi-bin/koha/opac-imageviewer.pl?biblionumber=[% biblionumber | url %]&amp;imagenumber=[% image.imagenumber| uri %]" onclick="showCover([% image.imagenumber| html %]); return false;">
105
                                            [% IF ( imagenumber == img ) %]
105
                                            [% IF loop.first %]
106
                                                <img class="thumbnail selected" id="[% img | html %]" src="/cgi-bin/koha/opac-image.pl?imagenumber=[% img | html %]&amp;thumbnail=1" alt="Thumbnail"/>
106
                                                <img class="thumbnail selected" id="[% image.imagenumber| html %]" src="/cgi-bin/koha/opac-image.pl?imagenumber=[% image.imagenumber | html %]&amp;thumbnail=1" alt="Thumbnail"/>
107
                                            [% ELSE %]
107
                                            [% ELSE %]
108
                                                <img class="thumbnail" id="[% img | html %]" src="/cgi-bin/koha/opac-image.pl?imagenumber=[% img | html %]&amp;thumbnail=1" alt="Thumbnail"/>
108
                                                <img class="thumbnail" id="[% image.imagenumber | html %]" src="/cgi-bin/koha/opac-image.pl?imagenumber=[% image.imagenumber | html %]&amp;thumbnail=1" alt="Thumbnail"/>
109
                                            [% END %]
109
                                            [% END %]
110
                                            </a>
110
                                            </a>
111
                                        [% END %]
111
                                        [% END %]
112
                                    [% END %]
112
                                    </div> <!-- /#thumbnails -->
113
                                </div> <!-- /#thumbnails -->
113
                                </div> <!-- /.col-lg-3 -->
114
                            </div> <!-- /.col-lg-3 -->
114
                            [% END %]
115
                        [% ELSE %]
115
                        [% ELSE %]
116
                            Unfortunately, images are not enabled for this catalog at this time.
116
                            Unfortunately, images are not enabled for this catalog at this time.
117
                        [% END %]
117
                        [% END %]
(-)a/opac/opac-detail.pl (-5 / +3 lines)
Lines 45-51 use C4::Letters; Link Here
45
use MARC::Record;
45
use MARC::Record;
46
use MARC::Field;
46
use MARC::Field;
47
use List::MoreUtils qw/any none/;
47
use List::MoreUtils qw/any none/;
48
use C4::Images;
49
use Koha::DateUtils;
48
use Koha::DateUtils;
50
use C4::HTML5Media;
49
use C4::HTML5Media;
51
use C4::CourseReserves qw(GetItemCourseReservesInfo);
50
use C4::CourseReserves qw(GetItemCourseReservesInfo);
Lines 764-771 if ( not $viewallitems and @items > $max_items_to_display ) { Link Here
764
    }
763
    }
765
764
766
    if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) {
765
    if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) {
767
        $itm->{imagenumber} =
766
        my $cover_image = $item->cover_image;
768
          C4::Images::GetImageForItem( $itm->{itemnumber} );
767
        $itm->{imagenumber} = $cover_image ? $cover_image->imagenumber : undef;
769
    }
768
    }
770
769
771
    my $itembranch = $itm->{$separatebranch};
770
    my $itembranch = $itm->{$separatebranch};
Lines 1248-1255 my $defaulttab = Link Here
1248
$template->param('defaulttab' => $defaulttab);
1247
$template->param('defaulttab' => $defaulttab);
1249
1248
1250
if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1249
if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1251
    my @images = ListImagesForBiblio($biblionumber);
1250
    $template->param( localimages => $biblio->cover_images );
1252
    $template->{VARS}->{localimages} = \@images;
1253
}
1251
}
1254
1252
1255
$template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1253
$template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
(-)a/opac/opac-image.pl (-29 / +25 lines)
Lines 27-33 use Modern::Perl; Link Here
27
27
28
use CGI qw ( -utf8 );
28
use CGI qw ( -utf8 );
29
use C4::Context;
29
use C4::Context;
30
use C4::Images;
30
use Koha::Biblios;
31
use Koha::CoverImages;
31
32
32
$| = 1;
33
$| = 1;
33
34
Lines 57-99 imagenumber, a random image is selected. Link Here
57
58
58
=cut
59
=cut
59
60
60
my ( $image, $mimetype ) = C4::Images->NoImage;
61
my ( $image );
61
if ( C4::Context->preference("OPACLocalCoverImages") ) {
62
if ( C4::Context->preference("OPACLocalCoverImages") ) {
62
    if ( defined $data->param('imagenumber') ) {
63
    my $imagenumber = $data->param('imagenumber');
64
    my $biblionumber = $data->param('biblionumber');
65
    if ( defined $imagenumber ) {
63
        $imagenumber = $data->param('imagenumber');
66
        $imagenumber = $data->param('imagenumber');
67
        $image = Koha::CoverImages->find($imagenumber);
64
    }
68
    }
65
    elsif ( defined $data->param('biblionumber') ) {
69
    elsif ( defined $biblionumber ) {
66
        my @imagenumbers = ListImagesForBiblio( scalar $data->param('biblionumber') );
70
        my $biblio = Koha::Biblios->find($biblionumber);
67
        if (@imagenumbers) {
71
        Koha::Exceptions::ObjectNotFound->throw( 'No bibliographic record for biblionumber ' . $biblionumber ) unless $biblio;
68
            $imagenumber = $imagenumbers[0];
72
        my $cover_images = $biblio->cover_images;
69
        }
73
        if ( $cover_images->count ) {
70
        else {
74
            $image = $cover_images->next;
75
        } else {
71
            warn "No images for this biblio" if $DEBUG;
76
            warn "No images for this biblio" if $DEBUG;
72
        }
77
        }
73
    }
78
    }
74
    else {
75
        $imagenumber = shift;
76
    }
77
78
    if ($imagenumber) {
79
        warn "imagenumber passed in: $imagenumber" if $DEBUG;
80
        my $imagedata = RetrieveImage($imagenumber);
81
        if ($imagedata) {
82
            if ( $data->param('thumbnail') ) {
83
                $image = $imagedata->{'thumbnail'};
84
            }
85
            else {
86
                $image = $imagedata->{'imagefile'};
87
            }
88
            $mimetype = $imagedata->{'mimetype'};
89
        }
90
    }
91
}
79
}
80
81
$image ||= Koha::CoverImages->no_image;
82
83
my $image_data =
84
    $data->param('thumbnail')
85
  ? $image->thumbnail
86
  : $image->imagefile;
87
92
print $data->header(
88
print $data->header(
93
    -type            => $mimetype,
89
    -type            => $image->mimetype,
94
    -expires         => '+30m',
90
    -expires         => '+30m',
95
    -Content_Length  => length($image)
91
    -Content_Length  => length($image_data)
96
), $image;
92
), $image_data;
97
93
98
=head1 AUTHOR
94
=head1 AUTHOR
99
95
(-)a/opac/opac-imageviewer.pl (-5 / +5 lines)
Lines 23-31 use CGI qw ( -utf8 ); Link Here
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Biblio;
24
use C4::Biblio;
25
use C4::Output;
25
use C4::Output;
26
use C4::Images;
27
26
28
use Koha::Biblios;
27
use Koha::Biblios;
28
use Koha::CoverImages;
29
use Koha::Items;
29
use Koha::Items;
30
30
31
my $query = new CGI;
31
my $query = new CGI;
Lines 42-60 my $biblionumber = $query->param('biblionumber') || $query->param('bib'); Link Here
42
my $imagenumber = $query->param('imagenumber');
42
my $imagenumber = $query->param('imagenumber');
43
unless ( $biblionumber ) {
43
unless ( $biblionumber ) {
44
    # Retrieving the biblio from the imagenumber
44
    # Retrieving the biblio from the imagenumber
45
    my $image = C4::Images::RetrieveImage($imagenumber);
45
    my $image = Koha::CoverImages->find($imagenumber);
46
    my $item  = Koha::Items->find($image->{itemnumber});
46
    my $item  = Koha::Items->find($image->{itemnumber});
47
    $biblionumber = $item->biblionumber;
47
    $biblionumber = $item->biblionumber;
48
}
48
}
49
my $biblio = Koha::Biblios->find( $biblionumber );
49
my $biblio = Koha::Biblios->find( $biblionumber );
50
50
51
if ( C4::Context->preference("OPACLocalCoverImages") ) {
51
if ( C4::Context->preference("OPACLocalCoverImages") ) {
52
    my @images = !$imagenumber ? ListImagesForBiblio($biblionumber) : ();
52
    my $images = !$imagenumber ? Koha::Biblios->find($biblionumber)->cover_images->as_list : [];
53
    $template->param(
53
    $template->param(
54
        OPACLocalCoverImages => 1,
54
        OPACLocalCoverImages => 1,
55
        images               => \@images,
55
        images               => $images,
56
        biblionumber         => $biblionumber,
56
        biblionumber         => $biblionumber,
57
        imagenumber          => $imagenumber || $images[0] || '',
57
        imagenumber          => (@$images ? $images->[0]->imagenumber : $imagenumber),
58
    );
58
    );
59
}
59
}
60
60
(-)a/svc/cover_images (-2 / +2 lines)
Lines 22-28 use Modern::Perl; Link Here
22
22
23
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
24
use C4::Auth qw/check_cookie_auth/;
24
use C4::Auth qw/check_cookie_auth/;
25
use C4::Images;
25
use Koha::CoverImages;
26
use JSON qw/to_json/;
26
use JSON qw/to_json/;
27
27
28
my $input = new CGI;
28
my $input = new CGI;
Lines 46-52 if ( $action eq "delete" ) { Link Here
46
46
47
    foreach my $imagenumber ( @imagenumbers ) {
47
    foreach my $imagenumber ( @imagenumbers ) {
48
        eval {
48
        eval {
49
            DelImage($imagenumber);
49
            Koha::CoverImages->find($imagenumber)->delete;
50
        };
50
        };
51
        if ( $@ ) {
51
        if ( $@ ) {
52
            push @$response, {
52
            push @$response, {
(-)a/t/Images.t (-71 lines)
Lines 1-71 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More;
21
use Test::MockModule;
22
23
use Module::Load::Conditional qw/check_install/;
24
25
BEGIN {
26
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
27
        plan tests => 8;
28
    } else {
29
        plan skip_all => "Need Test::DBIx::Class"
30
    }
31
}
32
33
use_ok('C4::Images');
34
35
use Test::DBIx::Class;
36
37
# Make the code in the module use our mocked Koha::Schema/Koha::Database
38
my $db = Test::MockModule->new('Koha::Database');
39
$db->mock(
40
    # Schema() gives us the DB connection set up by Test::DBIx::Class
41
    _new_schema => sub { return Schema(); }
42
);
43
44
my $biblionumber = 2;
45
my $images = [
46
    [ 1, $biblionumber, 'gif',  'imagefile1', 'thumbnail1' ],
47
    [ 3, $biblionumber, 'jpeg', 'imagefile3', 'thumbnail3' ],
48
];
49
fixtures_ok [
50
    Biblioimage => [
51
        [ 'imagenumber', 'biblionumber', 'mimetype', 'imagefile', 'thumbnail' ],
52
        @$images,
53
    ],
54
], 'add fixtures';
55
56
my $image = C4::Images::RetrieveImage(1);
57
58
is( $image->{'imagenumber'}, 1, 'First imagenumber is 1' );
59
60
is( $image->{'mimetype'}, 'gif', 'First mimetype is gif' );
61
62
is( $image->{'thumbnail'}, 'thumbnail1', 'First thumbnail is correct' );
63
64
my @imagenumbers = C4::Images::ListImagesForBiblio($biblionumber);
65
66
is( $imagenumbers[0], 1, 'imagenumber is 1' );
67
68
is( $imagenumbers[1], 3, 'imagenumber is 3' );
69
70
is( $imagenumbers[4], undef, 'imagenumber undef' );
71
(-)a/t/db_dependent/Koha/CoverImages.t (-11 / +8 lines)
Lines 81-96 is( ref( $item->cover_image ), Link Here
81
    'Koha::CoverImage',
81
    'Koha::CoverImage',
82
    'Koha::Item->cover_image returns a Koha::CoverImage object' );
82
    'Koha::Item->cover_image returns a Koha::CoverImage object' );
83
83
84
throws_ok {
84
Koha::CoverImage->new(
85
    Koha::CoverImage->new(
85
    {
86
        {
86
        biblionumber => $biblio->biblionumber,
87
            biblionumber => $biblio->biblionumber,
87
        itemnumber   => $item->itemnumber,
88
            itemnumber   => $item->itemnumber,
88
        src_image    => GD::Image->new($logo_filepath)
89
            src_image    => GD::Image->new($logo_filepath)
89
    }
90
        }
90
)->store;
91
      )->store
91
is( $biblio->cover_images->count, 3, );
92
}
93
'Koha::Exceptions::WrongParameter',
94
  'Exception is thrown if both biblionumber and itemnumber are passed';
95
92
96
$schema->storage->txn_rollback;
93
$schema->storage->txn_rollback;
(-)a/tools/upload-cover-image.pl (-11 / +37 lines)
Lines 45-51 use GD; Link Here
45
use C4::Context;
45
use C4::Context;
46
use C4::Auth;
46
use C4::Auth;
47
use C4::Output;
47
use C4::Output;
48
use C4::Images;
48
use Koha::Biblios;
49
use Koha::CoverImages;
49
use Koha::Items;
50
use Koha::Items;
50
use Koha::UploadedFiles;
51
use Koha::UploadedFiles;
51
use C4::Log;
52
use C4::Log;
Lines 92-99 if ($fileID) { Link Here
92
        my $srcimage = GD::Image->new($fh);
93
        my $srcimage = GD::Image->new($fh);
93
        $fh->close if $fh;
94
        $fh->close if $fh;
94
        if ( defined $srcimage ) {
95
        if ( defined $srcimage ) {
95
            my $dberror = PutImage( { biblionumber => $biblionumber, itemnumber => $itemnumber, src_image => $srcimage, replace => $replace } );
96
            eval {
96
            if ($dberror) {
97
                if ( $replace && $biblionumber ) {
98
                    Koha::Biblios->find($biblionumber)->cover_images->delete;
99
                } elsif ( $itemnumber ) {
100
                    my $cover_image = Koha::Items->find($itemnumber)->cover_image;
101
                    $cover_image->delete if $cover_image;
102
                }
103
104
                Koha::CoverImage->new(
105
                    {
106
                        biblionumber => $biblionumber,
107
                        itemnumber   => $itemnumber,
108
                        src_image    => $srcimage
109
                    }
110
                )->store;
111
            };
112
113
            if ($@) {
114
                warn $@;
97
                $error = 'DBERR';
115
                $error = 'DBERR';
98
            }
116
            }
99
            else {
117
            else {
Lines 162-175 if ($fileID) { Link Here
162
                            my $srcimage = GD::Image->new("$dir/$filename");
180
                            my $srcimage = GD::Image->new("$dir/$filename");
163
                            if ( defined $srcimage ) {
181
                            if ( defined $srcimage ) {
164
                                $total++;
182
                                $total++;
165
                                my $dberror = PutImage(
183
                                eval {
166
                                    {
184
                                    if ( $replace && $biblionumber ) {
167
                                        biblionumber => $biblionumber,
185
                                        Koha::Biblios->find($biblionumber)->cover_images->delete;
168
                                        src_image    => $srcimage,
186
                                    } elsif ( $itemnumber ) {
169
                                        replace      => $replace
187
                                        Koha::Items->find($itemnumber)->cover_image->delete;
170
                                    }
188
                                    }
171
                                );
189
172
                                if ($dberror) {
190
                                    Koha::CoverImage->new(
191
                                        {
192
                                            biblionumber => $biblionumber,
193
                                            itemnumber   => $itemnumber,
194
                                            src_image    => $srcimage
195
                                        }
196
                                    )->store;
197
                                };
198
199
                                if ($@) {
173
                                    $error = 'DBERR';
200
                                    $error = 'DBERR';
174
                                }
201
                                }
175
                            }
202
                            }
176
- 

Return to bug 26145