- my @data;
- my ( $results, $modules, $actions, $interfaces );
- if ( defined $actions[0] && $actions[0] ne '' ) { $actions = \@actions; } # match All means no limit
- if ( $modules[0] ne '' ) { $modules = \@modules; } # match All means no limit
- if ( defined $interfaces[0] && $interfaces[0] ne '' ) { $interfaces = \@interfaces; } # match All means no limit
- $results = GetLogs( $datefrom, $dateto, $user, $modules, $actions, $object, $info, $interfaces );
- @data = @$results;
- foreach my $result (@data) {
+ if ($datefrom and $dateto ) {
+ my $dateto_endday = dt_from_string($dateto);
+ $dateto_endday->set( # We set last second of day to see all log from that day
+ hour => 23,
+ minute => 59,
+ second => 59
+ );
+ $search_params{'timestamp'} = {
+ -between => [
+ $dtf->format_datetime( dt_from_string($datefrom) ),
+ $dtf->format_datetime( $dateto_endday ),
+ ]
+ };
+ } elsif ($datefrom) {
+ $search_params{'timestamp'} = {
+ '>=' => $dtf->format_datetime( dt_from_string($datefrom) )
+ };
+ } elsif ($dateto) {
+ my $dateto_endday = dt_from_string($dateto);
+ $dateto_endday->set( # We set last second of day to see all log from that day
+ hour => 23,
+ minute => 59,
+ second => 59
+ );
+ $search_params{'timestamp'} = {
+ '<=' => $dtf->format_datetime( $dateto_endday )
+ };
+ }
+ # Circulation uses RENEWAL, but Patrons uses RENEW, this helps to find both
+ if ( grep { $_ eq 'RENEW'} @actions ) { push @actions, 'RENEWAL' };
+
+ $search_params{user} = $user if $user;
+ $search_params{module} = { -in => [ @modules ] } if ( defined $modules[0] and $modules[0] ne '' ) ;
+ $search_params{action} = { -in => [ @actions ] } if ( defined $actions[0] && $actions[0] ne '' );
+ $search_params{interface} = { -in => [ @interfaces ] } if ( defined $interfaces[0] && $interfaces[0] ne '' );
+
+ if ( @modules == 1 && $object_type eq 'biblio' ) {
+ # Handle 'Modification log' from cataloguing
+ my @itemnumbers = Koha::Items->search({ biblionumber => $object })->get_column('itemnumber');
+ $search_params{'-or'} = [
+ { -and => { object => $object, info => { -like => 'biblio%' }}},
+ { -and => { object => \@itemnumbers, info => { -like => 'item%' }}},
+ ];
+ } else {
+ $search_params{info} = { -like => '%' . $info . '%' } if $info;
+ $search_params{object} = $object if $object;
+ }
+
+ my @logs = Koha::ActionLogs->search(\%search_params)->as_list;