@@ -, +, @@ uploaded files. --- C4/Images.pm | 83 ++++++++++++++++++---- .../atomicupdate/bug_17650_save_cover_to_hd.sql | 16 +++++ .../admin/preferences/enhanced_content.pref | 6 ++ .../prog/en/modules/tools/file-search.tt | 29 ++++++++ .../prog/en/modules/tools/upload-images.tt | 56 ++++++++++++++- tools/file-search.pl | 67 +++++++++++++++++ tools/upload-cover-image.pl | 5 +- tools/upload-file.pl | 2 + 8 files changed, 247 insertions(+), 17 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_17650_save_cover_to_hd.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/file-search.tt create mode 100755 tools/file-search.pl --- a/C4/Images.pm +++ a/C4/Images.pm @@ -24,6 +24,9 @@ use 5.010; use C4::Context; use GD; +use Koha::Upload; + +use File::Path qw(make_path); use vars qw($debug $noimage @ISA @EXPORT); @@ -54,7 +57,7 @@ Stores binary image data and thumbnail in database, optionally replacing existin =cut sub PutImage { - my ( $biblionumber, $srcimage, $replace ) = @_; + my ( $biblionumber, $srcimage, $replace, $uploadedfileid ) = @_; return -1 unless defined($srcimage); @@ -66,25 +69,29 @@ sub PutImage { my $dbh = C4::Context->dbh; my $query = -"INSERT INTO biblioimages (biblionumber, mimetype, imagefile, thumbnail) VALUES (?,?,?,?);"; +"INSERT INTO biblioimages (biblionumber, mimetype, imagefile, thumbnail, uploadedfileid) VALUES (?,?,?,?,?);"; my $sth = $dbh->prepare($query); my $mimetype = 'image/png' ; # GD autodetects three basic image formats: PNG, JPEG, XPM; we will convert all to PNG which is lossless... + if( defined $uploadedfileid){ + $sth->execute( $biblionumber, $mimetype, undef, undef, $uploadedfileid ); + }else{ + # Check the pixel size of the image we are about to import... + my $thumbnail = _scale_image( $srcimage, 140, 200 ) + ; # MAX pixel dims are 140 X 200 for thumbnail... + my $fullsize = _scale_image( $srcimage, 600, 800 ) + ; # MAX pixel dims are 600 X 800 for full-size image... + $debug and warn "thumbnail is " . length($thumbnail) . " bytes."; + + $sth->execute( $biblionumber, $mimetype, $fullsize->png(), + $thumbnail->png(), $uploadedfileid ); + undef $thumbnail; + undef $fullsize; + } - # Check the pixel size of the image we are about to import... - my $thumbnail = _scale_image( $srcimage, 140, 200 ) - ; # MAX pixel dims are 140 X 200 for thumbnail... - my $fullsize = _scale_image( $srcimage, 600, 800 ) - ; # MAX pixel dims are 600 X 800 for full-size image... - $debug and warn "thumbnail is " . length($thumbnail) . " bytes."; - - $sth->execute( $biblionumber, $mimetype, $fullsize->png(), - $thumbnail->png() ); my $dberror = $sth->errstr; warn "Error returned inserting $biblionumber.$mimetype." if $sth->errstr; - undef $thumbnail; - undef $fullsize; return $dberror; } @@ -100,20 +107,68 @@ sub RetrieveImage { my $dbh = C4::Context->dbh; my $query = -'SELECT imagenumber, mimetype, imagefile, thumbnail FROM biblioimages WHERE imagenumber = ?'; +'SELECT imagenumber, mimetype, imagefile, thumbnail, uploadedfileid FROM biblioimages WHERE imagenumber = ?'; my $sth = $dbh->prepare($query); $sth->execute($imagenumber); my $imagedata = $sth->fetchrow_hashref; if ( !$imagedata ) { $imagedata->{'thumbnail'} = $noimage; $imagedata->{'imagefile'} = $noimage; + }else{ + if (defined $imagedata->{'uploadedfileid'}){ + my ($thumbnail, $imagefile) = _retrieve_thumbs_images($imagedata->{'uploadedfileid'}); + $imagedata->{'thumbnail'} = $thumbnail; # MAX pixel dims are 140 X 200 for thumbnail... + $imagedata->{'imagefile'} = $imagefile; + + } } + if ( $sth->err ) { warn "Database error!" if $debug; } return $imagedata; } +sub _retrieve_thumbs_images { + my ($uploadedfileid) = @_; + my $thumbnail_name = '140_200.png'; + my $imagefile_name = '600_800.png'; + my $temp_directory = "/tmp/koha_thumbs_$uploadedfileid"; + my $files_exists = 0; + #Check if the uploaded file id exists on the temp directory. + #Check if a temp dir exists. + if ( -d $temp_directory){ + if ( -e "$temp_directory/$thumbnail_name" && -e "$temp_directory/$imagefile_name"){ + $files_exists = 1; + } + }else{ + make_path("/tmp/koha_thumbs_$uploadedfileid"); + } + my $thumbnail; + my $imagefile; + if($files_exists){ + $thumbnail = GD::Image->new("$temp_directory/$thumbnail_name")->png(); + $imagefile = GD::Image->new("$temp_directory/$imagefile_name")->png(); + }else{ + # There is none temp files, create them. + my $upload = Koha::Upload->new->get({ id => $uploadedfileid, filehandle => 1 }); + my $srcimage = GD::Image->new($upload->{fh}); + $thumbnail = _scale_image( $srcimage, 140, 200 )->png(); + $imagefile = _scale_image( $srcimage, 600, 800 )->png(); + warn "$temp_directory/$thumbnail_name"; + open( IMAGE, ">$temp_directory/$thumbnail_name"); + binmode( IMAGE ); + print IMAGE $thumbnail; + close IMAGE; + warn "$temp_directory/$imagefile_name"; + open( IMAGE2, ">$temp_directory/$imagefile_name"); + binmode( IMAGE2 ); + print IMAGE2 $imagefile; + close IMAGE2; + } + return ($thumbnail, $imagefile); +} + =head2 ListImagesForBiblio my (@images) = ListImagesForBiblio($biblionumber); --- a/installer/data/mysql/atomicupdate/bug_17650_save_cover_to_hd.sql +++ a/installer/data/mysql/atomicupdate/bug_17650_save_cover_to_hd.sql @@ -0,0 +1,16 @@ +ALTER TABLE `biblioimages` +DROP FOREIGN KEY `bibliocoverimage_fk1`; +ALTER TABLE `biblioimages` +CHANGE COLUMN `imagefile` `imagefile` MEDIUMBLOB NULL DEFAULT NULL , +CHANGE COLUMN `thumbnail` `thumbnail` MEDIUMBLOB NULL DEFAULT NULL , +ADD COLUMN `uploadedfileid` INT(11) NULL DEFAULT NULL AFTER `thumbnail`, +ADD INDEX `bibliocoverimage_fk2_idx` (`uploadedfileid` ASC); +ALTER TABLE `biblioimages` +ADD CONSTRAINT `bibliocoverimage_fk2` + FOREIGN KEY (`uploadedfileid`) + REFERENCES `uploaded_files` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; + + +INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('SaveCoverOnDisk','0','','Save the covers on the the hard disk instead of the database.','YesNo'); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref @@ -316,6 +316,12 @@ Enhanced Content: yes: Allow no: "Don't allow" - multiple images to be attached to each bibliographic record. + - + - pref: SaveCoverOnDisk + choices: + yes: "Yes" + no: "No" + - Save the covers on the the hard disk instead of the database. HTML5 Media: - - Show a tab with a HTML5 media player for files catalogued in field 856 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/file-search.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/file-search.tt @@ -0,0 +1,29 @@ +[% USE Koha %] +
Filename | +Size | +Hashvalue | +Category | +Public | +Temporary | +Actions | +
---|---|---|---|---|---|---|
[% record.name %] | +[% record.filesize %] | +[% record.hashvalue %] | +[% record.uploadcategorycode %] | +[% IF record.public %]Yes[% ELSE %]No[% END %] | +[% IF record.permanent %]No[% ELSE %]Yes[% END %] | ++ + | +