|
Lines 39-44
use Koha::SearchEngine;
Link Here
|
| 39 |
use Koha::SearchEngine::Indexer; |
39 |
use Koha::SearchEngine::Indexer; |
| 40 |
use Koha::Plugins::Handler; |
40 |
use Koha::Plugins::Handler; |
| 41 |
use Koha::Logger; |
41 |
use Koha::Logger; |
|
|
42 |
use List::MoreUtils qw( uniq ); |
| 42 |
|
43 |
|
| 43 |
our (@ISA, @EXPORT_OK); |
44 |
our (@ISA, @EXPORT_OK); |
| 44 |
BEGIN { |
45 |
BEGIN { |
|
Lines 69-74
BEGIN {
Link Here
|
| 69 |
GetImportBiblios |
70 |
GetImportBiblios |
| 70 |
GetImportRecordsRange |
71 |
GetImportRecordsRange |
| 71 |
GetItemNumbersFromImportBatch |
72 |
GetItemNumbersFromImportBatch |
|
|
73 |
GetImportItemsBranches |
| 72 |
|
74 |
|
| 73 |
GetImportBatchStatus |
75 |
GetImportBatchStatus |
| 74 |
SetImportBatchStatus |
76 |
SetImportBatchStatus |
|
Lines 812-817
sub _batchCommitItems {
Link Here
|
| 812 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" ); |
814 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" ); |
| 813 |
$item_marc->field($itemtag)->delete_subfield( code => $itemsubfield ); |
815 |
$item_marc->field($itemtag)->delete_subfield( code => $itemsubfield ); |
| 814 |
|
816 |
|
|
|
817 |
my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); |
| 818 |
my $homebranch = $item_marc->subfield( $homebranchfield, $homebranchsubfield ); |
| 819 |
my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); |
| 820 |
my $holdingbranch = $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield ); |
| 821 |
|
| 822 |
my @branches = map { $_->branchcode } Koha::Libraries->search->as_list; |
| 823 |
my %branches = map { $_ => 1 } @branches; |
| 824 |
|
| 825 |
my $missing_branchcode; |
| 826 |
$missing_branchcode = $homebranch if ( !exists( $branches{$homebranch} ) ); |
| 827 |
$missing_branchcode = $holdingbranch if ( !exists( $branches{$holdingbranch} ) ); |
| 828 |
if ($missing_branchcode) { |
| 829 |
$updsth->bind_param( 1, 'error' ); |
| 830 |
$updsth->bind_param( 2, undef ); |
| 831 |
$updsth->bind_param( 3, "Branch code $missing_branchcode missing" ); |
| 832 |
$updsth->bind_param( 4, $row->{'import_items_id'} ); |
| 833 |
$updsth->execute(); |
| 834 |
$num_items_errored++; |
| 835 |
next; |
| 836 |
} |
| 815 |
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } ); |
837 |
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } ); |
| 816 |
if( $itemnumber ) { |
838 |
if( $itemnumber ) { |
| 817 |
$updsth->bind_param( 1, 'imported' ); |
839 |
$updsth->bind_param( 1, 'imported' ); |
|
Lines 1195-1200
sub GetImportRecordsRange {
Link Here
|
| 1195 |
|
1217 |
|
| 1196 |
} |
1218 |
} |
| 1197 |
|
1219 |
|
|
|
1220 |
=head2 GetImportItemsBranches |
| 1221 |
|
| 1222 |
my @results = GetImportItemsBranches($batch_id); |
| 1223 |
|
| 1224 |
Returns an array of imported item branches. |
| 1225 |
|
| 1226 |
=cut |
| 1227 |
|
| 1228 |
sub GetImportItemsBranches { |
| 1229 |
my ( $batch_id ) = @_; |
| 1230 |
|
| 1231 |
my $dbh = C4::Context->dbh; |
| 1232 |
my $query = "SELECT import_items_id, import_items.marcxml, encoding |
| 1233 |
FROM import_items |
| 1234 |
JOIN import_records USING (import_record_id) |
| 1235 |
WHERE import_batch_id = ? |
| 1236 |
ORDER BY import_items_id"; |
| 1237 |
my @params; |
| 1238 |
push( @params, $batch_id ); |
| 1239 |
my $sth = $dbh->prepare_cached($query); |
| 1240 |
$sth->execute(@params); |
| 1241 |
my $results = $sth->fetchall_arrayref( {} ); |
| 1242 |
my @branch; |
| 1243 |
my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); |
| 1244 |
my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); |
| 1245 |
foreach my $row (@$results) { |
| 1246 |
my $item_marc = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); |
| 1247 |
push @branch, $item_marc->subfield( $homebranchfield, $homebranchsubfield ); |
| 1248 |
push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );; |
| 1249 |
} |
| 1250 |
$sth->finish(); |
| 1251 |
return uniq @branch; |
| 1252 |
} |
| 1253 |
|
| 1198 |
=head2 GetBestRecordMatch |
1254 |
=head2 GetBestRecordMatch |
| 1199 |
|
1255 |
|
| 1200 |
my $record_id = GetBestRecordMatch($import_record_id); |
1256 |
my $record_id = GetBestRecordMatch($import_record_id); |