From 31986217872eba561ed8600a0bc2bc5e03e3743e Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Wed, 27 Dec 2023 17:35:31 +0000 Subject: [PATCH] Bug 35653: Log import_patrons.pl info to action logs To test: 1. APPLY PATCH 2. Create a CSV file with a few lines that contain at least firstname, surname, cardnumber 3. Turn on "CronjobLog". 4. Run the import patron script. I did this: perl /kohadevbox/koha/misc/import_patrons.pl --file 'test1.csv' --matchpoint cardnumber -c 5. Check the action logs for cronjobs. 6. You should see info. about the import patron script. Signed-off-by: David Nind Signed-off-by: Emily Lamancusa Signed-off-by: Katrin Fischer --- misc/import_patrons.pl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/misc/import_patrons.pl b/misc/import_patrons.pl index cba3addc69..9428177414 100755 --- a/misc/import_patrons.pl +++ b/misc/import_patrons.pl @@ -24,6 +24,7 @@ use Pod::Usage qw( pod2usage ); use Koha::Script; use Koha::Patrons::Import; +use C4::Log qw( cronlogaction ); my $Import = Koha::Patrons::Import->new(); my $csv_file; @@ -40,6 +41,9 @@ my @preserve_fields; my $update_dateexpiry; my $update_dateexpiry_from_today; + +my $command_line_options = join(" ",@ARGV); + GetOptions( 'c|confirm' => \$confirm, 'f|file=s' => \$csv_file, @@ -60,7 +64,11 @@ pod2usage(1) if $help; pod2usage(q|--file is required|) unless $csv_file; pod2usage(q|--matchpoint is required|) unless $matchpoint; -warn "Running in dry-run mode, provide --confirm to apply the changes\n" unless $confirm; +if ( $confirm ) { + cronlogaction({ action => 'Run', info => $command_line_options }) +} else { + warn "Running in dry-run mode, provide --confirm to apply the changes\n"; +} my $handle; open( $handle, "<", $csv_file ) or die $!; @@ -87,9 +95,9 @@ my $imported = $return->{imported}; my $overwritten = $return->{overwritten}; my $alreadyindb = $return->{already_in_db}; my $invalid = $return->{invalid}; +my $total = $imported + $alreadyindb + $invalid + $overwritten; if ($verbose) { - my $total = $imported + $alreadyindb + $invalid + $overwritten; say q{}; say "Import complete:"; say "Imported: $imported"; @@ -110,6 +118,12 @@ if ($verbose > 2 ) { say Data::Dumper::Dumper( $feedback ); } +my $info = "Import complete. " . "Imported: " . $imported . " Overwritten: " . $overwritten . " Skipped: " . $alreadyindb . " Invalid: " . $invalid . " Total: " . $total; + +if ( $confirm ) { + cronlogaction({ action => 'End', info => $info }); +} + =head1 NAME import_patrons.pl - CLI script to import patrons data into Koha -- 2.39.5