Bugzilla – Attachment 89954 Details for
Bug 20208
Custom file upload paths
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20208: Custom file upload paths
Bug-20208-Custom-file-upload-paths.patch (text/plain), 26.30 KB, created by
Devinim
on 2019-05-22 09:44:40 UTC
(
hide
)
Description:
Bug 20208: Custom file upload paths
Filename:
MIME Type:
Creator:
Devinim
Created:
2019-05-22 09:44:40 UTC
Size:
26.30 KB
patch
obsolete
>From 0556192e295a66020cb7644c7172b8157d0efc29 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Nazl=C4=B1=20=C3=87etin?= <nazli@devinim.com.tr> >Date: Wed, 22 May 2019 08:20:36 +0000 >Subject: [PATCH] Bug 20208: Custom file upload paths > >--- > Koha/Schema/Result/UploadedFile.pm | 16 ++- > Koha/UploadedFile.pm | 5 +- > Koha/UploadedFiles.pm | 14 +++ > Koha/Uploader.pm | 13 +- > installer/data/mysql/atomicupdate/bug_20208.perl | 14 +++ > .../intranet-tmpl/prog/en/modules/tools/upload.tt | 133 ++++++++++++++++++++- > svc/uploadpath | 108 +++++++++++++++++ > t/db_dependent/Upload.t | 119 +++++++++++++++++- > tools/upload-file.pl | 4 +- > tools/upload.pl | 12 +- > 10 files changed, 421 insertions(+), 17 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_20208.perl > create mode 100755 svc/uploadpath > >diff --git a/Koha/Schema/Result/UploadedFile.pm b/Koha/Schema/Result/UploadedFile.pm >index 5a4397db69..e7852e4f82 100644 >--- a/Koha/Schema/Result/UploadedFile.pm >+++ b/Koha/Schema/Result/UploadedFile.pm >@@ -35,6 +35,12 @@ __PACKAGE__->table("uploaded_files"); > is_nullable: 0 > size: 40 > >+=head2 checksum >+ >+ data_type: 'tinyint' >+ default_value: 1 >+ is_nullable: 1 >+ > =head2 filename > > data_type: 'mediumtext' >@@ -43,7 +49,7 @@ __PACKAGE__->table("uploaded_files"); > =head2 dir > > data_type: 'mediumtext' >- is_nullable: 0 >+ is_nullable: 1 > > =head2 filesize > >@@ -84,10 +90,12 @@ __PACKAGE__->add_columns( > { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, > "hashvalue", > { data_type => "char", is_nullable => 0, size => 40 }, >+ "checksum", >+ { data_type => "tinyint", default_value => 1, is_nullable => 1 }, > "filename", > { data_type => "mediumtext", is_nullable => 0 }, > "dir", >- { data_type => "mediumtext", is_nullable => 0 }, >+ { data_type => "mediumtext", is_nullable => 1 }, > "filesize", > { data_type => "integer", is_nullable => 1 }, > "dtcreated", >@@ -120,8 +128,8 @@ __PACKAGE__->add_columns( > __PACKAGE__->set_primary_key("id"); > > >-# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:54 >-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kJUbIULQMBo3t51HvWC8cg >+# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-05-22 07:44:42 >+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:M1e7DojIWOcQgijZey9/UQ > > > # You can replace this text with custom code or comments, and it will be preserved on regeneration >diff --git a/Koha/UploadedFile.pm b/Koha/UploadedFile.pm >index 20fc608c68..ba4e87a131 100644 >--- a/Koha/UploadedFile.pm >+++ b/Koha/UploadedFile.pm >@@ -101,12 +101,13 @@ Returns the fully qualified path name for an uploaded file. > > sub full_path { > my ( $self ) = @_; >+ my $filename = $self->checksum ? $self->hashvalue ."_". $self->filename : $self->filename; > my $path = File::Spec->catfile( > $self->permanent > ? $self->permanent_directory > : C4::Context->temporary_directory, >- $self->dir, >- $self->hashvalue. '_'. $self->filename, >+ $self->dir ."/". $self->uploadcategorycode, >+ $filename, > ); > return $path; > } >diff --git a/Koha/UploadedFiles.pm b/Koha/UploadedFiles.pm >index b6804f299b..0b0f4767de 100644 >--- a/Koha/UploadedFiles.pm >+++ b/Koha/UploadedFiles.pm >@@ -159,6 +159,8 @@ sub search_term { > } > return $self->search( > [ { filename => { like => '%'.$term.'%' }, %public }, >+ { dir => { like => '%'.$term.'%' }, %public }, >+ { uploadcategorycode => { like => '%'.$term.'%' }, %public }, > { hashvalue => { like => '%'.$params->{term}.'%' }, %public } ], > { order_by => { -asc => 'id' }}, > ); >@@ -178,6 +180,18 @@ sub getCategories { > [ map {{ code => $_->{authorised_value}, name => $_->{lib} }} @$cats ]; > } > >+=head3 getPaths >+ >+getPaths returns a list of upload path codes and names >+ >+=cut >+ >+sub getPaths { >+ my ( $class ) = @_; >+ my $paths = C4::Koha::GetAuthorisedValues('UPLOAD_PATH'); >+ [ map {{ code => $_->{authorised_value}, name => $_->{lib} }} @$paths ]; >+} >+ > =head3 _type > > Returns name of corresponding DBIC resultset >diff --git a/Koha/Uploader.pm b/Koha/Uploader.pm >index a4baa6a30b..c72729a334 100644 >--- a/Koha/Uploader.pm >+++ b/Koha/Uploader.pm >@@ -69,6 +69,7 @@ use Modern::Perl; > use CGI; # no utf8 flag, since it may interfere with binary uploads > use Digest::MD5; > use Encode; >+use File::Path; > use File::Spec; > use IO::File; > use Time::HiRes; >@@ -197,6 +198,9 @@ sub _init { > > $params->{tmp} = $params->{temp} if !exists $params->{tmp}; > $self->{temporary} = $params->{tmp}? 1: 0; #default false >+ $params->{checksum} = 1 if !exists $params->{checksum}; >+ $self->{checksum} = $params->{checksum}; >+ $self->{dir} = $params->{dir} || ""; > if( $params->{tmp} ) { > my $db = C4::Context->config('database'); > $self->{category} = KOHA_UPLOAD; >@@ -230,7 +234,7 @@ sub _create_file { > } else { > my $dir = $self->_dir; > my $hashval = $self->{files}->{$filename}->{hash}; >- my $fn = $hashval. '_'. $filename; >+ my $fn = $self->{checksum} ? $hashval. '_'. $filename: $filename; > > # if the file exists and it is registered, then set error > # if it exists, but is not in the database, we will overwrite >@@ -238,6 +242,7 @@ sub _create_file { > Koha::UploadedFiles->search({ > hashvalue => $hashval, > uploadcategorycode => $self->{category}, >+ dir => $self->{dir}, > })->count ) { > $self->{files}->{$filename}->{errcode} = ERR_EXISTS; > return; >@@ -257,8 +262,9 @@ sub _create_file { > sub _dir { > my ( $self ) = @_; > my $dir = $self->{temporary}? $self->{tmpdir}: $self->{rootdir}; >+ $dir.= '/'. $self->{dir} if( $self->{dir} ); > $dir.= '/'. $self->{category}; >- mkdir $dir if !-d $dir; >+ mkpath $dir if !-d $dir; > return $dir; > } > >@@ -285,8 +291,9 @@ sub _register { > my ( $self, $filename, $size ) = @_; > my $rec = Koha::UploadedFile->new({ > hashvalue => $self->{files}->{$filename}->{hash}, >+ checksum => $self->{checksum}, > filename => $filename, >- dir => $self->{category}, >+ dir => $self->{dir}, > filesize => $size, > owner => $self->{uid}, > uploadcategorycode => $self->{category}, >diff --git a/installer/data/mysql/atomicupdate/bug_20208.perl b/installer/data/mysql/atomicupdate/bug_20208.perl >new file mode 100644 >index 0000000000..42237913c8 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_20208.perl >@@ -0,0 +1,14 @@ >+$DBversion = 'XXX'; # will be replaced by the RM >+if( CheckVersion( $DBversion ) ) { >+ unless ( column_exists('uploaded_files', 'checksum') ) { >+ $dbh->do( q{ ALTER TABLE uploaded_files ADD checksum tinyint(1) DEFAULT 1 AFTER hashvalue }); >+ $dbh->do( q{ UPDATE uploaded_files SET checksum=1, dir=NULL }); >+ $dbh->do( q{ ALTER TABLE `uploaded_files` MODIFY COLUMN `dir` mediumtext DEFAULT NULL }); >+ } >+ >+ $dbh->do( q{ INSERT IGNORE INTO authorised_value_categories( category_name ) VALUES ('UPLOAD_PATH') }); >+ >+ # Always end with this (adjust the bug info) >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 20208 - Custom file upload paths)\n"; >+} >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt >index 6bd010ad6f..839dd5053e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt >@@ -3,6 +3,7 @@ > [% USE Koha %] > [% SET footerjs = 1 %] > [% INCLUDE 'doc-head-open.inc' %] >+[% Asset.css("lib/jquery/plugins/treetable/stylesheets/jquery.treetable.css") | $raw %] > [% IF plugin %] > <title>Upload plugin</title> > [% ELSE %] >@@ -47,6 +48,26 @@ > <input type="file" id="fileToUpload" name="fileToUpload" multiple/> > </div> > </li> >+ <li> >+ <label for="fileChecksum">Add file checksum to the uploaded filename: </label> >+ <label class="radio"> >+ Yes <input type="radio" name="checksum" id="checksum" value="1" checked /> >+ No <input type="radio" name="checksum" id="checksum" value="0" /> >+ </label> >+ </li> >+ [% IF uploadpaths %] >+ <li> >+ <label for="uploadpath">Upload Path: </label> >+ <select id="uploadpath" name="uploadpath"> >+ [% IF !plugin %] >+ <option value=""></option> >+ [% END %] >+ [% FOREACH dir IN uploadpaths %] >+ <option value="[% dir.code | html %]">[% dir.name | html %]</option> >+ [% END %] >+ </select> >+ </li> >+ [% END %] > [% IF uploadcategories %] > <li> > <label for="uploadcategory">Category: </label> >@@ -149,13 +170,44 @@ > [% END %] > [% END %] > >+[% BLOCK upload_paths %] >+ <fieldset class="rows"> >+ <legend>Search uploads by file tree</legend> >+ <ol> >+ <li> >+ <table id="uploadpathtable"> >+ <caption> >+ <span class="actions"><a href="#" id="expand_all">Expand all</a> >+ | <a href="#" id="collapse_all">Collapse all</a> >+ </span> >+ </caption> >+ <thead> >+ <tr> >+ <th>Path</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH up IN paths %] >+ <tr data-pathname="[% up.pathname | $raw %]" data-tt-id="[% loop.count | html %]" data-tt-branch="true"> >+ <td>[% up.name | html %]</td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> >+ </li> >+ </ol> >+ </fieldset> >+[% END %] >+ > [% BLOCK table_results %] > <table id="uploadresults"> > <thead> > <tr> > <th>Filename</th> > <th>Size</th> >+ <th>File checksum</th> > <th>Hashvalue</th> >+ <th>Upload path</th> > <th>Category</th> > [% IF !plugin %]<th>Public</th>[% END %] > [% IF !plugin %]<th>Temporary</th>[% END %] >@@ -167,7 +219,9 @@ > <tr> > <td>[% record.filename | html %]</td> > <td>[% record.filesize | html %]</td> >+ <td>[% IF record.checksum %] Yes [% ELSE %] No [% END %]</td> > <td>[% record.hashvalue | html %]</td> >+ <td>[% record.dir | html %]</td> > <td>[% record.uploadcategorycode | html %]</td> > [% IF !plugin %] > <td>[% IF record.public %]Yes[% ELSE %]No[% END %]</td> >@@ -222,6 +276,7 @@ > [% IF mode == 'new' || mode == 'deleted' %] > [% PROCESS form_new %] > [% PROCESS form_search %] >+ [% PROCESS upload_paths %] > [% PROCESS closer %] > [% ELSIF mode == 'report' %] > [% IF uploads %] >@@ -256,6 +311,7 @@ > [% Asset.js("js/tools-menu.js") | $raw %] > [% INCLUDE 'datatables.inc' %] > [% Asset.js("js/file-upload.js") | $raw %] >+ [% Asset.js("lib/jquery/plugins/treetable/jquery.treetable.js") | $raw %] > <script> > function StartUpload() { > if( $('#fileToUpload').prop('files').length == 0 ) return; >@@ -270,16 +326,20 @@ > $("#searchfile").hide(); > $("#lastbreadcrumb").text( _("Add a new upload") ); > >- var cat, xtra=''; >+ var dir, cat, xtra=''; > if( $("#uploadcategory").val() ) > cat = encodeURIComponent( $("#uploadcategory").val() ); > if( cat ) xtra= 'category=' + cat + '&'; > [% IF plugin %] >- xtra = xtra + 'public=1&temp=0'; >+ xtra = xtra + 'public=1&temp=0&'; > [% ELSE %] > if( !cat ) xtra = 'temp=1&'; >- if( $('#public').prop('checked') ) xtra = xtra + 'public=1'; >+ if( $('#public').prop('checked') ) xtra = xtra + 'public=1&'; > [% END %] >+ if( $("#uploadpath").val() ) >+ dir = encodeURIComponent( $("#uploadpath").val() ); >+ if( dir ) xtra= xtra + 'dir=' + dir + '&'; >+ xtra = xtra + 'checksum=' + $('#checksum:checked').val(); > xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload ); > } > function CancelUpload() { >@@ -381,7 +441,72 @@ > [% END %] > window.close(); > } >+ > $(document).ready(function() { >+ var oTable = $("#uploadpathtable"); >+ >+ $(oTable).treetable({ >+ expandable: true, >+ onNodeCollapse: function() { >+ var node = this; >+ oTable.treetable("unloadBranch", node); >+ }, >+ onNodeExpand: function() { >+ var node = this; >+ var id = node.id; >+ var pathname = node.row.data('pathname'); >+ $.ajax({ >+ type: 'POST', >+ url: "/cgi-bin/koha/svc/uploadpath", >+ data: { >+ pathname: pathname , >+ [% IF plugin %] public: 1[% END %] >+ }, >+ success: function(data) { >+ var childNodes = data.success; >+ if(childNodes) { >+ var parentNode = $("#uploadpathtable").treetable("node", id); >+ for (var i = 0; i < childNodes.length; i++) { >+ var node = childNodes[i]; >+ var nodeToAdd = $("#uploadpathtable").treetable("node",id+"."+node['id']); >+ // check if node already exists. If not add row to parent node >+ if (!nodeToAdd) { >+ var row ='<tr data-pathname="' + node['pathname'] + '" data-tt-id="' + id + '.' + ( i+1) + '" data-tt-parent-id="' + id + '" '; >+ var search = ''; >+ if (node['type'] == 'branch' ) { >+ row += ' data-tt-branch="true" '; >+ search = "<a href='/cgi-bin/koha/tools/upload.pl?op=search&"; >+ [% IF plugin %] >+ search += "plugin=1&"; >+ [% END %] >+ search += "term="+ node['path'] + "'>" + node['path'] + "</a>"; >+ }else { >+ [% IF plugin %] >+ search += ' <button class="btn btn-default btn-xs" onclick="Choose(\'' + node['hashvalue'] + '\');"><i class="fa fa-plus"></i> Choose</button>'; >+ [% END %] >+ search += ' <button class="btn btn-default btn-xs " onclick="SubmitMe( \'download\', ' + node['fileID'] + ');"><i class="fa fa-download"></i> Download</button>'; >+ search += " " + node['path']; >+ } >+ row += ' >'; >+ row += "<td>" + search + "</td>"; >+ row +="</tr>"; >+ $("#uploadpathtable").treetable("loadBranch", parentNode, row); >+ } >+ } >+ } >+ }, >+ }); >+ } >+ }); >+ $("#expand_all").click(function(e){ >+ e.preventDefault(); >+ $(oTable).treetable('expandAll'); >+ }); >+ $("#collapse_all").click(function(e){ >+ e.preventDefault(); >+ $(oTable).treetable('collapseAll'); >+ }); >+ > $("#uploadresults").dataTable($.extend(true, {}, dataTablesDefaults, { > "aoColumnDefs": [ > { 'bSortable': false, 'aTargets': [ 'nosort' ] } >@@ -389,7 +514,7 @@ > "sPaginationType": "four_button" > })); > [% IF msg %] >- ShowAlerts( [% msg | html %] ); >+ ShowAlerts( [% msg | $raw %] ); > [% END %] > $("#fileuploadcancel").hide(); > $("#public_cb").click(function() { >diff --git a/svc/uploadpath b/svc/uploadpath >new file mode 100755 >index 0000000000..08469322ee >--- /dev/null >+++ b/svc/uploadpath >@@ -0,0 +1,108 @@ >+#!/usr/bin/perl >+ >+# Copyright 2019 Devinim >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+ >+use Modern::Perl; >+ >+use CGI; >+use JSON qw(to_json); >+ >+use C4::Context; >+use C4::Auth qw(check_cookie_auth); >+use Koha::UploadedFiles; >+ >+ >+my $input = new CGI; >+ >+my ( $auth_status, $sessionID ) = >+ check_cookie_auth( $input->cookie('CGISESSID'), { tools => 'upload_general_files' } ); >+ >+if ( $auth_status ne "ok" ) { >+ print $input->header(-type => 'text/plain', -status => '403 Forbidden'); >+ exit 0; >+} >+ >+my $fullDir = $input->param('pathname'); >+my $public = $input->param('public'); >+my $json; >+ >+exit if ! -e $fullDir; >+ >+opendir(BIN, $fullDir) or die "Can't open $fullDir: $!"; >+my @files; >+my $total = 0; >+my $temporary_directory = C4::Context::temporary_directory; >+my $permanent_directory = Koha::UploadedFile->permanent_directory; >+while( defined (my $file = readdir BIN) ) { >+ next if $file eq '.' or $file eq '..' or $file eq "cgisess_koha_kohadev"; >+ >+ $total++; >+ my %hash = ( >+ id => $total, >+ pathname => "$fullDir/$file", >+ path => $file, >+ ); >+ >+ if (-d "$fullDir/$file") { >+ $hash{'type'} = "branch"; >+ }else{ >+ my ($category, $permanent) ; >+ my $path = $fullDir; >+ if ($path =~ m/^$temporary_directory/){ >+ $path =~ s/^$temporary_directory\///; >+ $permanent = 0; >+ $category = "koha_kohadev_upload"; >+ }else { >+ $path =~ s/^$permanent_directory\///; >+ $permanent = 1; >+ $category = substr( $path, rindex($path, '/')+1); >+ } >+ $path =~ s/$category$//; >+ $path =~ s/\/$//; >+ my %dir = $path ? ( dir => $path ) : (); >+ my %public = $public ? ( public => $public ) : (); >+ my $uploads = Koha::UploadedFiles->search({ >+ uploadcategorycode => $category , >+ permanent => $permanent , >+ %dir , >+ %public, >+ })->unblessed; >+ foreach my $up (@$uploads){ >+ my $filename = $up->{'checksum'} ? $up->{'hashvalue'} ."_". $up->{'filename'} : $up->{'filename'}; >+ if($filename eq $file){ >+ $hash{'fileID'} = $up->{'id'}; >+ $hash{'hashvalue'} = $up->{'hashvalue'}; >+ } >+ } >+ next unless($hash{'fileID'}); >+ } >+ push (@files, \%hash); >+} >+closedir(BIN); >+ >+unless ( @files ) { >+ $json = to_json( { success => 0, error => "ERROR" } ); >+} >+ >+$json = to_json( { success => \@files } ); >+binmode STDOUT, ":encoding(UTF-8)"; >+print $input->header( >+ -type => 'application/json', >+ -charset => 'UTF-8' >+); >+ >+print $json; >diff --git a/t/db_dependent/Upload.t b/t/db_dependent/Upload.t >index 802dc58da0..98f08ad188 100644 >--- a/t/db_dependent/Upload.t >+++ b/t/db_dependent/Upload.t >@@ -2,7 +2,7 @@ > > use Modern::Perl; > use File::Temp qw/ tempdir /; >-use Test::More tests => 13; >+use Test::More tests => 18; > use Test::Warn; > > use Test::MockModule; >@@ -46,6 +46,23 @@ our $uploads = [ > { name => 'file6', cat => undef, size => 6500 }, > { name => 'file7', cat => undef, size => 6501 }, > ], >+ #cheksum tests >+ [ >+ { name => 'file8', cat => 'A', checksum => 0, size => 2000 }, >+ ], >+ [ >+ { name => 'file9', cat => undef, checksum => 0, size => 5000 }, # temp without checksum >+ ], >+ [ >+ { name => 'file3', cat => 'B', checksum => 0, size => 1000 }, #duplicate file without checksum >+ ], >+ #path tests >+ [ >+ { name => 'file10', dir => 'A/B', cat => 'A', size => 2000 }, >+ ], >+ [ >+ { name => 'file11', dir => 'A/B', cat => undef, size => 3000 }, >+ ], > ]; > > # Redirect upload dir structure and mock C4::Context and CGI >@@ -327,6 +344,106 @@ subtest 'Testing download headers' => sub { > is_deeply(\@pdf_head, \@pdf_expect,"Get inline pdf headers for pdf"); > is_deeply(\@not_head, \@not_expect,"Get download headers for non pdf"); > }; >+ >+subtest 'Not add file checksum to the uploaded filename' => sub { >+ plan tests => 7; >+ >+ my $upl = Koha::Uploader->new({ >+ category => $uploads->[$current_upload]->[0]->{cat}, >+ checksum => 0, >+ }); #add file8 >+ my $cgi = $upl->cgi; >+ my $res = $upl->result; >+ is( $upl->err, undef, 'No errors reported' ); >+ >+ my $rec = Koha::UploadedFiles->find( $res ); >+ is( $rec->filename, 'file8', 'Check file name' ); >+ is( $rec->checksum, 0, 'Checksum false' ); >+ my $path = $rec->full_path; >+ is( -e $path, 1, 'File is found' ); >+ my $fh = $rec->file_handle; >+ is( ref($fh) eq 'IO::File' && $fh->opened, 1, 'Get returns a file handle' ); >+ my $delete = $rec->delete; >+ ok( $delete=~/^-?1$/, 'Delete successful' ); >+ isnt( -e $path, 1, 'File no longer found after delete' ); >+}; >+ >+subtest 'Temporary upload without checksum' => sub { >+ plan tests => 5; >+ >+ my $upl = Koha::Uploader->new({ >+ tmp => 1, >+ checksum => 0, >+ }); #add file9 >+ my $cgi = $upl->cgi; >+ is( $upl->count, 1, 'Upload 9 includes one temporary file' ); >+ is( $upl->err, undef, 'No errors reported' ); >+ >+ my $rec = Koha::UploadedFiles->find( $upl->result ); >+ is( $rec->checksum, 0, 'Checksum false' ); >+ is( $rec->uploadcategorycode =~ /_upload$/, 1, 'Check category temp file' ); >+ my $path = $rec->full_path; >+ is( -e $path, 1, 'File is found' ); >+}; >+ >+subtest 'Duplicate file without checksum' => sub { >+ plan tests => 5; >+ >+ my $upl = Koha::Uploader->new({ >+ category => $uploads->[$current_upload]->[0]->{cat}, >+ checksum => 0, >+ }); >+ my $cgi = $upl->cgi; >+ is( $upl->count, 1, 'Upload 10 successful' ); >+ is( $upl->err, undef, 'No errors reported' ); >+ >+ my $rec = Koha::UploadedFiles->find( $upl->result ); >+ is( $rec->filename, 'file3', 'Check file name' ); >+ is( $rec->checksum, 0, 'Checksum false' ); >+ my $e = $upl->err; >+ isnt( $e->{file2}->{code}, Koha::Uploader::ERR_EXISTS, "Already exists error reported" ); >+}; >+ >+subtest 'Add upload in dir' => sub { >+ plan tests => 8; >+ >+ my $upl = Koha::Uploader->new({ >+ category => $uploads->[$current_upload]->[0]->{cat}, >+ dir => $uploads->[$current_upload]->[0]->{dir}, >+ }); >+ my $cgi = $upl->cgi; >+ is( $upl->count, 1, 'Upload 10 successful' ); >+ isnt( $upl->result, undef, 'Result is undefined' ); >+ is( $upl->err, undef, 'No errors reported' ); >+ >+ my $rec = Koha::UploadedFiles->find( $upl->result ); >+ is( $rec->dir, 'A/B', 'Check dir A/B' ); >+ my $path = $rec->full_path; >+ is( -e $path, 1, 'File is found' ); >+ my $fh = $rec->file_handle; >+ is( ref($fh) eq 'IO::File' && $fh->opened, 1, 'Get returns a file handle' ); >+ my $delete = $rec->delete; >+ ok( $delete=~/^-?1$/, 'Delete successful' ); >+ isnt( -e $path, 1, 'File no longer found after delete' ); >+}; >+ >+subtest 'Temporary upload in dir' => sub { >+ plan tests => 4; >+ >+ my $upl = Koha::Uploader->new({ >+ tmp => 1, >+ dir => $uploads->[$current_upload]->[0]->{dir}, >+ }); #add file9 >+ my $cgi = $upl->cgi; >+ is( $upl->err, undef, 'No errors reported' ); >+ >+ my $rec = Koha::UploadedFiles->find( $upl->result ); >+ is( $rec->dir, 'A/B', 'Check dir' ); >+ is( $rec->uploadcategorycode =~ /_upload$/, 1, 'Check category temp file' ); >+ my $path = $rec->full_path; >+ is( -e $path, 1, 'File is found' ); >+}; >+ > # The end > $schema->storage->txn_rollback; > >diff --git a/tools/upload-file.pl b/tools/upload-file.pl >index 86ef2c5dc2..3448be02be 100755 >--- a/tools/upload-file.pl >+++ b/tools/upload-file.pl >@@ -75,8 +75,8 @@ sub upload_pars { # this sub parses QUERY_STRING in order to build the > $qstr = Encode::decode_utf8( uri_unescape( $qstr ) ); > # category could include a utf8 character > my $rv = {}; >- foreach my $p ( qw[public category temp] ) { >- if( $qstr =~ /(^|&)$p=(\w+)(&|$)/ ) { >+ foreach my $p ( qw[public category temp checksum dir] ) { >+ if( $qstr =~ /(^|&)$p=([\w\/\_]*)(&|$)/ ) { > $rv->{$p} = $2; > } > } >diff --git a/tools/upload.pl b/tools/upload.pl >index afb7c516f9..1a27d7be85 100755 >--- a/tools/upload.pl >+++ b/tools/upload.pl >@@ -46,11 +46,22 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >+my @paths; >+push @paths, { pathname => Koha::UploadedFile->permanent_directory, >+ name => "Permanent Directory" >+ }; >+ >+push @paths, { pathname => C4::Context::temporary_directory, >+ name => "Temporary Directory" >+ }; >+ >+$template->param( paths => \@paths); > $template->param( > index => $index, > owner => $loggedinuser, > plugin => $plugin, > uploadcategories => Koha::UploadedFiles->getCategories, >+ uploadpaths => Koha::UploadedFiles->getPaths, > ); > > if ( $op eq 'new' ) { >@@ -75,7 +86,6 @@ if ( $op eq 'new' ) { > $plugin? (): ( include_private => 1 ), > })->unblessed; > } >- > $template->param( > mode => 'report', > msg => $msg, >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20208
:
84524
|
84525
| 89954