Bugzilla – Attachment 157098 Details for
Bug 34355
Automated MARC record ordering process
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34355: Add match_field and match_value to allow multiple accounts in the same file directory
Bug-34355-Add-matchfield-and-matchvalue-to-allow-m.patch (text/plain), 11.09 KB, created by
Matt Blenkinsop
on 2023-10-13 13:51:30 UTC
(
hide
)
Description:
Bug 34355: Add match_field and match_value to allow multiple accounts in the same file directory
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-10-13 13:51:30 UTC
Size:
11.09 KB
patch
obsolete
>From 77c7b022cf18a3774690a6857efe207286dbe036 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Thu, 7 Sep 2023 10:47:15 +0000 >Subject: [PATCH] Bug 34355: Add match_field and match_value to allow multiple > accounts in the same file directory > >--- > Koha/MarcOrder.pm | 46 +++++++++++++++++++ > Koha/Schema/Result/MarcOrderAccount.pm | 24 +++++++++- > admin/marc_order_accounts.pl | 2 + > .../bug_34355-add_marc_order_accounts.pl | 16 ++++--- > installer/data/mysql/kohastructure.sql | 2 + > .../en/modules/admin/marc_order_accounts.tt | 10 ++++ > misc/cronjobs/marc_ordering_process.pl | 20 ++++---- > 7 files changed, 104 insertions(+), 16 deletions(-) > >diff --git a/Koha/MarcOrder.pm b/Koha/MarcOrder.pm >index 3cfc9cdf3e..0d3a1e262d 100644 >--- a/Koha/MarcOrder.pm >+++ b/Koha/MarcOrder.pm >@@ -842,6 +842,52 @@ sub create_order_lines { > } > > >+=head3 match_file_to_account >+ >+ my $file_match = Koha::MarcOrder->match_file_to_account({ >+ filename => $filename, >+ filepath => $filepath, >+ profile => $profile >+ }); >+ >+ Used by the cronjob to detect whether a file matches the account and should be processed >+ >+=cut >+ >+ >+sub match_file_to_account { >+ my ($self, $args) = @_; >+ >+ my $match = 0; >+ my $filename = $args->{filename}; >+ my $filepath = $args->{filepath}; >+ my $profile = $args->{profile}; >+ my $format = index($filename, '.mrc') != -1 ? 'ISO2709' : 'MARCXML'; >+ >+ my ( $errors, $marcrecords ); >+ if ( $format eq 'MARCXML' ) { >+ ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filepath, $profile->encoding ); >+ } elsif ( $format eq 'ISO2709' ) { >+ ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( >+ $filepath, $profile->record_type, >+ $profile->encoding >+ ); >+ } >+ >+ my $match_record = @{ $marcrecords }[0]; >+ my ( $field, $subfield ) = split /\$/, $profile->match_field; >+ >+ my $field_value = $match_record->subfield( $field, $subfield ); >+ my $match_value = $profile->match_value; >+ >+ if($field_value eq $match_value) { >+ $match = 1; >+ } >+ >+ return $match; >+} >+ >+ > =head3 import_batches_list > > Fetches import batches matching the batch to be added to the basket and adds these to the $template >diff --git a/Koha/Schema/Result/MarcOrderAccount.pm b/Koha/Schema/Result/MarcOrderAccount.pm >index 88f6119290..be720da960 100644 >--- a/Koha/Schema/Result/MarcOrderAccount.pm >+++ b/Koha/Schema/Result/MarcOrderAccount.pm >@@ -116,6 +116,22 @@ type of record in the file > > file encoding > >+=head2 match_field >+ >+ data_type: 'varchar' >+ is_nullable: 1 >+ size: 10 >+ >+the field that a vendor account has been mapped to in a marc record >+ >+=head2 match_value >+ >+ data_type: 'varchar' >+ is_nullable: 1 >+ size: 50 >+ >+the value to be matched against the marc record >+ > =cut > > __PACKAGE__->add_columns( >@@ -143,6 +159,10 @@ __PACKAGE__->add_columns( > { data_type => "varchar", is_nullable => 1, size => 50 }, > "encoding", > { data_type => "varchar", is_nullable => 1, size => 50 }, >+ "match_field", >+ { data_type => "varchar", is_nullable => 1, size => 10 }, >+ "match_value", >+ { data_type => "varchar", is_nullable => 1, size => 50 }, > ); > > =head1 PRIMARY KEY >@@ -200,8 +220,8 @@ __PACKAGE__->belongs_to( > ); > > >-# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-07-18 16:31:16 >-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vMLrmisXQnn2e60qW7ppnA >+# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-07 08:55:26 >+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:6pN1TLuqkf9rQaeQ7Wf26A > > > # You can replace this text with custom code or comments, and it will be preserved on regeneration >diff --git a/admin/marc_order_accounts.pl b/admin/marc_order_accounts.pl >index e8938e0c6c..f3c692e1f7 100644 >--- a/admin/marc_order_accounts.pl >+++ b/admin/marc_order_accounts.pl >@@ -89,6 +89,8 @@ if( $op eq 'acct_form') { > item_action => scalar $input->param('item_action'), > record_type => scalar $input->param('record_type'), > encoding => scalar $input->param('encoding') || 'UTF-8', >+ match_field => scalar $input->param('match_field'), >+ match_value => scalar $input->param('match_value'), > }; > > if(scalar $input->param('id')) { >diff --git a/installer/data/mysql/atomicupdate/bug_34355-add_marc_order_accounts.pl b/installer/data/mysql/atomicupdate/bug_34355-add_marc_order_accounts.pl >index f0a5f2ab21..149afbeee9 100644 >--- a/installer/data/mysql/atomicupdate/bug_34355-add_marc_order_accounts.pl >+++ b/installer/data/mysql/atomicupdate/bug_34355-add_marc_order_accounts.pl >@@ -1,14 +1,15 @@ > use Modern::Perl; > > return { >- bug_number => "34355", >+ bug_number => "34355", > description => "Add a table to allow creation of MARC order accounts and a syspref to activate it.", >- up => sub { >+ up => sub { > my ($args) = @_; >- my ($dbh, $out) = @$args{qw(dbh out)}; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; > >- unless( TableExists('marc_order_accounts') ) { >- $dbh->do(q{ >+ unless ( TableExists('marc_order_accounts') ) { >+ $dbh->do( >+ q{ > CREATE TABLE `marc_order_accounts` ( > `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier and primary key', > `description` varchar(250) NOT NULL COMMENT 'description of this account', >@@ -22,11 +23,14 @@ return { > `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed', > `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file', > `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding', >+ `match_field` varchar(10) DEFAULT NULL COMMENT 'the field that a vendor account has been mapped to in a marc record', >+ `match_value` varchar(50) DEFAULT NULL COMMENT 'the value to be matched against the marc record', > PRIMARY KEY (`id`), > CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, > CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >- }); >+ } >+ ); > > say $out "Added new table 'marc_order_accounts'"; > } else { >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 27f9ab4a6f..8fd5d3b761 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -4112,6 +4112,8 @@ CREATE TABLE `marc_order_accounts` ( > `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed', > `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file', > `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding', >+ `match_field` varchar(10) DEFAULT NULL COMMENT 'the field that a vendor account has been mapped to in a marc record', >+ `match_value` varchar(50) DEFAULT NULL COMMENT 'the value to be matched against the marc record', > PRIMARY KEY (`id`), > CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, > CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt >index 1ef0c0f117..2b7ecc4926 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt >@@ -126,6 +126,16 @@ MARC Order Accounts > <input type="text" name="download_directory" id="download_directory" size="20" value="[% account.download_directory | html %]" /> > <div class="hint">The download directory specifies the directory in your koha installation that should be searched for new files.</div> > </li> >+ <li> >+ <label for="match_field">Match field: </label> >+ <input type="text" name="match_field" id="match_field" size="20" value="[% account.match_field | html %]" /> >+ <div class="hint">(Optional): If you have files from multiple vendors in the same file directory, the match field is the field in the marc record that will be checked to see if the file should be processed by this account.</div> >+ </li> >+ <li> >+ <label for="match_value">Match value: </label> >+ <input type="text" name="match_value" id="match_value" size="20" value="[% account.match_value | html %]" /> >+ <div class="hint">(Optional): This is the value that will be checked against the match field to see if the file matches this account. If it does it will be processed by this account, if not it will be skipped.</div> >+ </li> > </ol> > </fieldset> > <fieldset class="rows"> >diff --git a/misc/cronjobs/marc_ordering_process.pl b/misc/cronjobs/marc_ordering_process.pl >index e53ffb6765..8e3b7cb656 100644 >--- a/misc/cronjobs/marc_ordering_process.pl >+++ b/misc/cronjobs/marc_ordering_process.pl >@@ -106,14 +106,18 @@ foreach my $acct ( @accounts ) { > > foreach my $filename ( @files ) { > say sprintf "Creating order lines from file %s", $filename if $verbose; >+ my $full_path = "$working_dir/$filename"; >+ my $args = { >+ filename => $filename, >+ filepath => $full_path, >+ profile => $acct, >+ agent => 'cron' >+ }; >+ if($acct->match_field && $acct->match_value) { >+ my $file_match = Koha::MarcOrder->match_file_to_account($args); >+ next if !$file_match; >+ } > if($confirm) { >- my $full_path = "$working_dir/$filename"; >- my $args = { >- filename => $filename, >- filepath => $full_path, >- profile => $acct, >- agent => 'cron' >- }; > my $result = Koha::MarcOrder->create_order_lines_from_file($args); > if($result->{success}) { > $files_processed++; >@@ -125,7 +129,7 @@ foreach my $acct ( @accounts ) { > }; > } > } >- say sprintf "%s files processed", $files_processed unless $files_processed == 0; >+ say sprintf "%s file(s) processed", $files_processed unless $files_processed == 0; > print "Moving to next account\n\n"; > } > print "Process complete\n"; >-- >2.37.1 (Apple Git-137.1)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34355
:
154705
|
154706
|
154707
|
154708
|
154709
|
154710
|
157092
|
157093
|
157094
|
157095
|
157096
|
157097
|
157098
|
157099
|
157100
|
160858
|
160859
|
160860
|
160861
|
160862
|
160863
|
160864
|
160865
|
160866
|
160867
|
160868
|
160869
|
160870
|
160871
|
160872
|
160873
|
160874
|
160875
|
169896
|
169897
|
169898
|
169899
|
169900
|
169901
|
169902
|
169903
|
169904
|
170395
|
170401
|
170402
|
170403
|
170404
|
170405
|
170406
|
170407
|
170408
|
170409
|
173054
|
173055
|
173056
|
173057
|
173058
|
173059
|
173060
|
173061
|
173062
|
173063
|
173064
|
173065
|
173066
|
173709
|
173805
|
173806
|
173809
|
173824
|
173825
|
173993
|
173994
|
173995
|
173996
|
173997
|
173998
|
173999
|
174000
|
174001
|
174002
|
174003
|
174004
|
174005
|
174006
|
174007
|
174008
|
174009
|
174010
|
174362
|
174363
|
174364
|
174365
|
174366
|
174367
|
174368
|
174369
|
174370
|
174371
|
174372
|
174373
|
174374
|
174375
|
174376
|
174377
|
174378
|
174379
|
174380
|
174382
|
174383