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 88-93 __PAZPAR2_TOGGLE_XML_POST__ Link Here
88
 <authorityservershadow>1</authorityservershadow>
88
 <authorityservershadow>1</authorityservershadow>
89
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
89
 <pluginsdir>__PLUGINS_DIR__</pluginsdir>
90
 <enable_plugins>0</enable_plugins>
90
 <enable_plugins>0</enable_plugins>
91
 <uploadPath></uploadPath>
91
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
92
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
92
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
93
 <opacdir>__OPAC_CGI_DIR__/opac</opacdir>
93
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
94
 <opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
(-)a/installer/data/mysql/sysprefs.sql (-1 lines)
Lines 442-448 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
442
('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'),
442
('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'),
443
('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'),
443
('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'),
444
('UpdateTotalIssuesOnCirc','0',NULL,'Whether to update the totalissues field in the biblio on each circ.','YesNo'),
444
('UpdateTotalIssuesOnCirc','0',NULL,'Whether to update the totalissues field in the biblio on each circ.','YesNo'),
445
('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')
446
('uppercasesurnames','0',NULL,'If ON, surnames are converted to upper case in patron entry form','YesNo'),
445
('uppercasesurnames','0',NULL,'If ON, surnames are converted to upper case in patron entry form','YesNo'),
447
('URLLinkText','',NULL,'Text to display as the link anchor in the OPAC','free'),
446
('URLLinkText','',NULL,'Text to display as the link anchor in the OPAC','free'),
448
('UsageStats', 0, NULL, 'Share anonymous usage data on the Hea Koha community website.', 'YesNo'),
447
('UsageStats', 0, NULL, 'Share anonymous usage data on the Hea Koha community website.', 'YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (-7 / +2 lines)
Lines 9796-9806 if(CheckVersion($DBversion)) { Link Here
9796
$DBversion = "XXX";
9796
$DBversion = "XXX";
9797
if ( CheckVersion($DBversion) ) {
9797
if ( CheckVersion($DBversion) ) {
9798
    $dbh->do("
9798
    $dbh->do("
9799
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
9800
        VALUES('uploadPath','','Sets the upload path for the upload.pl plugin','','');
9801
    ");
9802
9803
    $dbh->do("
9804
        CREATE TABLE uploaded_files (
9799
        CREATE TABLE uploaded_files (
9805
            id CHAR(40) NOT NULL PRIMARY KEY,
9800
            id CHAR(40) NOT NULL PRIMARY KEY,
9806
            filename TEXT NOT NULL,
9801
            filename TEXT NOT NULL,
Lines 9809-9816 if ( CheckVersion($DBversion) ) { Link Here
9809
    ");
9804
    ");
9810
9805
9811
    print "Upgrade to $DBversion done (Bug 6874: New cataloging plugin upload.pl)\n";
9806
    print "Upgrade to $DBversion done (Bug 6874: New cataloging plugin upload.pl)\n";
9812
    print "This plugin comes with a new syspref (uploadPath) and a new table (uploaded_files)\n";
9807
    print "This plugin comes with a new config variable (uploadPath) and a new table (uploaded_files)\n";
9813
    print "To use it, set 'uploadPath' and 'OPACBaseURL' system preferences and link this plugin to a subfield (856\$u for instance)\n";
9808
    print "To use it, set 'uploadPath' config variable and 'OPACBaseURL' system preference and link this plugin to a subfield (856\$u for instance)\n";
9814
    SetVersion($DBversion);
9809
    SetVersion($DBversion);
9815
}
9810
}
9816
9811
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (-4 lines)
Lines 125-134 Cataloging: Link Here
125
            - 'MARC21: "952$a 952$b 952$c"'
125
            - 'MARC21: "952$a 952$b 952$c"'
126
            - Note that the FA framework is excluded from the permission.
126
            - Note that the FA framework is excluded from the permission.
127
            - If the pref is empty, no fields are restricted.
127
            - If the pref is empty, no fields are restricted.
128
        -
129
            - Absolute path where to store files uploaded in MARC record (plugin upload.pl)
130
            - pref: uploadPath
131
              class: multi
132
    Display:
128
    Display:
133
        -
129
        -
134
            - 'Separate multiple displayed authors, series or subjects with '
130
            - '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