Lines 41-46
use Koha::SearchEngine::Indexer;
Link Here
|
41 |
use Koha::Plugins::Handler; |
41 |
use Koha::Plugins::Handler; |
42 |
use Koha::Logger; |
42 |
use Koha::Logger; |
43 |
use List::MoreUtils qw( uniq any ); |
43 |
use List::MoreUtils qw( uniq any ); |
|
|
44 |
use Array::Utils qw( array_minus ); |
44 |
|
45 |
|
45 |
our (@ISA, @EXPORT_OK); |
46 |
our (@ISA, @EXPORT_OK); |
46 |
BEGIN { |
47 |
BEGIN { |
Lines 72-77
BEGIN {
Link Here
|
72 |
GetImportRecordsRange |
73 |
GetImportRecordsRange |
73 |
GetItemNumbersFromImportBatch |
74 |
GetItemNumbersFromImportBatch |
74 |
GetImportItemsBranches |
75 |
GetImportItemsBranches |
|
|
76 |
GetBadBranchesImportItems |
75 |
|
77 |
|
76 |
GetImportBatchStatus |
78 |
GetImportBatchStatus |
77 |
SetImportBatchStatus |
79 |
SetImportBatchStatus |
Lines 1248-1253
sub GetImportItemsBranches {
Link Here
|
1248 |
return uniq @branch; |
1250 |
return uniq @branch; |
1249 |
} |
1251 |
} |
1250 |
|
1252 |
|
|
|
1253 |
=head2 GetBadBranchesImportItems |
1254 |
|
1255 |
my @results = GetBadBranchesImportItems($batch_id); |
1256 |
|
1257 |
Returns an array of bad branches imported items. |
1258 |
|
1259 |
=cut |
1260 |
|
1261 |
sub GetBadBranchesImportItems { |
1262 |
my ($batch_id) = @_; |
1263 |
|
1264 |
my $dbh = C4::Context->dbh; |
1265 |
my $query = "SELECT import_items_id, import_record_id, import_items.marcxml, encoding |
1266 |
FROM import_items |
1267 |
JOIN import_records USING (import_record_id) |
1268 |
WHERE import_batch_id = ? |
1269 |
ORDER BY import_items_id"; |
1270 |
my @params; |
1271 |
push( @params, $batch_id ); |
1272 |
my $sth = $dbh->prepare($query); |
1273 |
$sth->execute(@params); |
1274 |
my $results = $sth->fetchall_arrayref( {} ); |
1275 |
my @items; |
1276 |
|
1277 |
my @import_items_branches = GetImportItemsBranches($batch_id); |
1278 |
my @branches = map { $_->branchcode } Koha::Libraries->search->as_list; |
1279 |
my @missing_branches = array_minus( @import_items_branches, @branches ); |
1280 |
my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); |
1281 |
my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); |
1282 |
|
1283 |
foreach my $row (@$results) { |
1284 |
my $item_marc = |
1285 |
MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); |
1286 |
my $title = GetTitleImportRecord( $row->{'import_record_id'} ); |
1287 |
foreach my $branch (@missing_branches) { |
1288 |
if ( $item_marc->subfield( $homebranchfield, $homebranchsubfield ) eq $branch ) { |
1289 |
push @items, { title => $title, branch => $branch }; |
1290 |
} |
1291 |
if ( $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield ) eq $branch ) { |
1292 |
push @items, { title => $title, branch => $branch }; |
1293 |
} |
1294 |
} |
1295 |
} |
1296 |
$sth->finish(); |
1297 |
return uniq @items; |
1298 |
} |
1299 |
|
1300 |
=head2 GetTitleImportRecord |
1301 |
|
1302 |
my $status = GetTitleImportRecord($import_record_id); |
1303 |
|
1304 |
=cut |
1305 |
|
1306 |
sub GetTitleImportRecord { |
1307 |
my ($import_record_id) = @_; |
1308 |
|
1309 |
my $dbh = C4::Context->dbh; |
1310 |
my $sth = $dbh->prepare("SELECT import_record_id, import_records.marcxml, encoding |
1311 |
FROM import_records WHERE import_record_id = ?"); |
1312 |
$sth->execute($import_record_id); |
1313 |
my $record = $sth->fetchall_arrayref( {} ); |
1314 |
my $marc_record = |
1315 |
MARC::Record->new_from_xml( StripNonXmlChars( $record->[0]->{'marcxml'} ), 'UTF-8', $record->[0]->{'encoding'} ); |
1316 |
$sth->finish(); |
1317 |
my $title = $marc_record->field('245')->subfield('a'); |
1318 |
return $title; |
1319 |
} |
1320 |
|
1251 |
=head2 GetBestRecordMatch |
1321 |
=head2 GetBestRecordMatch |
1252 |
|
1322 |
|
1253 |
my $record_id = GetBestRecordMatch($import_record_id); |
1323 |
my $record_id = GetBestRecordMatch($import_record_id); |