From 37adeecc8fc3886a5876366ccc18d7ecf535f887 Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Fri, 11 May 2018 14:24:32 -0300
Subject: [PATCH] Bug 20428: Make upload_tmp a more general tmp directory
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
---
Koha/UploadedFile.pm | 5 ++-
about.pl | 7 ++--
debian/docs/koha-create.xml | 8 ++---
debian/scripts/koha-create | 34 +++++++++----------
debian/scripts/koha-create-dirs | 3 +-
debian/templates/koha-conf-site.xml.in | 2 +-
etc/koha-conf.xml | 2 +-
.../intranet-tmpl/prog/en/modules/about.tt | 8 ++---
8 files changed, 37 insertions(+), 32 deletions(-)
diff --git a/Koha/UploadedFile.pm b/Koha/UploadedFile.pm
index b7efa85cde..6a148f7102 100644
--- a/Koha/UploadedFile.pm
+++ b/Koha/UploadedFile.pm
@@ -168,7 +168,10 @@ Returns root directory for temporary storage
sub temporary_directory {
my ( $class ) = @_;
- return C4::Context->config('upload_tmp_path') || File::Spec->tmpdir;
+ my $temporary_directory = ( C4::Context->config('tmp_path') )
+ ? C4::Context->config('upload_tmp_path') . '/uploads'
+ : File::Spec->tmpdir;
+ return $temporary_directory;
}
=head3 _type
diff --git a/about.pl b/about.pl
index 6fdb5785e6..c4b0233d60 100755
--- a/about.pl
+++ b/about.pl
@@ -24,6 +24,7 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use DateTime::TimeZone;
+use File::Spec;
use List::MoreUtils qw/ any /;
use LWP::Simple;
use Module::Load::Conditional qw(can_load);
@@ -261,10 +262,10 @@ if ( ! defined C4::Context->config('upload_path') ) {
}
}
-if ( ! defined C4::Context->config('upload_tmp_path') ) {
+if ( ! defined C4::Context->config('tmp_path') ) {
push @xml_config_warnings, {
- error => 'uploadtmppath_entry_missing',
- effective_upload_tmp_dir => Koha::UploadedFile->temporary_directory
+ error => 'tmp_path_entry_missing',
+ effective_tmp_dir => File::Spec->tmpdir
}
}
diff --git a/debian/docs/koha-create.xml b/debian/docs/koha-create.xml
index 07c1052ffe..b00b80a3e5 100644
--- a/debian/docs/koha-create.xml
+++ b/debian/docs/koha-create.xml
@@ -42,7 +42,7 @@
<arg><option>--template-cache-dir</option> directory</arg>
<arg><option>--timezone</option> time/zone</arg>
<arg><option>--upload-path</option> directory</arg>
- <arg><option>--upload-tmp-path</option> directory</arg>
+ <arg><option>--tmp-path</option> directory</arg>
<arg><option>--letsencrypt</option></arg>
<arg><option>--help</option>|<option>-h</option></arg>
@@ -203,10 +203,10 @@
</varlistentry>
<varlistentry>
- <term><option>--upload-tmp-path</option></term>
+ <term><option>--tmp-path</option></term>
<listitem>
- <para>Specify a <option>directory</option> for storing the temporarily uploaded files of the instance.
- It defaults to <filename>/var/lib/koha/instance/uploads_tmp</filename>.</para>
+ <para>Specify a <option>directory</option> for storing the temporary files. For example temporarily
+ uploaded files of the instance. It defaults to <filename>/var/lib/koha/instance/tmp</filename>.</para>
</listitem>
</varlistentry>
diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create
index c340c645fd..8cdc219e8b 100755
--- a/debian/scripts/koha-create
+++ b/debian/scripts/koha-create
@@ -74,8 +74,8 @@ Options:
--timezone time/zone Specify a timezone. e.g. America/Argentina
--upload-path dir Set a user defined upload_path. It defaults to
/var/lib/koha/<instance>/uploads
- --upload-tmp-path dir Set a user defined upload_tmp_path. It defaults to
- /var/lib/koha/<instance>/uploads_tmp
+ --tmp-path dir Set a user defined tmp_path. It defaults to
+ /var/lib/koha/<instance>/tmp
--letsencrypt Set up a https-only site with letsencrypt certificates
--help,-h Show this help.
@@ -120,7 +120,7 @@ generate_config_file() {
-e "s#__TEMPLATE_CACHE_DIR__#$TEMPLATE_CACHE_DIR#g" \
-e "s#__TIMEZONE__#$TIMEZONE#g" \
-e "s#__UPLOAD_PATH__#$UPLOAD_PATH#g" \
- -e "s#__UPLOAD_TMP_PATH__#$UPLOAD_TMP_PATH#g" \
+ -e "s#__TMP_PATH__#$TMP_PATH#g" \
-e "s/__LOG_DIR__/\/var\/log\/koha\/$name/g" \
-e "s/__PLUGINS_DIR__/\/var\/lib\/koha\/$name\/plugins/g" \
-e "s/__MEMCACHED_NAMESPACE__/$MEMCACHED_NAMESPACE/g" \
@@ -328,18 +328,18 @@ set_upload_path()
if [ "$CLO_UPLOAD_PATH" != "" ]; then
UPLOAD_PATH=$CLO_UPLOAD_PATH
else
- UPLOAD_PATH="$UPLOAD_PATH_BASE/$instance/$UPLOAD_DIR"
+ UPLOAD_PATH="$INSTANCE_PATH_BASE/$instance/$UPLOAD_DIR"
fi
}
-set_upload_tmp_path()
+set_tmp_path()
{
local instance="$1"
- if [ "$CLO_UPLOAD_TMP_PATH" != "" ]; then
- UPLOAD_TMP_PATH=$CLO_UPLOAD_TMP_PATH
+ if [ "$CLO_TMP_PATH" != "" ]; then
+ TMP_PATH=$CLO_TMP_PATH
else
- UPLOAD_TMP_PATH="$UPLOAD_PATH_BASE/$instance/$UPLOAD_TMP_DIR"
+ TMP_PATH="$INSTANCE_PATH_BASE/$instance/$TMP_DIR"
fi
}
@@ -425,15 +425,15 @@ MEMCACHED_PREFIX=""
# hardcoded memcached defaults
DEFAULT_MEMCACHED_SERVERS="127.0.0.1:11211"
DEFAULT_MEMCACHED_PREFIX="koha_"
-# hardcoded upload_path
-UPLOAD_PATH_BASE="/var/lib/koha"
+# hardcoded instance base path
+INSTANCE_PATH_BASE="/var/lib/koha"
UPLOAD_DIR="uploads"
UPLOAD_PATH=""
# timezone defaults to empty
TIMEZONE=""
# hardcoded upload_tmp_path
-UPLOAD_TMP_DIR="uploads_tmp"
-UPLOAD_TMP_PATH=""
+TMP_DIR="tmp"
+TMP_PATH=""
# cache base dir
CACHE_DIR_BASE="/var/cache/koha"
# Generate a randomizaed API secret
@@ -464,7 +464,7 @@ fi
[ $# -ge 1 ] && [ $# -le 16 ] || ( usage ; die "Error: wrong parameters" )
-TEMP=`getopt -o chrpm:l:d:f:b:a: -l create-db,request-db,populate-db,use-db,enable-sru,sru-port:,help,marcflavor:,auth-idx:,biblio-idx:,zebralang:,defaultsql:,configfile:,passwdfile:,dbhost:,database:,adminuser:,memcached-servers:,memcached-prefix:,template-cache-dir:,timezone:,upload-path:,upload-tmp-path:,letsencrypt, \
+TEMP=`getopt -o chrpm:l:d:f:b:a: -l create-db,request-db,populate-db,use-db,enable-sru,sru-port:,help,marcflavor:,auth-idx:,biblio-idx:,zebralang:,defaultsql:,configfile:,passwdfile:,dbhost:,database:,adminuser:,memcached-servers:,memcached-prefix:,template-cache-dir:,timezone:,upload-path:,tmp-path:,letsencrypt, \
-n "$0" -- "$@"`
# Note the quotes around `$TEMP': they are essential!
@@ -480,7 +480,7 @@ CLO_AUTHORITIES_INDEXING_MODE=""
CLO_MEMCACHED_SERVERS=""
CLO_MEMCACHED_PREFIX=""
CLO_UPLOAD_PATH=""
-CLO_UPLOAD_TMP_PATH=""
+CLO_TMP_PATH=""
CLO_LETSENCRYPT=""
CLO_TEMPLATE_CACHE_DIR=""
CLO_TIMEZONE=""
@@ -529,8 +529,8 @@ while true ; do
CLO_TIMEZONE="$2" ; shift 2 ;;
--upload-path)
CLO_UPLOAD_PATH="$2" ; shift 2 ;;
- --upload-tmp-path)
- CLO_UPLOAD_TMP_PATH="$2" ; shift 2 ;;
+ --tmp-path)
+ CLO_TMP_PATH="$2" ; shift 2 ;;
--letsencrypt)
CLO_LETSENCRYPT="yes" ; shift ;;
-h|--help)
@@ -600,7 +600,7 @@ set_authorities_indexing_mode $AUTHORITIES_INDEXING_MODE $ZEBRA_MARC_FORMAT
name="$1"
set_upload_path $name
-set_upload_tmp_path $name
+set_tmp_path $name
if [ "$op" = use ] && [ "$CLO_DATABASE" = "" ] &&
( [ ! -f "$PASSWDFILE" ] || [ ! `cat $PASSWDFILE | grep "^$name:"` ] )
diff --git a/debian/scripts/koha-create-dirs b/debian/scripts/koha-create-dirs
index f7777dffb5..a09d523c83 100755
--- a/debian/scripts/koha-create-dirs
+++ b/debian/scripts/koha-create-dirs
@@ -55,7 +55,8 @@ do
userdir "$name" "/var/lib/koha/$name/biblios/tmp"
userdir "$name" "/var/lib/koha/$name/plugins"
userdir "$name" "/var/lib/koha/$name/uploads"
- userdir "$name" "/var/lib/koha/$name/uploads_tmp"
+ userdir "$name" "/var/lib/koha/$name/tmp"
+ userdir "$name" "/var/lib/koha/$name/tmp/uploads"
userdir "$name" "/var/lock/koha/$name"
userdir "$name" "/var/lock/koha/$name/authorities"
userdir "$name" "/var/lock/koha/$name/biblios"
diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in
index 7d91711bb8..d2b47fcb30 100644
--- a/debian/templates/koha-conf-site.xml.in
+++ b/debian/templates/koha-conf-site.xml.in
@@ -261,7 +261,7 @@ __END_SRU_PUBLICSERVER__
<pluginsdir>__PLUGINS_DIR__</pluginsdir> <!-- This entry can be repeated to use multiple directories -->
<enable_plugins>0</enable_plugins>
<upload_path>__UPLOAD_PATH__</upload_path>
- <upload_tmp_path>__UPLOAD_TMP_PATH__</upload_tmp_path>
+ <tmp_path>__TMP_PATH__</tmp_path>
<intranetdir>/usr/share/koha/intranet/cgi-bin</intranetdir>
<opacdir>/usr/share/koha/opac/cgi-bin/opac</opacdir>
<opachtdocs>/usr/share/koha/opac/htdocs/opac-tmpl</opachtdocs>
diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml
index 111c40fa26..541606598b 100644
--- a/etc/koha-conf.xml
+++ b/etc/koha-conf.xml
@@ -93,7 +93,7 @@ __PAZPAR2_TOGGLE_XML_POST__
<pluginsdir>__PLUGINS_DIR__</pluginsdir> <!-- This entry can be repeated to use multiple directories -->
<enable_plugins>0</enable_plugins>
<upload_path></upload_path>
- <upload_tmp_path></upload_tmp_path>
+ <tmp_path></tmp_path>
<intranetdir>__INTRANET_CGI_DIR__</intranetdir>
<opacdir>__OPAC_CGI_DIR__/opac</opacdir>
<opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt
index 0e462b66e5..a3e7bf74e6 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt
@@ -414,12 +414,12 @@
Also note that you need to properly set the OPACBaseURL preference for the file upload plugin to work.
</td>
</tr>
- [% ELSIF config_entry.error == 'uploadtmppath_entry_missing' %]
+ [% ELSIF config_entry.error == 'tmp_path_entry_missing' %]
<tr>
<th scope="row"><b>Warning</b></th>
- <td>You are missing the <upload_tmp_path> entry in your koha-conf.xml file. Please
- add it, pointing to the configured temporary file upload directory for your Koha instance.
- The effective temporary file upload directory is '[% config_entry.effective_upload_tmp_dir %]'
+ <td>You are missing the <tmp_path> entry in your koha-conf.xml file. Please
+ add it, pointing to the configured temporary directory for your Koha instance.
+ The effective temporary directory is '[% config_entry.effective_tmp_dir %]'.
</td>
</tr>
[% END %]
--
2.17.0