View | Details | Raw Unified | Return to bug 2060
Collapse All | Expand All

(-)a/C4/AuthoritiesMarc.pm (-10 / +12 lines)
Lines 207-222 sub SearchAuthorities { Link Here
207
            # also store main entry MARC tag, to extract it at end of search
207
            # also store main entry MARC tag, to extract it at end of search
208
        my $mainentrytag;
208
        my $mainentrytag;
209
        ##first set the authtype search and may be multiple authorities
209
        ##first set the authtype search and may be multiple authorities
210
        my $n=0;
210
        if ($authtypecode) {
211
        my @authtypecode;
211
            my $n=0;
212
        my @auths=split / /,$authtypecode ;
212
            my @authtypecode;
213
        foreach my  $auth (@auths){
213
            my @auths=split / /,$authtypecode ;
214
            $query .=" \@attr 1=authtype \@attr 5=100 ".$auth; ##No truncation on authtype
214
            foreach my  $auth (@auths){
215
            push @authtypecode ,$auth;
215
                $query .=" \@attr 1=authtype \@attr 5=100 ".$auth; ##No truncation on authtype
216
            $n++;
216
                    push @authtypecode ,$auth;
217
        }
217
                $n++;
218
        if ($n>1){
218
            }
219
            while ($n>1){$query= "\@or ".$query;$n--;}
219
            if ($n>1){
220
                while ($n>1){$query= "\@or ".$query;$n--;}
221
            }
220
        }
222
        }
221
        
223
        
222
        my $dosearch;
224
        my $dosearch;
(-)a/C4/Context.pm (-1 / +1 lines)
Lines 1009-1015 set_userenv is called in Auth.pm Link Here
1009
#'
1009
#'
1010
sub set_userenv {
1010
sub set_userenv {
1011
    my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_;
1011
    my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress, $branchprinter)= @_;
1012
    my $var=$context->{"activeuser"};
1012
    my $var=$context->{"activeuser"} || '';
1013
    my $cell = {
1013
    my $cell = {
1014
        "number"     => $usernum,
1014
        "number"     => $usernum,
1015
        "id"         => $userid,
1015
        "id"         => $userid,
(-)a/C4/ImportBatch.pm (-8 / +8 lines)
Lines 205-211 sub AddImportBatch { Link Here
205
    my (@fields, @vals);
205
    my (@fields, @vals);
206
    foreach (qw( matcher_id template_id branchcode
206
    foreach (qw( matcher_id template_id branchcode
207
                 overlay_action nomatch_action item_action
207
                 overlay_action nomatch_action item_action
208
                 import_status batch_type file_name comments )) {
208
                 import_status batch_type file_name comments record_type )) {
209
        if (exists $params->{$_}) {
209
        if (exists $params->{$_}) {
210
            push @fields, $_;
210
            push @fields, $_;
211
            push @vals, $params->{$_};
211
            push @vals, $params->{$_};
Lines 328-334 sub BatchStageMarcRecords { Link Here
328
    my $branch_code = shift;
328
    my $branch_code = shift;
329
    my $parse_items = shift;
329
    my $parse_items = shift;
330
    my $leave_as_staging = shift;
330
    my $leave_as_staging = shift;
331
   
331
332
    # optional callback to monitor status 
332
    # optional callback to monitor status 
333
    # of job
333
    # of job
334
    my $progress_interval = 0;
334
    my $progress_interval = 0;
Lines 346-351 sub BatchStageMarcRecords { Link Here
346
            batch_type => 'batch',
346
            batch_type => 'batch',
347
            file_name => $file_name,
347
            file_name => $file_name,
348
            comments => $comments,
348
            comments => $comments,
349
            record_type => $record_type,
349
        } );
350
        } );
350
    if ($parse_items) {
351
    if ($parse_items) {
351
        SetImportBatchItemAction($batch_id, 'always_add');
352
        SetImportBatchItemAction($batch_id, 'always_add');
Lines 584-590 sub BatchCommitRecords { Link Here
584
                    $num_items_errored += $bib_items_errored;
585
                    $num_items_errored += $bib_items_errored;
585
                }
586
                }
586
            } else {
587
            } else {
587
                my $authid = AddAuthority($marc_record, undef, GuessAuthTypeCode($marc_record));
588
                $recordid = AddAuthority($marc_record, undef, GuessAuthTypeCode($marc_record));
588
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
589
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
589
            }
590
            }
590
            my $sth = $dbh->prepare_cached($query);
591
            my $sth = $dbh->prepare_cached($query);
Lines 616-622 sub BatchCommitRecords { Link Here
616
                    $num_items_errored += $bib_items_errored;
617
                    $num_items_errored += $bib_items_errored;
617
                }
618
                }
618
            } else {
619
            } else {
619
                my $oldxml = GetAuthorityXML($recordid);
620
                $oldxml = GetAuthorityXML($recordid);
620
621
621
                ModAuthority($recordid, $marc_record, GuessAuthTypeCode($marc_record));
622
                ModAuthority($recordid, $marc_record, GuessAuthTypeCode($marc_record));
622
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
623
                $query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?";
Lines 1350-1358 sub _add_auth_fields { Link Here
1350
    if ($marc_record->field('001')) {
1351
    if ($marc_record->field('001')) {
1351
        $controlnumber = $marc_record->field('001')->data();
1352
        $controlnumber = $marc_record->field('001')->data();
1352
    }
1353
    }
1353
    my $authorized_heading = GetAuthorizedHeading($marc_record);
1354
    my $authorized_heading = GetAuthorizedHeading({ record => $marc_record });
1354
    my $dbh = C4::Context->dbh;
1355
    my $dbh = C4::Context->dbh;
1355
    my $sth = $dbh->prepare("INSERT INTO import_auths (import_record_id, controlnumber, authorized_heading) VALUES (?, ?, ?)");
1356
    my $sth = $dbh->prepare("INSERT INTO import_auths (import_record_id, control_number, authorized_heading) VALUES (?, ?, ?)");
1356
    $sth->execute($import_record_id, $controlnumber, $authorized_heading);
1357
    $sth->execute($import_record_id, $controlnumber, $authorized_heading);
1357
    $sth->finish();
1358
    $sth->finish();
1358
}
1359
}
Lines 1403-1410 sub _update_batch_record_counts { Link Here
1403
                                        num_records = (
1404
                                        num_records = (
1404
                                            SELECT COUNT(*)
1405
                                            SELECT COUNT(*)
1405
                                            FROM import_records
1406
                                            FROM import_records
1406
                                            WHERE import_batch_id = import_batches.import_batch_id
1407
                                            WHERE import_batch_id = import_batches.import_batch_id),
1407
                                            AND record_type = 'biblio'),
1408
                                        num_items = (
1408
                                        num_items = (
1409
                                            SELECT COUNT(*)
1409
                                            SELECT COUNT(*)
1410
                                            FROM import_records
1410
                                            FROM import_records
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 924-930 CREATE TABLE `import_auths` ( Link Here
924
  `original_source` varchar(25) default NULL,
924
  `original_source` varchar(25) default NULL,
925
  CONSTRAINT `import_auths_ibfk_1` FOREIGN KEY (`import_record_id`)
925
  CONSTRAINT `import_auths_ibfk_1` FOREIGN KEY (`import_record_id`)
926
             REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
926
             REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
927
  KEY `matched_authid` (`matched_authid`),
927
  KEY `matched_authid` (`matched_authid`)
928
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
928
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
929
929
930
--
930
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (-18 / +35 lines)
Lines 1-3 Link Here
1
[% BLOCK final_match_link %]
2
    [% IF ( record.record_type == 'biblio' ) %]
3
        <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.final_match_id %]">[% record.final_match_id %]</a>
4
    [% ELSIF ( record.record_type == 'auth' ) %]
5
        <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% record.final_match_id %]">[% record.final_match_id %]</a>
6
    [% END %]
7
[% END %]
8
[% BLOCK match_link %]
9
    [% IF ( record_lis.match_id ) %]
10
        <tr>
11
            <td />
12
            [% IF ( record.record_type == 'biblio' ) %]
13
                <td class="highlight" colspan="4">Matches biblio [% record_lis.match_id %] (score = [% record_lis.match_score %]): <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record_lis.match_id %]">[% record_lis.match_citation %]</a></td>
14
            [% ELSIF ( record.record_type == 'auth' ) %]
15
                <td class="highlight" colspan="4">Matches authority [% record_lis.match_id %] (score = [% record_lis.match_score %]): <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% record_lis.match_id %]">[% record_lis.match_citation %]</a></td>
16
            [% END %]
17
        </tr>
18
    [% END %]
19
[% END %]
1
[% INCLUDE 'doc-head-open.inc' %]
20
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Manage staged MARC records
21
<title>Koha &rsaquo; Tools &rsaquo; Manage staged MARC records
3
[% IF ( import_batch_id ) %]
22
[% IF ( import_batch_id ) %]
Lines 107-113 $(document).ready(function(){ Link Here
107
<fieldset class="rows" id="staged-record-matching-rules">
126
<fieldset class="rows" id="staged-record-matching-rules">
108
  <ol>
127
  <ol>
109
    <li><span class="label">File name:</span> [% file_name %]</li>
128
    <li><span class="label">File name:</span> [% file_name %]</li>
110
    <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments %](none)[% END %]</li>
129
    <li><span class="label">Comments:</span> [% IF ( comments ) %][% comments %][% ELSE %](none)[% END %]</li>
130
    <li><span class="label">Type:</span> [% IF ( record_type == 'auth' ) %]Authority records[% ELSE %]Bibliographic records[% END %]</li>
111
    <li><span class="label">Staged:</span> [% upload_timestamp %]</li>
131
    <li><span class="label">Staged:</span> [% upload_timestamp %]</li>
112
    <li><span class="label">Status:</span> [% import_status %]</li>
132
    <li><span class="label">Status:</span> [% import_status %]</li>
113
    <li> 
133
    <li> 
Lines 218-226 Page Link Here
218
    <th>#</th>
238
    <th>#</th>
219
    <th>File name</th>
239
    <th>File name</th>
220
    <th>Comments</th>
240
    <th>Comments</th>
241
    <th>Type</th>
221
    <th>Status</th>
242
    <th>Status</th>
222
    <th>Staged</th>
243
    <th>Staged</th>
223
    <th># Bibs</th>
244
    <th># Records</th>
224
    <th># Items</th>
245
    <th># Items</th>
225
    <th>Action</th>
246
    <th>Action</th>
226
  </tr>
247
  </tr>
Lines 229-237 Page Link Here
229
    <td>[% batch_lis.import_batch_id %]</td>
250
    <td>[% batch_lis.import_batch_id %]</td>
230
    <td><a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]">[% batch_lis.file_name %]</a></td>
251
    <td><a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]">[% batch_lis.file_name %]</a></td>
231
    <td>[% batch_lis.comments %]</td>
252
    <td>[% batch_lis.comments %]</td>
253
    <td>[% IF ( batch_lis.record_type == 'auth' ) %]Authority[% ELSE %]Bibliographic[% END %]</td>
232
    <td>[% batch_lis.import_status %]</td>
254
    <td>[% batch_lis.import_status %]</td>
233
    <td>[% batch_lis.upload_timestamp %]</td>
255
    <td>[% batch_lis.upload_timestamp %]</td>
234
    <td>[% batch_lis.num_biblios %]</td>
256
    <td>[% batch_lis.num_records %]</td>
235
    <td>[% batch_lis.num_items %][% IF ( batch_lis.num_items ) %] <a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]&amp;op=create_labels">(Create label batch)</a>[% END %]</td>
257
    <td>[% batch_lis.num_items %][% IF ( batch_lis.num_items ) %] <a href="[% batch_lis.script_name %]?import_batch_id=[% batch_lis.import_batch_id %]&amp;op=create_labels">(Create label batch)</a>[% END %]</td>
236
    <td>[% IF ( batch_lis.can_clean ) %]
258
    <td>[% IF ( batch_lis.can_clean ) %]
237
          <form method="post" action="[% batch_lis.script_name %]" name="clean_batch_[% batch_lis.import_batch_id %]" id="clean_batch_[% batch_lis.import_batch_id %]" >
259
          <form method="post" action="[% batch_lis.script_name %]" name="clean_batch_[% batch_lis.import_batch_id %]" id="clean_batch_[% batch_lis.import_batch_id %]" >
Lines 258-264 Page Link Here
258
  [% END %]
280
  [% END %]
259
[% END %]
281
[% END %]
260
282
261
[% IF ( biblio_list ) %]
283
[% IF ( record_list ) %]
262
  [% IF ( pages ) %]
284
  [% IF ( pages ) %]
263
<div class="pages">
285
<div class="pages">
264
Page 
286
Page 
Lines 277-302 Page Link Here
277
    <th>Citation</th>
299
    <th>Citation</th>
278
    <th>Status</th>
300
    <th>Status</th>
279
    <th>Match?</th>
301
    <th>Match?</th>
280
    <th>Bib</th>
302
    <th>Record</th>
281
303
282
  </tr>
304
  </tr>
283
  [% FOREACH biblio_lis IN biblio_list %]
305
  [% FOREACH record_lis IN record_list %]
284
  [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
306
  [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
285
    <td>[% biblio_lis.record_sequence %]</td>
307
    <td>[% record_lis.record_sequence %]</td>
286
    <td><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% biblio_lis.import_record_id %]" rel="gb_page_center[600,500]">[% biblio_lis.citation %]</a></td>
308
    <td><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% record_lis.import_record_id %]" rel="gb_page_center[600,500]">[% record_lis.citation %]</a></td>
287
    <td>[% biblio_lis.status %]</td>
309
    <td>[% record_lis.status %]</td>
288
    <td>[% biblio_lis.overlay_status %]</td>
310
    <td>[% record_lis.overlay_status %]</td>
289
    <td>[% IF ( biblio_lis.final_match_biblionumber ) %]
311
    <td>[% IF ( record_lis.final_match_id ) %]
290
        <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio_lis.final_match_biblionumber %]">[% biblio_lis.final_match_biblionumber %]</a>
312
        [% PROCESS final_match_link record=record_lis %]
291
        [% END %]
313
        [% END %]
292
    </td>
314
    </td>
293
  </tr>
315
  </tr>
294
    [% IF ( biblio_lis.match_biblionumber ) %]
316
    [% PROCESS match_link record=record_lis %]
295
    <tr>
296
      <td />
297
      <td class="highlight" colspan="4">Matches biblio [% biblio_lis.match_biblionumber %] (score = [% biblio_lis.match_score %]): <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio_lis.match_biblionumber %]">[% biblio_lis.match_citation %]</a></td>
