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 279-284 __PAZPAR2_TOGGLE_XML_POST__ Link Here
279
 <authorityservershadow>1</authorityservershadow>
279
 <authorityservershadow>1</authorityservershadow>
280
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
280
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
281
 <enable_plugins>0</enable_plugins>
281
 <enable_plugins>0</enable_plugins>
282
 <uploadPath></uploadPath>
282
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
283
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
283
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
284
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
284
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
285
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
(-)a/installer/data/mysql/sysprefs.sql (-1 lines)
Lines 401-407 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
401
('UNIMARCField100Language','fre',NULL,'UNIMARC field 100 default language','short'),
401
('UNIMARCField100Language','fre',NULL,'UNIMARC field 100 default language','short'),
402
('UniqueItemFields','barcode','','Space-separated list of fields that should be unique (used in acquisition module for item creation). Fields must be valid SQL column names of items table','Free'),
402
('UniqueItemFields','barcode','','Space-separated list of fields that should be unique (used in acquisition module for item creation). Fields must be valid SQL column names of items table','Free'),
403
('UpdateTotalIssuesOnCirc','0',NULL,'Whether to update the totalissues field in the biblio on each circ.','YesNo'),
403
('UpdateTotalIssuesOnCirc','0',NULL,'Whether to update the totalissues field in the biblio on each circ.','YesNo'),
404
('uploadPath','',NULL,'Sets the upload path for the upload.pl plugin. For security reasons, the upload path MUST NOT be a public, webserver accessible directory.','Free')
405
('uppercasesurnames','0',NULL,'If ON, surnames are converted to upper case in patron entry form','YesNo'),
404
('uppercasesurnames','0',NULL,'If ON, surnames are converted to upper case in patron entry form','YesNo'),
406
('URLLinkText','',NULL,'Text to display as the link anchor in the OPAC','free'),
405
('URLLinkText','',NULL,'Text to display as the link anchor in the OPAC','free'),
407
('UseAuthoritiesForTracings','1','0','Use authority record numbers for subject tracings instead of heading strings.','YesNo'),
406
('UseAuthoritiesForTracings','1','0','Use authority record numbers for subject tracings instead of heading strings.','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (-7 / +2 lines)
Lines 8100-8110 if (CheckVersion($DBversion)) { Link Here
8100
$DBversion = "XXX";
8100
$DBversion = "XXX";
8101
if ( CheckVersion($DBversion) ) {
8101
if ( CheckVersion($DBversion) ) {
8102
    $dbh->do("
8102
    $dbh->do("
8103
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
8104
        VALUES('uploadPath','','Sets the upload path for the upload.pl plugin','','');
8105
    ");
8106
8107
    $dbh->do("
8108
        CREATE TABLE uploaded_files (
8103
        CREATE TABLE uploaded_files (
8109
            id CHAR(40) NOT NULL PRIMARY KEY,
8104
            id CHAR(40) NOT NULL PRIMARY KEY,
8110
            filename TEXT NOT NULL,
8105
            filename TEXT NOT NULL,
Lines 8113-8120 if ( CheckVersion($DBversion) ) { Link Here
8113
    ");
8108
    ");
8114
8109
8115
    print "Upgrade to $DBversion done (Bug 6874: New cataloging plugin upload.pl)\n";
8110
    print "Upgrade to $DBversion done (Bug 6874: New cataloging plugin upload.pl)\n";
8116
    print "This plugin comes with a new syspref (uploadPath) and a new table (uploaded_files)\n";
8111
    print "This plugin comes with a new config variable (uploadPath) and a new table (uploaded_files)\n";
8117
    print "To use it, set 'uploadPath' and 'OPACBaseURL' system preferences and link this plugin to a subfield (856\$u for instance)\n";
8112
    print "To use it, set 'uploadPath' config variable and 'OPACBaseURL' system preference and link this plugin to a subfield (856\$u for instance)\n";
8118
    SetVersion($DBversion);
8113
    SetVersion($DBversion);
8119
}
8114
}
8120
8115
(-)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 (-6 / +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;
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::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');
45
- 

Return to bug 6874