From 827c1ca4084ec8edef090c82c287143b12774d5f Mon Sep 17 00:00:00 2001 From: Jason Boyer Date: Tue, 10 Mar 2026 16:31:04 -0400 Subject: [PATCH] Bug 42059: Add a filename option to Connextion importer Allow admins to assign filenames to Connexion importer configs to allow multiple libraries to maintain separate staged import batches. Signed-off-by: Jason Boyer --- C4/ImportBatch.pm | 3 +- misc/bin/connexion_import_daemon.pl | 45 ++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index ccf87a8867..3551053368 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -162,7 +162,8 @@ sub GetWebserviceBatchId { my $dbh = C4::Context->dbh; my $sql = $WEBSERVICE_BASE_QRY; my @args; - foreach my $field (qw(matcher_id overlay_action nomatch_action item_action)) { + $sql .= " AND file_name IS NULL" unless exists $params->{file_name}; + foreach my $field (qw(matcher_id overlay_action nomatch_action item_action file_name)) { if ( my $val = $params->{$field} ) { $sql .= " AND $field = ?"; push @args, $val; diff --git a/misc/bin/connexion_import_daemon.pl b/misc/bin/connexion_import_daemon.pl index b62d639ca8..8c9d3cc78d 100755 --- a/misc/bin/connexion_import_daemon.pl +++ b/misc/bin/connexion_import_daemon.pl @@ -20,6 +20,7 @@ use strict; use warnings; +use POSIX qw( strftime ); use Getopt::Long qw( GetOptions ); my ( $help, $config, $daemon ); @@ -143,6 +144,20 @@ Config file format: show up in all catalog searches as soon as the indexing catches up. Defaults to `stage`. + import_file_name + Filename string used to distinguish batches in staff client. Supports 2 + placeholders: + {TS} + A YYYYMMDDHHmmss timestamp + {0} + A simple incremented count modulo the number of 0's within the + braces, up to 5. For example, {0} = 1 through 9, {00} = 01 through + 99, etc. up to 99999. + If no placeholders are used the named batch will be used for all imports + until imported or removed, if any placeholder is used then every import + will be a separate batch. If not supplied the default `(webservice)` + batch will be used. + match Which code to use for matching MARC records when deciding whether to add or replace a record. @@ -220,7 +235,7 @@ Explanation of `import_mode`: batch immediately. - When using `stage`, each request will cause records to be added to an existing batch. -- The batch name is always `(webservice)`. +- The batch name is `(webservice)` unless specified with import_file_name. - If you change `import_mode` from `stage` to `direct` after some records have already been staged, the next request will cause all records in that batch to be imported into the catalog, not just the records from the latest @@ -332,12 +347,24 @@ exit; $self->{port} = delete( $param{port} ) or die "Port not specified"; + $self->{import_fn_count} = 1; + $self->{import_fn_len} = 1; + $self->{import_file_name} = delete( $param{import_file_name} ); + if ( $self->{import_file_name} ) { + if ( $self->{import_file_name} =~ /\{(0+)\}/ ) { + my $len = int(length($1)); + if ( $len lt 1 || $len gt 5 ) { $len = 1; } + $self->{import_fn_len} = $len; + } + } + $self->{debug} = delete( $param{debug} ); my $log_fh; close $self->{log_fh} if $self->{log_fh}; if ( my $logfile = delete $param{log} ) { open( $log_fh, '>>', $logfile ) or die "Cannot open $logfile for write: $!"; + $log_fh->autoflush(1); } else { $log_fh = \*STDERR; } @@ -543,6 +570,21 @@ exit; return $self->error_response("Unauthorized request"); } + my $import_fname = ""; + if ( $self->{import_file_name} ) { + my $ts = strftime("%Y%m%d%H%M%S", localtime); + my $pad = $self->{import_fn_len}; + $import_fname = $self->{import_file_name}; + + $import_fname =~ s/\{TS\}/$ts/g; + $import_fname =~ s/\{0+\}/sprintf("%0${pad}u", $self->{import_fn_count})/eg; + + $self->{import_fn_count} = $self->{import_fn_count} + 1; + $self->{import_fn_count} = $self->{import_fn_count} % ($self->{import_fn_len} ** 10); + } + + + my $ua; if ( $self->{user} ) { $user = $self->{user}; @@ -561,6 +603,7 @@ exit; 'framework' => $self->{params}->{framework}, 'overlay_framework' => $self->{params}->{overlay_framework}, 'item_action' => $self->{params}->{item_action}, + 'file_name' => $import_fname, 'xml' => $data }; -- 2.34.1