Lines 42-47
use Koha::SearchEngine::Indexer;
Link Here
|
42 |
use Koha::Plugins::Handler; |
42 |
use Koha::Plugins::Handler; |
43 |
use Koha::Logger; |
43 |
use Koha::Logger; |
44 |
use List::MoreUtils qw( uniq any ); |
44 |
use List::MoreUtils qw( uniq any ); |
|
|
45 |
use Array::Utils qw( array_minus ); |
45 |
|
46 |
|
46 |
our ( @ISA, @EXPORT_OK ); |
47 |
our ( @ISA, @EXPORT_OK ); |
47 |
|
48 |
|
Lines 74-79
BEGIN {
Link Here
|
74 |
GetImportRecordsRange |
75 |
GetImportRecordsRange |
75 |
GetItemNumbersFromImportBatch |
76 |
GetItemNumbersFromImportBatch |
76 |
GetImportItemsBranches |
77 |
GetImportItemsBranches |
|
|
78 |
GetBadBranchesImportItems |
77 |
|
79 |
|
78 |
GetImportBatchStatus |
80 |
GetImportBatchStatus |
79 |
SetImportBatchStatus |
81 |
SetImportBatchStatus |
Lines 1304-1309
sub GetImportItemsBranches {
Link Here
|
1304 |
return uniq @branch; |
1306 |
return uniq @branch; |
1305 |
} |
1307 |
} |
1306 |
|
1308 |
|
|
|
1309 |
=head2 GetBadBranchesImportItems |
1310 |
|
1311 |
my @results = GetBadBranchesImportItems($batch_id); |
1312 |
|
1313 |
Returns an array of bad branches imported items. |
1314 |
|
1315 |
=cut |
1316 |
|
1317 |
sub GetBadBranchesImportItems { |
1318 |
my ($batch_id) = @_; |
1319 |
|
1320 |
my $dbh = C4::Context->dbh; |
1321 |
my $query = "SELECT import_items_id, import_record_id, import_items.marcxml, encoding |
1322 |
FROM import_items |
1323 |
JOIN import_records USING (import_record_id) |
1324 |
WHERE import_batch_id = ? |
1325 |
ORDER BY import_items_id"; |
1326 |
my @params; |
1327 |
push( @params, $batch_id ); |
1328 |
my $sth = $dbh->prepare($query); |
1329 |
$sth->execute(@params); |
1330 |
my $results = $sth->fetchall_arrayref( {} ); |
1331 |
my @items; |
1332 |
|
1333 |
my @import_items_branches = GetImportItemsBranches($batch_id); |
1334 |
my @branches = map { $_->branchcode } Koha::Libraries->search->as_list; |
1335 |
my @missing_branches = array_minus( @import_items_branches, @branches ); |
1336 |
my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); |
1337 |
my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); |
1338 |
|
1339 |
foreach my $row (@$results) { |
1340 |
my $item_marc = |
1341 |
MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); |
1342 |
my $title = GetTitleImportRecord( $row->{'import_record_id'} ); |
1343 |
foreach my $branch (@missing_branches) { |
1344 |
if ( $item_marc->subfield( $homebranchfield, $homebranchsubfield ) eq $branch ) { |
1345 |
push @items, { title => $title, branch => $branch }; |
1346 |
} |
1347 |
if ( $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield ) eq $branch ) { |
1348 |
push @items, { title => $title, branch => $branch }; |
1349 |
} |
1350 |
} |
1351 |
} |
1352 |
$sth->finish(); |
1353 |
return uniq @items; |
1354 |
} |
1355 |
|
1356 |
=head2 GetTitleImportRecord |
1357 |
|
1358 |
my $status = GetTitleImportRecord($import_record_id); |
1359 |
|
1360 |
=cut |
1361 |
|
1362 |
sub GetTitleImportRecord { |
1363 |
my ($import_record_id) = @_; |
1364 |
|
1365 |
my $dbh = C4::Context->dbh; |
1366 |
my $sth = $dbh->prepare( |
1367 |
"SELECT import_record_id, import_records.marcxml, encoding |
1368 |
FROM import_records WHERE import_record_id = ?" |
1369 |
); |
1370 |
$sth->execute($import_record_id); |
1371 |
my $record = $sth->fetchall_arrayref( {} ); |
1372 |
my $marc_record = MARC::Record->new_from_xml( |
1373 |
StripNonXmlChars( $record->[0]->{'marcxml'} ), 'UTF-8', |
1374 |
$record->[0]->{'encoding'} |
1375 |
); |
1376 |
$sth->finish(); |
1377 |
my $title = $marc_record->field('245')->subfield('a'); |
1378 |
return $title; |
1379 |
} |
1380 |
|
1307 |
=head2 GetBestRecordMatch |
1381 |
=head2 GetBestRecordMatch |
1308 |
|
1382 |
|
1309 |
my $record_id = GetBestRecordMatch($import_record_id); |
1383 |
my $record_id = GetBestRecordMatch($import_record_id); |