|
Lines 41-46
use Koha::SearchEngine;
Link Here
|
| 41 |
use Koha::SearchEngine::Indexer; |
41 |
use Koha::SearchEngine::Indexer; |
| 42 |
use Koha::Plugins::Handler; |
42 |
use Koha::Plugins::Handler; |
| 43 |
use Koha::Logger; |
43 |
use Koha::Logger; |
|
|
44 |
use List::MoreUtils qw( uniq ); |
| 44 |
|
45 |
|
| 45 |
our ( @ISA, @EXPORT_OK ); |
46 |
our ( @ISA, @EXPORT_OK ); |
| 46 |
|
47 |
|
|
Lines 72-77
BEGIN {
Link Here
|
| 72 |
GetImportBiblios |
73 |
GetImportBiblios |
| 73 |
GetImportRecordsRange |
74 |
GetImportRecordsRange |
| 74 |
GetItemNumbersFromImportBatch |
75 |
GetItemNumbersFromImportBatch |
|
|
76 |
GetImportItemsBranches |
| 75 |
|
77 |
|
| 76 |
GetImportBatchStatus |
78 |
GetImportBatchStatus |
| 77 |
SetImportBatchStatus |
79 |
SetImportBatchStatus |
|
Lines 843-848
sub _batchCommitItems {
Link Here
|
| 843 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber"); |
845 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber"); |
| 844 |
$item_marc->field($itemtag)->delete_subfield( code => $itemsubfield ); |
846 |
$item_marc->field($itemtag)->delete_subfield( code => $itemsubfield ); |
| 845 |
|
847 |
|
|
|
848 |
my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); |
| 849 |
my $homebranch = $item_marc->subfield( $homebranchfield, $homebranchsubfield ); |
| 850 |
my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); |
| 851 |
my $holdingbranch = $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield ); |
| 852 |
|
| 853 |
my @branches = map { $_->branchcode } Koha::Libraries->search->as_list; |
| 854 |
my %branches = map { $_ => 1 } @branches; |
| 855 |
|
| 856 |
my $missing_branchcode; |
| 857 |
$missing_branchcode = $homebranch if ( !exists( $branches{$homebranch} ) ); |
| 858 |
$missing_branchcode = $holdingbranch if ( !exists( $branches{$holdingbranch} ) ); |
| 859 |
if ($missing_branchcode) { |
| 860 |
$updsth->bind_param( 1, 'error' ); |
| 861 |
$updsth->bind_param( 2, undef ); |
| 862 |
$updsth->bind_param( 3, "Branch code $missing_branchcode missing" ); |
| 863 |
$updsth->bind_param( 4, $row->{'import_items_id'} ); |
| 864 |
$updsth->execute(); |
| 865 |
$num_items_errored++; |
| 866 |
next; |
| 867 |
} |
| 868 |
|
| 846 |
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( |
869 |
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( |
| 847 |
$item_marc, $biblionumber, |
870 |
$item_marc, $biblionumber, |
| 848 |
{ biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } |
871 |
{ biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } |
|
Lines 1248-1253
sub GetImportRecordsRange {
Link Here
|
| 1248 |
|
1271 |
|
| 1249 |
} |
1272 |
} |
| 1250 |
|
1273 |
|
|
|
1274 |
=head2 GetImportItemsBranches |
| 1275 |
|
| 1276 |
my @results = GetImportItemsBranches($batch_id); |
| 1277 |
|
| 1278 |
Returns an array of imported item branches. |
| 1279 |
|
| 1280 |
=cut |
| 1281 |
|
| 1282 |
sub GetImportItemsBranches { |
| 1283 |
my ( $batch_id ) = @_; |
| 1284 |
|
| 1285 |
my $dbh = C4::Context->dbh; |
| 1286 |
my $query = "SELECT import_items_id, import_items.marcxml, encoding |
| 1287 |
FROM import_items |
| 1288 |
JOIN import_records USING (import_record_id) |
| 1289 |
WHERE import_batch_id = ? |
| 1290 |
ORDER BY import_items_id"; |
| 1291 |
my @params; |
| 1292 |
push( @params, $batch_id ); |
| 1293 |
my $sth = $dbh->prepare_cached($query); |
| 1294 |
$sth->execute(@params); |
| 1295 |
my $results = $sth->fetchall_arrayref( {} ); |
| 1296 |
my @branch; |
| 1297 |
my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); |
| 1298 |
my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); |
| 1299 |
foreach my $row (@$results) { |
| 1300 |
my $item_marc = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); |
| 1301 |
push @branch, $item_marc->subfield( $homebranchfield, $homebranchsubfield ); |
| 1302 |
push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );; |
| 1303 |
} |
| 1304 |
$sth->finish(); |
| 1305 |
return uniq @branch; |
| 1306 |
} |
| 1307 |
|
| 1251 |
=head2 GetBestRecordMatch |
1308 |
=head2 GetBestRecordMatch |
| 1252 |
|
1309 |
|
| 1253 |
my $record_id = GetBestRecordMatch($import_record_id); |
1310 |
my $record_id = GetBestRecordMatch($import_record_id); |