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

(-)a/C4/UploadedFiles.pm (-3 / +3 lines)
Lines 61-67 use C4::Context; Link Here
61
sub _get_file_path {
61
sub _get_file_path {
62
    my ($id, $dirname, $filename) = @_;
62
    my ($id, $dirname, $filename) = @_;
63
63
64
    my $uploadPath = C4::Context->preference('uploadPath');
64
    my $uploadPath = C4::Context->config('uploadPath');
65
    my $filepath = "$uploadPath/$dirname/${id}_$filename";
65
    my $filepath = "$uploadPath/$dirname/${id}_$filename";
66
    $filepath =~ s|/+|/|g;
66
    $filepath =~ s|/+|/|g;
67
67
Lines 81-87 Hash keys are: Link Here
81
81
82
=item * filename: name of the file
82
=item * filename: name of the file
83
83
84
=item * dir: directory where file is stored (relative to syspref 'uploadPath')
84
=item * dir: directory where file is stored (relative to config variable 'uploadPath')
85
85
86
=back
86
=back
87
87
Lines 123-129 Parameters: Link Here
123
123
124
=item * $filename: name of the file
124
=item * $filename: name of the file
125
125
126
=item * $dir: directory where to store the file (path relative to syspref 'uploadPath'
126
=item * $dir: directory where to store the file (path relative to config variable 'uploadPath'
127
127
128
=item * $io_handle: valid IO::Handle object, can be retrieved with
128
=item * $io_handle: valid IO::Handle object, can be retrieved with
129
$cgi->upload('uploaded_file')->handle;
129
$cgi->upload('uploaded_file')->handle;
(-)a/cataloguing/value_builder/upload.pl (-17 / +21 lines)
Lines 108-129 sub plugin { Link Here
108
            }
108
            }
109
        }
109
        }
110
    } else {
110
    } else {
111
        my $filefield = CGI::filefield(
111
        my $upload_path = C4::Context->config('uploadPath');
112
            -name => 'uploaded_file',
112
        if ($upload_path) {
113
            -size => 50,
113
            my $filefield = CGI::filefield(
114
        );
114
                -name => 'uploaded_file',
115
115
                -size => 50,
116
        my $upload_path = C4::Context->preference('uploadPath');
116
            );
117
        my $dirs_tree = [ {
117
118
            name => '/',
118
            my $dirs_tree = [ {
119
            value => '/',
119
                name => '/',
120
            dirs => finddirs($upload_path)
120
                value => '/',
121
        } ];
121
                dirs => finddirs($upload_path)
122
122
            } ];
123
        $template->param(
123
124
            dirs_tree => $dirs_tree,
124
            $template->param(
125
            filefield => $filefield
125
                dirs_tree => $dirs_tree,
126
        );
126
                filefield => $filefield
127
            );
128
        } else {
129
            $template->param( error_upload_path_not_configured => 1 );
130
        }
127
    }
131
    }
