Bug 20727: Move temporary_directory() to C4::Context

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Kyle M Hall 2018-05-29 08:03:55 -04:00 committed by Nick Clemens
parent c2b0c92800
commit 3ff7c27d98
12 changed files with 23 additions and 22 deletions

View File

@ -1740,7 +1740,7 @@ sub _get_session_params {
}
else {
# catch all defaults to tmp should work on all systems
my $dir = Koha::UploadedFile->temporary_directory;
my $dir = C4::Context::temporary_directory;
my $instance = C4::Context->config( 'database' ); #actually for packages not exactly the instance name, but generally safer to leave it as it is
return { dsn => "driver:File;serializer:yaml;id:md5", dsn_args => { Directory => "$dir/cgisess_$instance" } };
}

View File

@ -1076,6 +1076,18 @@ sub only_my_library {
&& C4::Context->userenv->{branch};
}
=head3 temporary_directory
Returns root directory for temporary storage
=cut
sub temporary_directory {
my ( $class ) = @_;
return C4::Context->config('tmp_path') || File::Spec->tmpdir;
}
1;
__END__

View File

@ -239,7 +239,7 @@ sub checkauth {
my $dbh = C4::Context->dbh();
my $template_name;
$template_name = "installer/auth.tt";
my $sessdir = File::Spec->catdir( Koha::UploadedFile->temporary_directory, 'cgisess_' . C4::Context->config('database') ); # same construction as in C4/Auth
my $sessdir = File::Spec->catdir( C4::Context::temporary_directory, 'cgisess_' . C4::Context->config('database') ); # same construction as in C4/Auth
# state variables
my $loggedin = 0;

View File

@ -40,7 +40,7 @@ sub new {
my $self = {
account => $acct,
schema => $schema,
working_dir => Koha::UploadedFile->temporary_directory, #temporary work directory
working_dir => C4::Context::temporary_directory, #temporary work directory
transfer_date => DateTime->now( time_zone => 'local' ),
};

View File

@ -160,17 +160,6 @@ sub permanent_directory {
return C4::Context->config('upload_path');
}
=head3 tmp_directory
Returns root directory for temporary storage
=cut
sub temporary_directory {
my ( $class ) = @_;
return C4::Context->config('tmp_path') || File::Spec->tmpdir;
}
=head3 _type
Returns name of corresponding DBIC resultset

View File

@ -189,7 +189,7 @@ sub _init {
my ( $self, $params ) = @_;
$self->{rootdir} = Koha::UploadedFile->permanent_directory;
$self->{tmpdir} = Koha::UploadedFile->temporary_directory;
$self->{tmpdir} = C4::Context::temporary_directory;
$params->{tmp} = $params->{temp} if !exists $params->{tmp};
$self->{temporary} = $params->{tmp}? 1: 0; #default false

View File

@ -263,7 +263,7 @@ if ( ! defined C4::Context->config('upload_path') ) {
}
if ( ! C4::Context->config('tmp_path') ) {
my $temporary_directory = Koha::UploadedFile->temporary_directory;
my $temporary_directory = C4::Context::temporary_directory;
push @xml_config_warnings, {
error => 'tmp_path_missing',
effective_tmp_dir => $temporary_directory,

View File

@ -184,7 +184,7 @@ sub set_holiday {
sub get_filename {
my $directory = shift;
if ( !$directory ) {
$directory = Koha::UploadedFile->temporary_directory;
$directory = C4::Context::temporary_directory;
}
if ( !-d $directory ) {
carp "Could not write to $directory ... does not exist!";

View File

@ -63,7 +63,7 @@ is( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->
# test absolute path change in get_template with Koha::Plugin::Test
# using the mock set before
# we also add tmpdir as an approved template dir
t::lib::Mocks::mock_config( 'pluginsdir', [ Koha::UploadedFile->temporary_directory ] );
t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context::temporary_directory ] );
my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1 );
print $fh 'I am [% filename %]';
close $fh;

View File

@ -64,7 +64,7 @@ $db->mock(
_new_schema => sub { return Schema(); }
);
my $dir = Koha::UploadedFile->temporary_directory;
my $dir = C4::Context::temporary_directory;
my $data = [
[qw/ 1 2013-11-15 2013-11-15/],

View File

@ -126,9 +126,9 @@ subtest "Absolute path change in _get_template_file" => sub {
# We create a simple template in /tmp.
# We simulate an anonymous OPAC session; the OPACBaseURL template variable
# should be filled by get_template_and_user.
t::lib::Mocks::mock_config( 'pluginsdir', [ Koha::UploadedFile->temporary_directory ] );
t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context::temporary_directory ] );
t::lib::Mocks::mock_preference( 'OPACBaseURL', 'without any doubt' );
my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => Koha::UploadedFile->temporary_directory );
my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context::temporary_directory );
print $fh q|I am a [% quality %] template [% OPACBaseURL %]|;
close $fh;
my ( $template, $login, $cookie ) = C4::Auth::get_template_and_user({

View File

@ -74,7 +74,7 @@ subtest 'permanent_directory and temporary_directory' => sub {
# Check mocked directories
is( Koha::UploadedFile->permanent_directory, $tempdir,
'Check permanent directory' );
is( Koha::UploadedFile->temporary_directory, $tempdir,
is( C4::Context::temporary_directory, $tempdir,
'Check temporary directory' );
};