|
Lines 17-25
package C4::ImportBatch;
Link Here
|
| 17 |
# You should have received a copy of the GNU General Public License |
17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
|
|
| 21 |
use base 'Exporter'; |
20 |
use base 'Exporter'; |
| 22 |
|
21 |
|
|
|
22 |
use strict; |
| 23 |
use warnings; |
| 24 |
|
| 25 |
use Modern::Perl; |
| 26 |
|
| 27 |
use C4::Context; |
| 28 |
use C4::Koha qw( GetNormalizedISBN ); |
| 29 |
use C4::Biblio qw( |
| 30 |
AddBiblio |
| 31 |
DelBiblio |
| 32 |
GetMarcFromKohaField |
| 33 |
GetXmlBiblio |
| 34 |
ModBiblio |
| 35 |
TransformMarcToKoha |
| 36 |
); |
| 37 |
use C4::Items qw( AddItemFromMarc ModItemFromMarc ); |
| 38 |
use C4::Charset qw( MarcToUTF8Record SetUTF8Flag StripNonXmlChars ); |
| 39 |
use C4::AuthoritiesMarc |
| 40 |
qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority GetAuthorizedHeading ); |
| 41 |
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate ); |
| 42 |
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; |
| 43 |
use Koha::Items; |
| 44 |
use Koha::SearchEngine; |
| 45 |
use Koha::SearchEngine::Indexer; |
| 46 |
use Koha::Plugins::Handler; |
| 47 |
use Koha::Logger; |
| 48 |
use List::MoreUtils qw( uniq ); |
| 49 |
|
| 50 |
our ( @ISA, @EXPORT_OK ); |
| 51 |
|
| 23 |
BEGIN { |
52 |
BEGIN { |
| 24 |
our @EXPORT_OK = qw( |
53 |
our @EXPORT_OK = qw( |
| 25 |
GetZ3950BatchId |
54 |
GetZ3950BatchId |
|
Lines 46-51
BEGIN {
Link Here
|
| 46 |
GetImportBiblios |
75 |
GetImportBiblios |
| 47 |
GetImportRecordsRange |
76 |
GetImportRecordsRange |
| 48 |
GetItemNumbersFromImportBatch |
77 |
GetItemNumbersFromImportBatch |
|
|
78 |
GetImportItemsBranches |
| 49 |
|
79 |
|
| 50 |
GetImportBatchStatus |
80 |
GetImportBatchStatus |
| 51 |
SetImportBatchStatus |
81 |
SetImportBatchStatus |
|
Lines 839-844
sub _batchCommitItems {
Link Here
|
| 839 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber"); |
869 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber"); |
| 840 |
$item_marc->field($itemtag)->delete_subfield( code => $itemsubfield ); |
870 |
$item_marc->field($itemtag)->delete_subfield( code => $itemsubfield ); |
| 841 |
|
871 |
|
|
|
872 |
my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); |
| 873 |
my $homebranch = $item_marc->subfield( $homebranchfield, $homebranchsubfield ); |
| 874 |
my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); |
| 875 |
my $holdingbranch = $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield ); |
| 876 |
|
| 877 |
my @branches = map { $_->branchcode } Koha::Libraries->search->as_list; |
| 878 |
my %branches = map { $_ => 1 } @branches; |
| 879 |
|
| 880 |
my $missing_branchcode; |
| 881 |
$missing_branchcode = $homebranch if ( !exists( $branches{$homebranch} ) ); |
| 882 |
$missing_branchcode = $holdingbranch if ( !exists( $branches{$holdingbranch} ) ); |
| 883 |
if ($missing_branchcode) { |
| 884 |
$updsth->bind_param( 1, 'error' ); |
| 885 |
$updsth->bind_param( 2, undef ); |
| 886 |
$updsth->bind_param( 3, "Branch code $missing_branchcode missing" ); |
| 887 |
$updsth->bind_param( 4, $row->{'import_items_id'} ); |
| 888 |
$updsth->execute(); |
| 889 |
$num_items_errored++; |
| 890 |
next; |
| 891 |
} |
| 892 |
|
| 842 |
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( |
893 |
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( |
| 843 |
$item_marc, $biblionumber, |
894 |
$item_marc, $biblionumber, |
| 844 |
{ biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } |
895 |
{ biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } |
|
Lines 1250-1255
sub GetImportRecordsRange {
Link Here
|
| 1250 |
|
1301 |
|
| 1251 |
} |
1302 |
} |
| 1252 |
|
1303 |
|
|
|
1304 |
=head2 GetImportItemsBranches |
| 1305 |
|
| 1306 |
my @results = GetImportItemsBranches($batch_id); |
| 1307 |
|
| 1308 |
Returns an array of imported item branches. |
| 1309 |
|
| 1310 |
=cut |
| 1311 |
|
| 1312 |
sub GetImportItemsBranches { |
| 1313 |
my ( $batch_id ) = @_; |
| 1314 |
|
| 1315 |
my $dbh = C4::Context->dbh; |
| 1316 |
my $query = "SELECT import_items_id, import_items.marcxml, encoding |
| 1317 |
FROM import_items |
| 1318 |
JOIN import_records USING (import_record_id) |
| 1319 |
WHERE import_batch_id = ? |
| 1320 |
ORDER BY import_items_id"; |
| 1321 |
my @params; |
| 1322 |
push( @params, $batch_id ); |
| 1323 |
my $sth = $dbh->prepare_cached($query); |
| 1324 |
$sth->execute(@params); |
| 1325 |
my $results = $sth->fetchall_arrayref( {} ); |
| 1326 |
my @branch; |
| 1327 |
my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); |
| 1328 |
my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); |
| 1329 |
foreach my $row (@$results) { |
| 1330 |
my $item_marc = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); |
| 1331 |
push @branch, $item_marc->subfield( $homebranchfield, $homebranchsubfield ); |
| 1332 |
push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield );; |
| 1333 |
} |
| 1334 |
$sth->finish(); |
| 1335 |
return uniq @branch; |
| 1336 |
} |
| 1337 |
|
| 1253 |
=head2 GetBestRecordMatch |
1338 |
=head2 GetBestRecordMatch |
| 1254 |
|
1339 |
|
| 1255 |
my $record_id = GetBestRecordMatch($import_record_id); |
1340 |
my $record_id = GetBestRecordMatch($import_record_id); |