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 93-98 __PAZPAR2_TOGGLE_XML_POST__ Link Here
93
 <authorityservershadow>1</authorityservershadow>
93
 <authorityservershadow>1</authorityservershadow>
94
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
94
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
95
 <enable_plugins>0</enable_plugins>
95
 <enable_plugins>0</enable_plugins>
96
 <uploadPath></uploadPath>
96
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
97
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
97
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
98
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
98
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
99
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
(-)a/installer/data/mysql/sysprefs.sql (-1 lines)
Lines 417-423 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
417
('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'),
417
('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'),
418
('UpdateNotForLoanStatusOnCheckin', '', 'NULL', 'This is a list of value pairs. When an item is checked in, if the not for loan value on the left matches the items not for loan value it will be updated to the right-hand value. E.g. ''-1: 0'' will cause an item that was set to ''Ordered'' to now be available for loan. Each pair of values should be on a separate line.', 'Free'),
418
('UpdateNotForLoanStatusOnCheckin', '', 'NULL', 'This is a list of value pairs. When an item is checked in, if the not for loan value on the left matches the items not for loan value it will be updated to the right-hand value. E.g. ''-1: 0'' will cause an item that was set to ''Ordered'' to now be available for loan. Each pair of values should be on a separate line.', 'Free'),
419
('UpdateTotalIssuesOnCirc','0',NULL,'Whether to update the totalissues field in the biblio on each circ.','YesNo'),
419
('UpdateTotalIssuesOnCirc','0',NULL,'Whether to update the totalissues field in the biblio on each circ.','YesNo'),
420
('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')
421
('uppercasesurnames','0',NULL,'If ON, surnames are converted to upper case in patron entry form','YesNo'),
420
('uppercasesurnames','0',NULL,'If ON, surnames are converted to upper case in patron entry form','YesNo'),
422
('URLLinkText','',NULL,'Text to display as the link anchor in the OPAC','free'),
421
('URLLinkText','',NULL,'Text to display as the link anchor in the OPAC','free'),
423
('UseAuthoritiesForTracings','1','0','Use authority record numbers for subject tracings instead of heading strings.','YesNo'),
422
('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 8592-8602 if ( CheckVersion($DBversion) ) { Link Here
8592
$DBversion = "XXX";
8592
$DBversion = "XXX";
8593
if ( CheckVersion($DBversion) ) {
8593
if ( CheckVersion($DBversion) ) {
8594
    $dbh->do("
8594
    $dbh->do("
8595
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
8596
        VALUES('uploadPath','','Sets the upload path for the upload.pl plugin','','');
8597
    ");
8598
8599
    $dbh->do("
8600
        CREATE TABLE uploaded_files (
8595
        CREATE TABLE uploaded_files (
8601
            id CHAR(40) NOT NULL PRIMARY KEY,
8596
            id CHAR(40) NOT NULL PRIMARY KEY,
8602
            filename TEXT NOT NULL,
8597
            filename TEXT NOT NULL,
Lines 8605-8612 if ( CheckVersion($DBversion) ) { Link Here
8605
    ");
8600
    ");
8606
8601
8607
    print "Upgrade to $DBversion done (Bug 6874: New cataloging plugin upload.pl)\n";
8602
    print "Upgrade to $DBversion done (Bug 6874: New cataloging plugin upload.pl)\n";
8608
    print "This plugin comes with a new syspref (uploadPath) and a new table (uploaded_files)\n";
8603
    print "This plugin comes with a new config variable (uploadPath) and a new table (uploaded_files)\n";
8609
    print "To use it, set 'uploadPath' and 'OPACBaseURL' system preferences and link this plugin to a subfield (856\$u for instance)\n";
8604
    print "To use it, set 'uploadPath' config variable and 'OPACBaseURL' system preference and link this plugin to a subfield (856\$u for instance)\n";
8610
    SetVersion($DBversion);
8605
    SetVersion($DBversion);
8611
}
8606
}
8612
8607
(-)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