Bug 20727: Move temporary_directory() to C4::Context
authorKyle M Hall <kyle@bywatetsolutions.com>
Tue, 29 May 2018 12:03:55 +0000 (08:03 -0400)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 22 Jun 2018 16:10:09 +0000 (16:10 +0000)
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>

12 files changed:
C4/Auth.pm
C4/Context.pm
C4/InstallAuth.pm
Koha/Edifact/Transport.pm
Koha/UploadedFile.pm
Koha/Uploader.pm
about.pl
misc/cronjobs/fines.pl
t/db_dependent/Plugins.t
t/db_dependent/Sitemapper.t
t/db_dependent/Templates.t
t/db_dependent/Upload.t

index 645fd34..6f00a1b 100644 (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" } };
     }
index 7ce91b6..247b7a4 100644 (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__
index 6922d04..d279ae8 100644 (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;
index 0fa1d67..c14df3a 100644 (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' ),
     };
 
index a8eb8a3..cee9265 100644 (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
index 8e6a2aa..e1b34c9 100644 (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
index 70900dd..6151d18 100755 (executable)
--- a/about.pl
+++ b/about.pl
@@ -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,
index fec343e..9fa7b94 100755 (executable)
@@ -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!";
index 3f7601e..2415059 100755 (executable)
@@ -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;
index 3e47d6f..91a4933 100755 (executable)
@@ -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/],
index f45dcff..2efce26 100755 (executable)
@@ -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({
index 3637244..ccb879a 100644 (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' );
 };