298
    </tr>
299
    [% END %]
300
  [% END %]
317
  [% END %]
301
</table>
318
</table>
302
  [% IF ( pages ) %]
319
  [% IF ( pages ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (-4 / +24 lines)
Lines 11-16 Link Here
11
//<![CDATA[
11
//<![CDATA[
12
$(document).ready(function(){
12
$(document).ready(function(){
13
	$("#processfile").hide();
13
	$("#processfile").hide();
14
    $("#record_type").change(function() {
15
        if ($(this).val() == 'auth') {
16
            $('#items').hide();
17
        } else {
18
            $('#items').show();
19
        }
20
    });
14
});
21
});
15
function CheckForm(f) {
22
function CheckForm(f) {
16
    if ($("#fileToUpload").value == '') {
23
    if ($("#fileToUpload").value == '') {
Lines 40-45 function CheckForm(f) { Link Here
40
[% IF ( uploadmarc ) %]
47
[% IF ( uploadmarc ) %]
41
<p>MARC staging results :</p>
48
<p>MARC staging results :</p>
42
<ul>
49
<ul>
50
    [% SWITCH (record_type) %]
51
    [% CASE 'biblio' %]
52
        <li>Processing bibliographic records</li>
53
    [% CASE 'auth' %]
54
        <li>Processing authority records</li>
55
    [% END %]
43
	<li>[% total %]  records in file</li>
56
	<li>[% total %]  records in file</li>
44
	<li>[% import_errors %] records not staged because of MARC error</li>
57
	<li>[% import_errors %] records not staged because of MARC error</li>
45
	<li>[% staged %] records staged</li>
58
	<li>[% staged %] records staged</li>
Lines 62-69 function CheckForm(f) { Link Here
62
</ul>
75
</ul>
63
[% ELSE %]
76
[% ELSE %]
64
<ul>
77
<ul>
65
	<li>Select a MARC file to stage in the import reservoir.  It will be parsed, and each valid record staged for later import into the catalog.</li>
78
    <li>Select a MARC file to stage in the import reservoir.  It will be parsed, and each valid record staged for later import into the catalog.</li>
66
	<li>You can enter a name for this import. It may be useful, when creating a biblio, to remember where the suggested MARC data comes from!</li>
79
    <li>You can enter a name for this import. It may be useful, when creating a record, to remember where the suggested MARC data comes from!</li>
67
</ul>
80
</ul>
68
<form method="post" action="[% SCRIPT_NAME %]" id="uploadfile" enctype="multipart/form-data">
81
<form method="post" action="[% SCRIPT_NAME %]" id="uploadfile" enctype="multipart/form-data">
69
<fieldset class="rows" id="uploadform">
82
<fieldset class="rows" id="uploadform">
Lines 92-97 function CheckForm(f) { Link Here
92
		<input type="text" id="comments" name="comments" />
105
		<input type="text" id="comments" name="comments" />
93
		
106
		
94
	</li>
107
	</li>
108
    <li>
109
        <label for='record_type'>Record type:</label>
110
        <select name='record_type' id='record_type'>
111
            <option value='biblio' selected='selected'>Bibliographic</option>
112
            <option value='auth'>Authority</option>
113
        </select>
114
    </li>
95
	<li>
115
	<li>
96
		<label for="encoding">Character encoding: </label>
116
		<label for="encoding">Character encoding: </label>
97
            <select name="encoding" id="encoding"><option value="utf8" selected="selected">UTF-8 (Default)</option><option value="MARC-8">MARC 8</option><option value="ISO_5426">ISO 5426</option><option value="ISO_6937">ISO 6937</option><option value=ISO_8859-1">ISO 8859-1</option><option value="EUC-KR">EUC-KR</option></select>
117
            <select name="encoding" id="encoding"><option value="utf8" selected="selected">UTF-8 (Default)</option><option value="MARC-8">MARC 8</option><option value="ISO_5426">ISO 5426</option><option value="ISO_6937">ISO 6937</option><option value=ISO_8859-1">ISO 8859-1</option><option value="EUC-KR">EUC-KR</option></select>
Lines 108-114 function CheckForm(f) { Link Here
108
       [% END %]
128
       [% END %]
109
    </select>
129
    </select>
110
    </li>
130
    </li>
111
      <li><label for="overlay_action">Action if matching bibliographic record found: </label>
131
      <li><label for="overlay_action">Action if matching record found: </label>
112
           [% INCLUDE 'tools-overlay-action.inc' %]
132
           [% INCLUDE 'tools-overlay-action.inc' %]
113
      </li>
133
      </li>
114
      <li><label for="nomatch_action">Action if no match is found: </label>
134
      <li><label for="nomatch_action">Action if no match is found: </label>
Lines 116-122 function CheckForm(f) { Link Here
116
      </li>
136
      </li>
117
    </ol>
137
    </ol>
118
  </fieldset>
138
  </fieldset>
119
  <fieldset class="rows">
139
  <fieldset class="rows" id="items">
120
    <legend>Check for embedded item record data?</legend>
140
    <legend>Check for embedded item record data?</legend>
121
    <ol>
141
    <ol>
122
      <li class="radio">
142
      <li class="radio">
(-)a/misc/commit_biblios_file.pl (-12 / +44 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use strict;
3
use strict;
4
#use warnings; FIXME - Bug 2505
4
use warnings;
5
BEGIN {
5
BEGIN {
6
    # find Koha's Perl modules
6
    # find Koha's Perl modules
7
    # test carefully before changing this
7
    # test carefully before changing this
Lines 18-28 $| = 1; Link Here
18
# command-line parameters
18
# command-line parameters
19
my $batch_number = "";
19
my $batch_number = "";
20
my $list_batches = 0;
20
my $list_batches = 0;
21
my $revert = 0;
21
my $want_help = 0;
22
my $want_help = 0;
22
23
23
my $result = GetOptions(
24
my $result = GetOptions(
24
    'batch-number:s' => \$batch_number,
25
    'batch-number:s' => \$batch_number,
25
    'list-batches'   => \$list_batches,
26
    'list-batches'   => \$list_batches,
27
    'revert'         => \$revert,
26
    'h|help'         => \$want_help
28
    'h|help'         => \$want_help
27
);
29
);
28
30
Lines 45-53 $dbh->{AutoCommit} = 0; Link Here
45
if ($batch_number =~ /^\d+$/ and $batch_number > 0) {
47
if ($batch_number =~ /^\d+$/ and $batch_number > 0) {
46
    my $batch = GetImportBatch($batch_number);
48
    my $batch = GetImportBatch($batch_number);
47
    die "$0: import batch $batch_number does not exist in database\n" unless defined $batch;
49
    die "$0: import batch $batch_number does not exist in database\n" unless defined $batch;
48
    die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
50
    if ($revert) {
49
        unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted";
51
        die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
50
    process_batch($batch_number);
52
            unless $batch->{'import_status'} eq "imported";
53
        revert_batch($batch_number);
54
    } else {
55
        die "$0: import batch $batch_number status is '" . $batch->{'import_status'} . "', and therefore cannot be imported\n"
56
            unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted";
57
        process_batch($batch_number);
58
    }
51
    $dbh->commit();
59
    $dbh->commit();
52
} else {
60
} else {
53
    die "$0: please specify a numeric batch ID\n";
61
    die "$0: please specify a numeric batch ID\n";
Lines 74-81 sub process_batch { Link Here
74
    my ($import_batch_id) = @_;
82
    my ($import_batch_id) = @_;
75
83
76
    print "... importing MARC records -- please wait\n";
84
    print "... importing MARC records -- please wait\n";
77
    my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) = 
85
    my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) =
78
        BatchCommitBibRecords($import_batch_id, '', 100, \&print_progress_and_commit);
86
        BatchCommitRecords($import_batch_id, '', 100, \&print_progress_and_commit);
79
    print "... finished importing MARC records\n";
87
    print "... finished importing MARC records\n";
80
88
81
    print <<_SUMMARY_;
89
    print <<_SUMMARY_;
Lines 83-99 sub process_batch { Link Here
83
MARC record import report
91
MARC record import report
84
----------------------------------------
92
----------------------------------------
85
Batch number:                    $import_batch_id
93
Batch number:                    $import_batch_id
86
Number of new bibs added:        $num_added
94
Number of new records added:     $num_added
87
Number of bibs replaced:         $num_updated
95
Number of records replaced:      $num_updated
88
Number of bibs ignored:          $num_ignored
96
Number of records ignored:       $num_ignored
89
Number of items added:           $num_items_added
97
Number of items added:           $num_items_added
90
Number of items ignored:         $num_items_errored
98
Number of items ignored:         $num_items_errored
91
99
92
Note: an item is ignored if its barcode is a 
100
Note: an item is ignored if its barcode is a
93
duplicate of one already in the database.
101
duplicate of one already in the database.
94
_SUMMARY_
102
_SUMMARY_
95
}
103
}
96
104
105
sub revert_batch {
106
    my ($import_batch_id) = @_;
107
108
    print "... reverting batch -- please wait\n";
109
    my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored) =
110
        BatchRevertRecords($import_batch_id, 100, \&print_progress_and_commit);
111
    print "... finished reverting batch\n";
112
113
    print <<_SUMMARY_;
114
115
MARC record import report
116
----------------------------------------
117
Batch number:                    $import_batch_id
118
Number of records deleted:       $num_deleted
119
Number of errors:                $num_errors
120
Number of records reverted:      $num_reverted
121
Number of records ignored:       $num_ignored
122
Number of items added:           $num_items_deleted
123
124
_SUMMARY_
125
}
126
127
97
sub print_progress_and_commit {
128
sub print_progress_and_commit {
98
    my $recs = shift;
129
    my $recs = shift;
99
    print "... processed $recs records\n";
130
    print "... processed $recs records\n";
Lines 106-112 $0: import a batch of staged MARC records into database. Link Here
106
137
107
Use this batch job to complete the import of a batch of
138
Use this batch job to complete the import of a batch of
108
MARC records that was staged either by the batch job
139
MARC records that was staged either by the batch job
109
stage_biblios_file.pl or by the Koha Tools option
140
stage_file.pl or by the Koha Tools option
110
"Stage MARC Records for Import".
141
"Stage MARC Records for Import".
111
142
112
Parameters:
143
Parameters:
Lines 114-119 Parameters: Link Here
114
                         to import
145
                         to import
115
    --list-batches       print a list of record batches
146
    --list-batches       print a list of record batches
116
                         available to commit
147
                         available to commit
117
    --help or -h            show this message.
148
    --revert             revert a batch instead of importing it
149
    --help or -h         show this message.
118
_USAGE_
150
_USAGE_
119
}
151
}
(-)a/misc/stage_biblios_file.pl (-36 / +48 lines)
Lines 4-9 Link Here
4
#
4
#
5
# Copyright (C) 2007 LibLime
5
# Copyright (C) 2007 LibLime
6
# Parts Copyright BSZ 2011
6
# Parts Copyright BSZ 2011
7
# Parts Copyright C & P Bibliography Services 2012
7
#
8
#
8
# Koha is free software; you can redistribute it and/or modify it under the
9
# Koha is free software; you can redistribute it and/or modify it under the
9
# terms of the GNU General Public License as published by the Free Software
10
# terms of the GNU General Public License as published by the Free Software
Lines 35-42 use Getopt::Long; Link Here
35
$| = 1;
36
$| = 1;
36
37
37
# command-line parameters
38
# command-line parameters
39
my $record_type = "biblio";
38
my $encoding = "";
40
my $encoding = "";
39
my $match_bibs = 0;
41
my $authorities = 0;
42
my $match = 0;
40
my $add_items = 0;
43
my $add_items = 0;
41
my $input_file = "";
44
my $input_file = "";
42
my $batch_comment = "";
45
my $batch_comment = "";
Lines 46-58 my $no_replace ; Link Here
46
my $result = GetOptions(
49
my $result = GetOptions(
47
    'encoding:s'    => \$encoding,
50
    'encoding:s'    => \$encoding,
48
    'file:s'        => \$input_file,
51
    'file:s'        => \$input_file,
49
    'match-bibs:s'  => \$match_bibs,
52
    'match|match-bibs:s'  => \$match,
50
    'add-items'     => \$add_items,
53
    'add-items'     => \$add_items,
51
    'no-replace'    => \$no_replace,
54
    'no-replace'    => \$no_replace,
52
    'comment:s'     => \$batch_comment,
55
    'comment:s'     => \$batch_comment,
56
    'authorities'   => \$authorities,
53
    'h|help'        => \$want_help
57
    'h|help'        => \$want_help
54
);
58
);
55
59
60
$record_type = 'auth' if ($authorities);
61
56
if ($encoding eq "") {
62
if ($encoding eq "") {
57
    $encoding = "utf8";
63
    $encoding = "utf8";
58
}
64
}
Lines 68-80 unless (-r $input_file) { Link Here
68
74
69
my $dbh = C4::Context->dbh;
75
my $dbh = C4::Context->dbh;
70
$dbh->{AutoCommit} = 0;
76
$dbh->{AutoCommit} = 0;
71
process_batch($input_file, $match_bibs, $add_items, $batch_comment);
77
process_batch($input_file, $record_type, $match, $add_items, $batch_comment);
72
$dbh->commit();
78
$dbh->commit();
73
79
74
exit 0;
80
exit 0;
75
81
76
sub process_batch {
82
sub process_batch {
77
    my ($input_file, $match_bibs, $add_items, $batch_comment) = @_;
83
    my ($input_file, $record_type, $match, $add_items, $batch_comment) = @_;
78
84
79
    open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
85
    open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
80
    my $marc_records = "";
86
    my $marc_records = "";
Lines 92-141 sub process_batch { Link Here
92
    close IN;
98
    close IN;
93
99
94
    print "... staging MARC records -- please wait\n";
100
    print "... staging MARC records -- please wait\n";
95
    my ($batch_id, $num_valid, $num_items, @import_errors) = 
101
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
96
        BatchStageMarcRecords($encoding, $marc_records, $input_file, $batch_comment, '', $add_items, 0,
102
        BatchStageMarcRecords($record_type, $encoding, $marc_records, $input_file, $batch_comment, '', $add_items, 0,
97
                              100, \&print_progress_and_commit);
103
                              100, \&print_progress_and_commit);
98
    print "... finished staging MARC records\n";
104
    print "... finished staging MARC records\n";
99
105
100
    my $num_with_matches = 0;
106
    my $num_with_matches = 0;
101
    if ($match_bibs) {
107
    if ($match) {
102
        my $matcher = C4::Matcher->fetch($match_bibs) ;
108
        my $matcher = C4::Matcher->fetch($match) ;
103
        if (! defined $matcher) {
109
        if (defined $matcher) {
104
            $matcher = C4::Matcher->new('biblio');
110
            SetImportBatchMatcher($batch_id, $match);
111
        } elsif ($record_type eq 'biblio')  {
112
            $matcher = C4::Matcher->new($record_type);
105
            $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
113
            $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
106
            $matcher->add_simple_required_check('245', 'a', -1, 0, '', 
114
            $matcher->add_simple_required_check('245', 'a', -1, 0, '',
107
                                            '245', 'a', -1, 0, '');
115
                                            '245', 'a', -1, 0, '');
108
        } else {
109
            SetImportBatchMatcher($batch_id, $match_bibs);
110
        }
116
        }
111
        # set default record overlay behavior
117
        # set default record overlay behavior
112
        SetImportBatchOverlayAction($batch_id, ($no_replace) ? 'ignore' : 'replace');
118
        SetImportBatchOverlayAction($batch_id, ($no_replace) ? 'ignore' : 'replace');
113
        SetImportBatchNoMatchAction($batch_id, 'create_new');
119
        SetImportBatchNoMatchAction($batch_id, 'create_new');
114
        SetImportBatchItemAction($batch_id, 'always_add');
120
        SetImportBatchItemAction($batch_id, 'always_add');
115
        print "... looking for matches with records already in database\n";
121
        print "... looking for matches with records already in database\n";
116
        $num_with_matches = BatchFindBibDuplicates($batch_id, $matcher, 10, 100, \&print_progress_and_commit);
122
        $num_with_matches = BatchFindDuplicates($batch_id, $matcher, 10, 100, \&print_progress_and_commit);
117
        print "... finished looking for matches\n";
123
        print "... finished looking for matches\n";
118
    }
124
    }
119
125
120
    my $num_invalid_bibs = scalar(@import_errors);
126
    my $num_invalid_records = scalar(@import_errors);
121
    print <<_SUMMARY_;
127
    print <<_SUMMARY_;
122
128
123
MARC record staging report
129
MARC record staging report
124
------------------------------------
130
------------------------------------
125
Input file:              $input_file
131
Input file:                 $input_file
126
Number of input bibs:    $num_input_records
132
Record type:                $record_type
127
Number of valid bibs:    $num_valid
133
Number of input records:    $num_input_records
128
Number of invalid bibs:  $num_invalid_bibs
134
Number of valid records:    $num_valid_records
135
Number of invalid records:  $num_invalid_records
129
_SUMMARY_
136
_SUMMARY_
130
    if ($match_bibs) {
137
    if ($match) {
131
        print "Number of bibs matched:  $num_with_matches\n";
138
        print "Number of records matched:  $num_with_matches\n";
132
    } else {
139
    } else {
133
        print "Incoming bibs not matched against existing bibs (--match-bibs option not supplied)\n";
140
        print "Incoming records not matched against existing records (--match option not supplied)\n";
134
    }
141
    }
135
    if ($add_items) {
142
    if ($record_type eq 'biblio') {
136
        print "Number of items parsed:  $num_items\n";
143
        if ($add_items) {
137
    } else {
144
            print "Number of items parsed:  $num_items\n";
138
        print "No items parsed (--add-items option not supplied)\n";
145
        } else {
146
            print "No items parsed (--add-items option not supplied)\n";
147
        }
139
    }
148
    }
140
149
141
    print "\n";
150
    print "\n";
Lines 151-181 sub print_progress_and_commit { Link Here
151
160
152
sub print_usage {
161
sub print_usage {
153
    print <<_USAGE_;
162
    print <<_USAGE_;
154
$0: stage MARC bib file into reservoir.
163
$0: stage MARC file into reservoir.
155
164
156
Use this batch job to load a file of MARC bibliographic records
165
Use this batch job to load a file of MARC bibliographic
157
(with optional item information) into the Koha reservoir.
166
(with optional item information) or authority records into
167
the Koha reservoir.
158
168
159
After running this program to stage your file, you can use
169
After running this program to stage your file, you can use
160
either the batch job commit_biblios_file.pl or the Koha
170
either the batch job commit_file.pl or the Koha
161
Tools option "Manage Staged MARC Records" to load the
171
Tools option "Manage Staged MARC Records" to load the
162
records into the main Koha database.
172
records into the main Koha database.
163
173
164
Parameters:
174
Parameters:
165
    --file <file_name>      name of input MARC bib file
175
    --file <file_name>      name of input MARC bib file
176
    --authorities           stage authority records instead of bibs
166
    --encoding <encoding>   encoding of MARC records, default is utf8.
177
    --encoding <encoding>   encoding of MARC records, default is utf8.
167
                            Other possible options are: MARC-8,
178
                            Other possible options are: MARC-8,
168
                            ISO_5426, ISO_6937, ISO_8859-1, EUC-KR
179
                            ISO_5426, ISO_6937, ISO_8859-1, EUC-KR
169
    --match-bibs <match_id> use this option to match bibs
180
    --match <match_id>      use this option to match records
170
                            in the file with bibs already in 
181
                            in the file with records already in
171
                            the database for future overlay.
182
                            the database for future overlay.
172
                            If <match_id> isn't defined, a default 
183
                            If <match_id> isn't defined, a default
173
                            MARC21 ISBN & title match rule will be applied.
184
                            MARC21 ISBN & title match rule will be applied
185
                            for bib imports.
174
    --add-items             use this option to specify that
186
    --add-items             use this option to specify that
175
                            item data is embedded in the MARC
187
                            item data is embedded in the MARC
176
                            bibs and should be parsed.
188
                            bibs and should be parsed.
177
    --no-replace            overlay action for bib record: default is to 
189
    --no-replace            overlay action for record: default is to
178
                            replace extant bib with the imported record.
190
                            replace extant with the imported record.
179
    --comment <comment>     optional comment to describe
191
    --comment <comment>     optional comment to describe
180
                            the record batch; if the comment
192
                            the record batch; if the comment
181
                            has spaces in it, surround the
193
                            has spaces in it, surround the
(-)a/tools/manage-marc-import.pl (+1 lines)
Lines 29-34 use MARC::File::USMARC; Link Here
29
use C4::Context;
29
use C4::Context;
30
use C4::Koha;
30
use C4::Koha;
31
use C4::Auth;
31
use C4::Auth;
32
use C4::AuthoritiesMarc;
32
use C4::Output;
33
use C4::Output;
33
use C4::Biblio;
34
use C4::Biblio;
34
use C4::ImportBatch;
35
use C4::ImportBatch;
(-)a/tools/stage-marc-import.pl (-2 / +2 lines)
Lines 55-60 my $nomatch_action = $input->param('nomatch_action'); Link Here
55
my $parse_items = $input->param('parse_items');
55
my $parse_items = $input->param('parse_items');
56
my $item_action = $input->param('item_action');
56
my $item_action = $input->param('item_action');
57
my $comments = $input->param('comments');
57
my $comments = $input->param('comments');
58
my $record_type = $input->param('record_type');
58
my $encoding = $input->param('encoding');
59
my $encoding = $input->param('encoding');
59
my ($template, $loggedinuser, $cookie)
60
my ($template, $loggedinuser, $cookie)
60
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
61
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
Lines 115-121 if ($completedJobID) { Link Here
115
            # close STDOUT to signal to Apache that
116
            # close STDOUT to signal to Apache that
116
            # we're now running in the background
117
            # we're now running in the background
117
            close STDOUT;
118
            close STDOUT;
118
            close STDERR;
119
            # close STDERR; # there is no good reason to close STDERR
119
        } else {
120
        } else {
120
            # fork failed, so exit immediately
121
            # fork failed, so exit immediately
121
            warn "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job";
122
            warn "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job";
122
- 

Return to bug 2060