128
132
129
    $template->param(
133
    $template->param(
Lines 137-143 sub plugin { Link Here
137
# Build a hierarchy of directories
141
# Build a hierarchy of directories
138
sub finddirs {
142
sub finddirs {
139
    my $base = shift;
143
    my $base = shift;
140
    my $upload_path = C4::Context->preference('uploadPath');
144
    my $upload_path = C4::Context->config('uploadPath');
141
    my $found = 0;
145
    my $found = 0;
142
    my @dirs;
146
    my @dirs;
143
    my @files = glob("$base/*");
147
    my @files = glob("$base/*");
(-)a/etc/koha-conf.xml (+1 lines)
Lines 278-283 __PAZPAR2_TOGGLE_XML_POST__ Link Here
278
 <authorityservershadow>1</authorityservershadow>
278
 <authorityservershadow>1</authorityservershadow>
279
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
279
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
280
 <enable_plugins>0</enable_plugins>
280
 <enable_plugins>0</enable_plugins>
281
 <uploadPath></uploadPath>
281
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
282
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
282
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
283
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
283
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
284
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
(-)a/installer/data/mysql/sysprefs.sql (-1 lines)
Lines 427-430 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' Link Here
427
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo');
427
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo');
428
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacHoldNotes',0,'Show hold notes on OPAC','','YesNo');
428
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacHoldNotes',0,'Show hold notes on OPAC','','YesNo');
429
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo');
429
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo');
430
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('uploadPath','','Sets the upload path for the upload.pl plugin. For security reasons, the upload path MUST NOT be a public, webserver accessible directory.','','');
(-)a/installer/data/mysql/updatedatabase.pl (-7 / +2 lines)
Lines 6994-7004 if ( CheckVersion($DBversion) ) { Link Here
6994
$DBversion = "XXX";
6994
$DBversion = "XXX";
6995
if ( CheckVersion($DBversion) ) {
6995
if ( CheckVersion($DBversion) ) {
6996
    $dbh->do("
6996
    $dbh->do("
6997
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
6998
        VALUES('uploadPath','','Sets the upload path for the upload.pl plugin','','');
6999
    ");
7000
7001
    $dbh->do("
7002
        CREATE TABLE uploaded_files (
6997
        CREATE TABLE uploaded_files (
7003
            id CHAR(40) NOT NULL PRIMARY KEY,
6998
            id CHAR(40) NOT NULL PRIMARY KEY,
7004
            filename TEXT NOT NULL,
6999
            filename TEXT NOT NULL,
Lines 7007-7014 if ( CheckVersion($DBversion) ) { Link Here
7007
    ");
7002
    ");
7008
7003
7009
    print "Upgrade to $DBversion done (Bug 6874: New cataloging plugin upload.pl)\n";
7004
    print "Upgrade to $DBversion done (Bug 6874: New cataloging plugin upload.pl)\n";
7010
    print "This plugin comes with a new syspref (uploadPath) and a new table (uploaded_files)\n";
7005
    print "This plugin comes with a new config variable (uploadPath) and a new table (uploaded_files)\n";
7011
    print "To use it, set 'uploadPath' and 'OPACBaseURL' system preferences and link this plugin to a subfield (856\$u for instance)\n";
7006
    print "To use it, set 'uploadPath' config variable and 'OPACBaseURL' system preference and link this plugin to a subfield (856\$u for instance)\n";
7012
    SetVersion($DBversion);
7007
    SetVersion($DBversion);
7013
}
7008
}
7014
7009
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (-4 lines)
Lines 109-118 Cataloging: Link Here
109
            - pref: UNIMARCField100Language
109
            - pref: UNIMARCField100Language
110
              class: short
110
              class: short
111
            - as default language in the UNIMARC field 100 when creating a new record or in the field plugin.
111
            - as default language in the UNIMARC field 100 when creating a new record or in the field plugin.
112
        -
113
            - Absolute path where to store files uploaded in MARC record (plugin upload.pl)
114
            - pref: uploadPath
115
              class: multi
116
    Display:
112
    Display:
117
        -
113
        -
118
            - 'Separate multiple displayed authors, series or subjects with '
114
            - 'Separate multiple displayed authors, series or subjects with '
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/upload.tt (-9 / +15 lines)
Lines 54-68 Link Here
54
            [% END %]
54
            [% END %]
55
        [% END %]
55
        [% END %]
56
56
57
        <h2>Please select the file to upload : </h2>
57
        [% IF (error_upload_path_not_configured) %]
58
        <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/cataloguing/plugin_launcher.pl">
58
          <h2>Configuration error</h2>
59
            [% filefield %]
59
          <p>Configuration variable 'uploadPath' is not configured.</p>
60
            <h3>Choose where to upload file</h3>
60
          <p>Please configure it in your koha-conf.xml</p>
61
            [% INCLUDE list_dirs dirs = dirs_tree %]
61
        [% ELSE %]
62
            <input type="hidden" name="plugin_name" value="upload.pl" />
62
          <h2>Please select the file to upload : </h2>
63
            <input type="hidden" name="index" value="[% index %]" />
63
          <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/cataloguing/plugin_launcher.pl">
64
            <input type="submit">
64
              [% filefield %]
65
        </form>
65
              <h3>Choose where to upload file</h3>
66
              [% INCLUDE list_dirs dirs = dirs_tree %]
67
              <input type="hidden" name="plugin_name" value="upload.pl" />
68
              <input type="hidden" name="index" value="[% index %]" />
69
              <input type="submit">
70
          </form>
71
        [% END %]
66
    [% END %]
72
    [% END %]
67
73
68
[% END %]
74
[% END %]
(-)a/t/db_dependent/UploadedFiles.t (-5 / +3 lines)
Lines 5-10 use File::Temp qw/ tempdir /; Link Here
5
use Test::CGI::Multipart;
5
use Test::CGI::Multipart;
6
use Test::More tests => 11;
6
use Test::More tests => 11;
7
7
8
use t::lib::Mocks::Context;
9
8
use C4::Context;
10
use C4::Context;
9
use C4::UploadedFiles;
11
use C4::UploadedFiles;
10
12
Lines 17-26 $tcm->upload_file( Link Here
17
);
19
);
18
my $cgi = $tcm->create_cgi;
20
my $cgi = $tcm->create_cgi;
19
21
20
# Save the value of uploadPath and set it to a temporary directory
21
my $uploadPath = C4::Context->preference('uploadPath');
22
my $tempdir = tempdir(CLEANUP => 1);
22
my $tempdir = tempdir(CLEANUP => 1);
23
C4::Context->set_preference('uploadPath', $tempdir);
23
t::lib::Mocks::Context::mock_config('uploadPath', $tempdir);
24
24
25
my $testfilename = $cgi->param('testfile');
25
my $testfilename = $cgi->param('testfile');
26
my $testfile_fh = $cgi->upload('testfile');
26
my $testfile_fh = $cgi->upload('testfile');
Lines 38-44 ok(-e $file->{filepath}, "File $file->{filepath} exists"); Link Here
38
ok(C4::UploadedFiles::DelUploadedFile($id), "DelUploadedFile($id) returned true");
38
ok(C4::UploadedFiles::DelUploadedFile($id), "DelUploadedFile($id) returned true");
39
ok(! -e $file->{filepath}, "File $file->{filepath} does not exist anymore");
39
ok(! -e $file->{filepath}, "File $file->{filepath} does not exist anymore");
40
40
41
C4::Context->set_preference('uploadPath', $uploadPath);
42
43
is(C4::UploadedFiles::UploadFile($testfilename, '../', $testfile_fh->handle), undef, 'UploadFile with $dir containing ".." return undef');
41
is(C4::UploadedFiles::UploadFile($testfilename, '../', $testfile_fh->handle), undef, 'UploadFile with $dir containing ".." return undef');
44
is(C4::UploadedFiles::GetUploadedFile(), undef, 'GetUploadedFile without parameters returns undef');
42
is(C4::UploadedFiles::GetUploadedFile(), undef, 'GetUploadedFile without parameters returns undef');
(-)a/t/lib/Mocks/Context.pm (-2 / +23 lines)
Lines 1-5 Link Here
1
package t::lib::Mocks::Context;
1
package t::lib::Mocks::Context;
2
use t::lib::Mocks::Context;
2
3
use Modern::Perl;
4
use Test::MockModule;
3
use C4::Context;
5
use C4::Context;
4
6
5
sub MockPreference {
7
sub MockPreference {
Lines 10-13 sub MockPreference { Link Here
10
    $mock_object->mock('preference', sub { &t::lib::Mocks::Context::MockPreference( @_, $value, $mock_object ) });
12
    $mock_object->mock('preference', sub { &t::lib::Mocks::Context::MockPreference( @_, $value, $mock_object ) });
11
    return $r;
13
    return $r;
12
}
14
}
15
16
our %config;
17
sub mock_config {
18
    my ($variable, $value) = @_;
19
20
    $config{$variable} = $value;
21
22
    my $module = new Test::MockModule('C4::Context');
23
    unless ($module->is_mocked('config')) {
24
        $module->mock('config', sub {
25
            my ($self, $variable) = @_;
26
            if (exists $config{$variable}) {
27
                return $config{$variable};
28
            } else {
29
                return $module->original('config')->($self, $variable);
30
            }
31
        });
32
    }
33
}
34
13
1;
35
1;
14
- 

Return to bug 6874