Bug 33146: Unit tests
[koha-ffzg.git] / tools / viewlog.pl
index 5909cb3..9db4e43 100755 (executable)
@@ -33,6 +33,7 @@ use Koha::Database;
 use Koha::DateUtils qw( dt_from_string );
 use Koha::Items;
 use Koha::Patrons;
+use Koha::Recalls;
 
 
 =head1 viewlog.pl
@@ -139,7 +140,7 @@ if ($do_it) {
         $search_params{object} = $object if $object;
     }
 
-    my @logs = Koha::ActionLogs->search(\%search_params);
+    my @logs = Koha::ActionLogs->search(\%search_params)->as_list;
 
     my @data;
     foreach my $log (@logs) {
@@ -156,6 +157,7 @@ if ($do_it) {
             $itemnumber = $log->info if ( $log->module eq "CIRCULATION" );
             my $item = Koha::Items->find($itemnumber);
             if ($item) {
+                $result->{'object_found'}     = 1;
                 $result->{'biblionumber'}     = $item->biblionumber;
                 $result->{'biblioitemnumber'} = $item->biblionumber;
                 $result->{'barcode'}          = $item->barcode;
@@ -189,6 +191,15 @@ if ($do_it) {
             }
         }
 
+        # get recall information
+        if ( $log->module eq "RECALLS" ) {
+            if ( $log->object ) {
+                my $recall = Koha::Recalls->find( $log->object );
+                if ( $recall && $output eq 'screen' ) {
+                    $result->{recall} = $recall;
+                }
+            }
+        }
         push @data, $result;
     }
     if ( $output eq "screen" ) {
@@ -219,8 +230,8 @@ if ($do_it) {
 
         # Printing to a csv file
         my $content = q{};
-        my $delimiter = C4::Context->preference('CSVDelimiter') || ',';
         if (@data) {
+            my $delimiter = C4::Context->csv_delimiter;
             my $csv = Text::CSV::Encoded->new( { encoding_out => 'utf8', sep_char => $delimiter } );
             $csv or die "Text::CSV::Encoded->new FAILED: " . Text::CSV::Encoded->error_diag();