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

(-)a/C4/Biblio.pm (-6 / +22 lines)
Lines 3240-3245 sub _koha_delete_biblio_metadata { Link Here
3240
3240
3241
=head1 UNEXPORTED FUNCTIONS
3241
=head1 UNEXPORTED FUNCTIONS
3242
3242
3243
=head2 Update005Time
3244
3245
  &Update005Time( $record );
3246
3247
Updates the 005 timestamp of the given record to the current time.
3248
3249
=cut
3250
3251
sub UpdateMarcTimestamp {
3252
    my ( $record ) = @_;
3253
3254
    my $encoding = C4::Context->preference("marcflavour");
3255
3256
    if ( $encoding =~ /MARC21|UNIMARC/ ) {
3257
        my @a = (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3258
        # YY MM DD HH MM SS (update year and month)
3259
        my $f005 = $record->field('005');
3260
        $f005->update( sprintf( "%4d%02d%02d%02d%02d%04.1f",@a ) ) if $f005;
3261
    }
3262
}
3263
3243
=head2 ModBiblioMarc
3264
=head2 ModBiblioMarc
3244
3265
3245
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
3266
  &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);
Lines 3292-3303 sub ModBiblioMarc { Link Here
3292
    }
3313
    }
3293
3314
3294
    #enhancement 5374: update transaction date (005) for marc21/unimarc
3315
    #enhancement 5374: update transaction date (005) for marc21/unimarc
3295
    if($encoding =~ /MARC21|UNIMARC/) {
3316
    UpdateMarcTimestamp( $record );
3296
      my @a= (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3297
        # YY MM DD HH MM SS (update year and month)
3298
      my $f005= $record->field('005');
3299
      $f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005;
3300
    }
3301
3317
3302
    my $metadata = {
3318
    my $metadata = {
3303
        biblionumber => $biblionumber,
3319
        biblionumber => $biblionumber,
(-)a/C4/ImportBatch.pm (-5 / +13 lines)
Lines 27-32 use C4::Items; Link Here
27
use C4::Charset;
27
use C4::Charset;
28
use C4::AuthoritiesMarc;
28
use C4::AuthoritiesMarc;
29
use C4::MarcModificationTemplates;
29
use C4::MarcModificationTemplates;
30
use DateTime;
31
use DateTime::Format::Strptime;
30
use Koha::Plugins::Handler;
32
use Koha::Plugins::Handler;
31
use Koha::Logger;
33
use Koha::Logger;
32
34
Lines 1608-1617 sub _create_import_record { Link Here
1608
sub _update_import_record_marc {
1610
sub _update_import_record_marc {
1609
    my ($import_record_id, $marc_record, $marc_type) = @_;
1611
    my ($import_record_id, $marc_record, $marc_type) = @_;
1610
1612
1613
    my $upload_timestamp = _get_import_record_timestamp($marc_record);
1614
1611
    my $dbh = C4::Context->dbh;
1615
    my $dbh = C4::Context->dbh;
1612
    my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?
1616
    my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?, upload_timestamp = ?
1613
                             WHERE  import_record_id = ?");
1617
                             WHERE  import_record_id = ?");
1614
    $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $import_record_id);
1618
    $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml($marc_type), $upload_timestamp, $import_record_id);
1615
    $sth->finish();
1619
    $sth->finish();
1616
}
1620
}
1617
1621
Lines 1632-1643 sub _add_auth_fields { Link Here
1632
sub _add_biblio_fields {
1636
sub _add_biblio_fields {
1633
    my ($import_record_id, $marc_record) = @_;
1637
    my ($import_record_id, $marc_record) = @_;
1634
1638
1639
    my $controlnumber;
1640
    if ($marc_record->field('001')) {
1641
        $controlnumber = $marc_record->field('001')->data();
1642
    }
1635
    my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
1643
    my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
1636
    my $dbh = C4::Context->dbh;
1644
    my $dbh = C4::Context->dbh;
1637
    # FIXME no controlnumber, originalsource
1645
    # FIXME no originalsource
1638
    $isbn = C4::Koha::GetNormalizedISBN($isbn);
1646
    $isbn = C4::Koha::GetNormalizedISBN($isbn);
1639
    my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn) VALUES (?, ?, ?, ?, ?)");
1647
    my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn, control_number) VALUES (?, ?, ?, ?, ?, ?)");
1640
    $sth->execute($import_record_id, $title, $author, $isbn, $issn);
1648
    $sth->execute($import_record_id, $title, $author, $isbn, $issn, $controlnumber);
1641
    $sth->finish();
1649
    $sth->finish();
1642
                
1650
                
1643
}
1651
}
(-)a/cataloguing/editor.pl (-1 / +1 lines)
Lines 49-55 my $schema = Koha::Database->new->schema; Link Here
49
$template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search(
49
$template->{VARS}->{editable_batches} = [ $schema->resultset('ImportBatch')->search(
50
    {
50
    {
51
        batch_type => [ 'batch', 'webservice' ],
51
        batch_type => [ 'batch', 'webservice' ],
52
        import_status => 'staged',
52
        import_status => [ 'staged', 'staging' ],
53
    },
53
    },
54
    { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
54
    { result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
55
) ];
55
) ];
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js (+52 lines)
Lines 130-135 define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin Link Here
130
            } );
130
            } );
131
        },
131
        },
132
132
133
        GetBatchRecord: function( batch_id, id, callback ) {
134
            $.get(
135
                '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/' + id
136
            ).done( function( data ) {
137
                var record = new MARC.Record();
138
                record.loadMARCXML( data.record );
139
                callback(record);
140
            } ).fail( function( data ) {
141
                callback( { error: data } );
142
            } );
143
        },
144
145
        CreateBatch: function( batch_name, callback ) {
146
            $.ajax( {
147
                type: 'POST',
148
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/',
149
                data: { batch_name: batch_name },
150
            } ).done( function( data ) {
151
                callback( data );
152
            } ).fail( function( data ) {
153
                callback( { error: data } );
154
            } );
155
        },
156
157
        CreateBatchRecord: function( record, batch_id, callback, options ) {
158
            $.ajax( {
159
                type: 'POST',
160
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/',
161
                data: { record: record.toXML(), allow_control_number_conflict: options.allow_control_number_conflict ? 1 : undefined },
162
            } ).done( function( data ) {
163
                callback( data );
164
            } ).fail( function( data ) {
165
                callback( { error: $.parseJSON( data.responseText ) || data.responseText } );
166
            } );
167
        },
168
169
        SaveBatchRecord: function( batch_id, id, record, callback, options ) {
170
            $.ajax( {
171
                type: 'POST',
172
                url: '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '/' + id,
173
                data: { record: record.toXML(), allow_control_number_conflict: options.allow_control_number_conflict ? 1 : undefined },
174
            } ).done( function( data ) {
175
                callback( data );
176
            } ).fail( function( data ) {
177
                callback( { data: { error: data } } );
178
            } );
179
        },
180
181
        StartBatchExport: function( batch_id, options ) {
182
            window.open( '/cgi-bin/koha/svc/cataloguing/import_batches/' + batch_id + '?download=1&' + $.param( options ) );
183
        },
184
133
        GetTagsBy: function( frameworkcode, field, value ) {
185
        GetTagsBy: function( frameworkcode, field, value ) {
134
            var result = {};
186
            var result = {};
135
187
(-)a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/preferences.js (+2 lines)
Lines 29-38 define( function() { Link Here
29
29
30
            Preferences.user = $.extend( {
30
            Preferences.user = $.extend( {
31
                // Preference defaults
31
                // Preference defaults
32
                enabledBatches: {},
32
                fieldWidgets: true,
33
                fieldWidgets: true,
33
                font: 'monospace',
34
                font: 'monospace',
34
                fontSize: '1em',
35
                fontSize: '1em',
35
                macros: {},
36
                macros: {},
37
                selected_save_targets: {},
36
                selected_search_targets: {},
38
                selected_search_targets: {},
37
            }, saved_prefs );
39
            }, saved_prefs );
38
        },
40
        },
(-)a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css (-1 / +43 lines)
Lines 59-64 body { Link Here
59
    font-size: 12px;
59
    font-size: 12px;
60
}
60
}
61
61
62
#save-targets input {
63
    display: inline-block;
64
    margin: 1px;
65
    vertical-align: middle;
66
}
67
68
#save-targets input:checked + label {
69
    color: #000;
70
}
71
72
#save-targets label {
73
    color: #666;
74
    display: inline-block;
75
    margin-left: 0.3em;
76
    padding: 0.3em 0;
77
    vertical-align: middle;
78
    width: 10em;
79
}
80
81
#save-targets li {
82
    overflow: hidden;
83
}
84
85
#shortcuts-container {
86
    font-size: 12px;
87
}
88
62
/*> MARC editor */
89
/*> MARC editor */
63
#editor .CodeMirror {
90
#editor .CodeMirror {
64
    line-height: 1.2;
91
    line-height: 1.2;
Lines 212-218 body { Link Here
212
239
213
/*> Search */
240
/*> Search */
214
241
215
#advanced-search-ui .modal-lg, #search-results-ui .modal-lg, #macro-ui .modal-lg {
242
#advanced-search-ui .modal-lg, #search-results-ui .modal-lg, #macro-ui .modal-lg .ui-modal {
243
    padding: 5px;
216
    width: 90%;
244
    width: 90%;
217
}
245
}
218
246
Lines 453-455 body { Link Here
453
.CodeMirror-gutter-wrapper {
481
.CodeMirror-gutter-wrapper {
454
    position: absolute;
482
    position: absolute;
455
}
483
}
484
485
/* >Batches */
486
#batches-list > li {
487
    border: 2px solid #F0F0F0;
488
    border-radius: 6px;
489
    display: block;
490
    line-height: 3em;
491
    font-size: 115%;
492
}
493
494
#batches-list > li input {
495
    display: inline-block;
496
    margin: 0 1em;
497
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cateditor-ui.inc (-34 / +316 lines)
Lines 37-42 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
37
            recordtype: 'biblio',
37
            recordtype: 'biblio',
38
            checked: false,
38
            checked: false,
39
        },
39
        },
40
        [%- FOREACH batch = editable_batches -%]
41
            'batch:[% batch.import_batch_id %]': {
42
                name: _("Batch: ") + '[% batch.file_name %]',
43
                recordtype: 'biblio',
44
                checked: false,
45
            },
46
        [%- END -%]
40
        [%- FOREACH server = z3950_servers -%]
47
        [%- FOREACH server = z3950_servers -%]
41
            [% server.id %]: {
48
            [% server.id %]: {
42
                name: '[% server.servername %]',
49
                name: '[% server.servername %]',
Lines 62-69 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
62
69
63
    var state = {
70
    var state = {
64
        backend: '',
71
        backend: '',
65
        saveBackend: 'catalog',
72
        recordID: undefined,
66
        recordID: undefined
73
        saveTargets: {},
67
    };
74
    };
68
75
69
    var editor;
76
    var editor;
Lines 227-242 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
227
            },
234
            },
228
        },
235
        },
229
        'catalog': {
236
        'catalog': {
230
            titleForRecord: _("Editing catalog record #{ID}"),
237
            titleForRecord: _("Editing catalog record #%s"),
231
            links: [
238
            links: [
232
                { title: _("view"), href: "/cgi-bin/koha/catalogue/detail.pl?biblionumber={ID}" },
239
                { title: _("view"), href: "/cgi-bin/koha/catalogue/detail.pl?biblionumber=%s" },
233
                { title: _("edit items"), href: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber={ID}" },
240
                { title: _("edit items"), href: "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=%s" },
234
            ],
241
            ],
235
            saveLabel: _("Save to catalog"),
242
            saveLabel: _("New catalog record"),
243
            saveExistingLabel: _("Catalog record #%s"),
236
            get: function( id, callback ) {
244
            get: function( id, callback ) {
237
                if ( !id ) return false;
245
                if ( !id ) return false;
238
246
239
                KohaBackend.GetRecord( id, callback );
247
                KohaBackend.GetRecord( id, function( data ) {
248
                    if ( !data.error ) {
249
                        setSaveTargetChecked( 'catalog/', false );
250
                        addSaveTarget( {
251
                            label: backends.catalog.saveExistingLabel.format( id ),
252
                            id: 'catalog/' + id,
253
                            description: '',
254
                            checked: true
255
                        } );
256
                    }
257
258
                    callback(data);
259
                } );
240
            },
260
            },
241
            save: function( id, record, done ) {
261
            save: function( id, record, done ) {
242
                function finishCb( data ) {
262
                function finishCb( data ) {
Lines 251-257 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
251
            }
271
            }
252
        },
272
        },
253
        'iso2709': {
273
        'iso2709': {
254
            saveLabel: _("Save as ISO2709 (.mrc) file"),
274
            saveLabel: _("New ISO2709 (.mrc) file"),
255
            save: function( id, record, done ) {
275
            save: function( id, record, done ) {
256
                saveAs( new Blob( [record.toISO2709()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.mrc' );
276
                saveAs( new Blob( [record.toISO2709()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.mrc' );
257
277
Lines 259-265 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
259
            }
279
            }
260
        },
280
        },
261
        'marcxml': {
281
        'marcxml': {
262
            saveLabel: _("Save as MARCXML (.xml) file"),
282
            saveLabel: _("New MARCXML (.xml) file"),
263
            save: function( id, record, done ) {
283
            save: function( id, record, done ) {
264
                saveAs( new Blob( [record.toXML()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.xml' );
284
                saveAs( new Blob( [record.toXML()], { 'type': 'application/octet-stream;charset=utf-8' } ), 'record.xml' );
265
285
Lines 281-286 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
281
        },
301
        },
282
    };
302
    };
283
303
304
    var editable_batches = {
305
        [%- FOREACH batch = editable_batches -%]
306
            [% batch.import_batch_id %]: {
307
                'name': '[% batch.file_name %]',
308
            },
309
        [%- END -%]
310
    };
311
312
    function addSaveTarget( target ) {
313
        state.saveTargets[target.id] = target;
314
        if (target.enabled == null) target.enabled = true;
315
316
        // Have to check that Preferences has been initialized
317
        var saved_value = Preferences.user && Preferences.user.selected_save_targets[target.id];
318
        if ( saved_value != null ) target.checked = saved_value;
319
320
        var target_list = $.map( state.saveTargets, function( target ) {
321
            return target;
322
        } );
323
324
        target_list.sort( function( a, b ) {
325
            return a.label.localeCompare(b.label);
326
        } );
327
328
        $('#save-targets ol').empty();
329
330
        $.each( target_list, function( i, target ) {
331
            var $new_target = $(
332
                '<li><input type="checkbox" class="save-toggle-target" data-target-id="' + target.id + '" id="save-target-' + i + '"' + ( target.checked ? ' checked="checked"' : '' ) + '> <label for="save-target-' + i + '">' + target.label + '</label></li>'
333
            );
334
335
            $new_target.find('input').change( function() {
336
                target.checked = this.checked;
337
            } );
338
339
            $('#save-targets ol').append($new_target);
340
341
            if (!target.enabled) $new_target.hide();
342
        } );
343
    }
344
345
    function setSaveTargetChecked( target_id, checked ) {
346
        if ( state.saveTargets[target_id] == null ) return;
347
348
        state.saveTargets[target_id].checked = checked;
349
        $( '#save-targets input[data-target-id="' + target_id + '"]' )[0].checked = checked;
350
    }
351
352
    function setSaveTargetEnabled( target_id, enabled ) {
353
        if ( !enabled ) {
354
            setSaveTargetChecked( target_id, false );
355
        }
356
357
        state.saveTargets[target_id].enabled = enabled;
358
        $( '#save-targets input[data-target-id="' + target_id + '"]' ).closest('li').toggle(enabled);
359
    }
360
284
    function setSource(parts) {
361
    function setSource(parts) {
285
        state.backend = parts[0];
362
        state.backend = parts[0];
286
        state.recordID = parts[1];
363
        state.recordID = parts[1];
Lines 291-303 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
291
368
292
        document.location.hash = '#' + parts[0] + '/' + parts[1];
369
        document.location.hash = '#' + parts[0] + '/' + parts[1];
293
370
294
        $('#title').text( backend.titleForRecord.replace( '{ID}', parts[1] ) );
371
        $('#title').text( backend.titleForRecord.format( parts[1] ) );
295
372
296
        $.each( backend.links || [], function( i, link ) {
373
        $.each( backend.links || [], function( i, link ) {
297
            $('#title').append(' <a target="_blank" href="' + link.href.replace( '{ID}', parts[1] ) + '">(' + link.title + ')</a>' );
374
            $('#title').append(' <a target="_blank" href="' + link.href.format( parts[1] ) + '">(' + link.title + ')</a>' );
298
        } );
375
        } );
299
        $( 'title', document.head ).html( _("Koha &rsaquo; Cataloging &rsaquo; ") + backend.titleForRecord.replace( '{ID}', parts[1] ) );
376
        $( 'title', document.head ).html( _("Koha &rsaquo; Cataloging &rsaquo; ") + backend.titleForRecord.format( parts[1] ) );
300
        $('#save-record span').text( backends[ state.saveBackend ].saveLabel );
301
    }
377
    }
302
378
303
    function saveRecord( recid, editor, callback ) {
379
    function saveRecord( recid, editor, callback ) {
Lines 333-338 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
333
409
334
            if (data.newId) {
410
            if (data.newId) {
335
                setSource(data.newId);
411
                setSource(data.newId);
412
413
                var backend = backends[ parts[0] ];
414
415
                setSaveTargetChecked( recid, false );
416
                addSaveTarget( {
417
                    label: backend.saveExistingLabel.format( data.newId[1] ),
418
                    id: data.newId.join('/'),
419
                    description: '',
420
                    checked: true
421
                } );
336
            } else {
422
            } else {
337
                setSource( [ state.backend, state.recordID ] );
423
                setSource( [ state.backend, state.recordID ] );
338
            }
424
            }
Lines 591-596 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
591
        var value = Preferences.user[pref];
677
        var value = Preferences.user[pref];
592
678
593
        switch (pref) {
679
        switch (pref) {
680
            case 'enabledBatches':
681
                $.each( editable_batches, function( batch_id, batch ) {
682
                    $( '#batches-list li[data-batch-id=' + batch_id + '] input' )[0].checked = Preferences.user.enabledBatches[batch_id];
683
                    setSaveTargetEnabled( 'batch:' + batch_id + '/', Preferences.user.enabledBatches[batch_id] || false );
684
                } );
594
            case 'fieldWidgets':
685
            case 'fieldWidgets':
595
                $( '#set-field-widgets' ).text( value ? _("Show fields verbatim") : _("Show helpers for fixed and coded fields") );
686
                $( '#set-field-widgets' ).text( value ? _("Show fields verbatim") : _("Show helpers for fixed and coded fields") );
596
                break;
687
                break;
Lines 612-617 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
612
                    if ( saved_val != null ) server.checked = saved_val;
703
                    if ( saved_val != null ) server.checked = saved_val;
613
                } );
704
                } );
614
                break;
705
                break;
706
            case 'selected_save_targets':
707
                $.each( state.saveTargets, function( target_id, target ) {
708
                    var saved_val = Preferences.user.selected_save_targets[target_id];
709
710
                    if ( saved_val != null ) setSaveTargetChecked( target_id, saved_val );
711
                } );
712
                break;
713
            case 'selected_search_targets':
714
                $.each( z3950Servers, function( server_id, server ) {
715
                    var saved_val = Preferences.user.selected_search_targets[server_id];
716
717
                    if ( saved_val != null ) server.checked = saved_val;
718
                } );
719
                break;
615
        }
720
        }
616
    }
721
    }
617
722
Lines 625-631 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
625
            } );
730
            } );
626
        }
731
        }
627
732
733
        function _addLiveHandler( sel, event, handler ) {
734
            $( document ).on( event, sel, function (e) {
735
                e.preventDefault();
736
                handler.call( this, e, Preferences.user[pref] );
737
                Preferences.Save( [% USER_INFO.borrowernumber %] );
738
                showPreference(pref);
739
            } );
740
        }
741
628
        switch (pref) {
742
        switch (pref) {
743
            case 'enabledBatches':
744
                _addLiveHandler( '#batches-list input', 'change', function() {
745
                    Preferences.user.enabledBatches[ $( this ).closest('li').data('batch-id') ] = this.checked;
746
                } );
747
                break;
629
            case 'fieldWidgets':
748
            case 'fieldWidgets':
630
                _addHandler( '#set-field-widgets', 'click', function( e, oldValue ) {
749
                _addHandler( '#set-field-widgets', 'click', function( e, oldValue ) {
631
                    editor.setUseWidgets( Preferences.user.fieldWidgets = !Preferences.user.fieldWidgets );
750
                    editor.setUseWidgets( Preferences.user.fieldWidgets = !Preferences.user.fieldWidgets );
Lines 641-646 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
641
                    Preferences.user.fontSize = $( e.target ).css( 'font-size' );
760
                    Preferences.user.fontSize = $( e.target ).css( 'font-size' );
642
                } );
761
                } );
643
                break;
762
                break;
763
            case 'selected_save_targets':
764
                $( document ).on( 'change', 'input.save-toggle-target', function() {
765
                    var target_id = $( this ).data('target-id');
766
                    Preferences.user.selected_save_targets[target_id] = this.checked;
767
                    Preferences.Save( [% USER_INFO.borrowernumber %] );
768
                } );
769
                break;
644
            case 'selected_search_targets':
770
            case 'selected_search_targets':
645
                $( document ).on( 'change', 'input.search-toggle-server', function() {
771
                $( document ).on( 'change', 'input.search-toggle-server', function() {
646
                    var server_id = $( this ).closest('li').data('server-id');
772
                    var server_id = $( this ).closest('li').data('server-id');
Lines 734-739 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
734
        showSavedMacros();
860
        showSavedMacros();
735
    }
861
    }
736
862
863
    function addImportBatch(batch) {
864
        var backend_id = 'batch:' + batch.batch_id;
865
        backends[backend_id] = {
866
            titleForRecord: _("Editing record from batch: ") + batch.name,
867
            saveLabel: _("Batch: ") + batch.name,
868
            saveExistingLabel: batch.name + ": #%s",
869
            get: function( id, callback ) {
870
                KohaBackend.GetBatchRecord( batch.batch_id, id, function( data ) {
871
                    if ( !data.error ) {
872
                        setSaveTargetChecked( backend_id + '/', false );
873
                        addSaveTarget( {
874
                            label: batch.name + ": #" + id,
875
                            id: backend_id + '/' + id,
876
                            description: '',
877
                            checked: true
878
                        } );
879
                    }
880
881
                    callback(data);
882
                } );
883
            },
884
            save: function( id, record, done, options ) {
885
                function finishCb( data ) {
886
                    done( {
887
                        error: data.message || data.error,
888
                        newRecord: data.updated_record,
889
                        newId: data.import_record_id && [ backend_id, data.import_record_id ]
890
                    } );
891
                }
892
893
                if ( id ) {
894
                    KohaBackend.SaveBatchRecord( batch.batch_id, id, record, finishCb, { allow_control_number_conflict: options.override_warnings } );
895
                } else {
896
                    KohaBackend.CreateBatchRecord( record, batch.batch_id, finishCb, { allow_control_number_conflict: options.override_warnings } );
897
                }
898
            },
899
        };
900
901
        // Build batch UI
902
        var $batch_entry = $( '<li data-batch-id="' + batch.batch_id + '"><input type="checkbox" />' + batch.name + '</li>' );
903
904
        var $batch_buttons = $('<span class="batch-buttons"></span>').appendTo($batch_entry);
905
        var $export_button = $( '<button>' + _("Export...") + '</button>' ).appendTo($batch_buttons).click( function() {
906
            $('#batches-list .batch-export').hide();
907
            $export_screen.show();
908
        } );
909
910
        var $export_screen = $(
911
            '<form class="batch-export form-horizontal" style="display: none">'
912
            + '<div class="control-group">'
913
            + '<label class="control-label">' + _("Control number range:") + '</label>'
914
            + '<div class="controls"><input class="batch-control-number-start" type="text"> - <input class="batch-control-number-end" type="text"></div>'
915
            + '</div>'
916
            + '<label class="control-label">' + _("Timestamp range (YYYYMMDD or YYYMMDDHHMMSS):") + '</label>'
917
            + '<div class="controls"><input class="batch-timestamp-start" type="text"> - <input class="batch-timestamp-end" type="text"></div>'
918
            + '</div>'
919
            + '<div class="control-group">'
920
            + '<div class="controls"><button class="batch-export-start">' + _("Start export") + '</div>'
921
            + '</form>'
922
        ).appendTo($batch_entry);
923
924
        $export_screen.find('.batch-export-start').click( function() {
925
            function getFormVal(name) {
926
                return $export_screen.find( '.batch-' + name ).val();
927
            }
928
929
            var options = {
930
                start_control_number: getFormVal('control-number-start'),
931
                end_control_number: getFormVal('control-number-end'),
932
                start_timestamp: getFormVal('timestamp-start'),
933
                end_timestamp: getFormVal('timestamp-end'),
934
            };
935
936
            KohaBackend.StartBatchExport( batch.batch_id, options );
937
        } );
938
939
        $('#batches-list').append( $batch_entry );
940
    }
941
737
    $(document).ready( function() {
942
    $(document).ready( function() {
738
        // Editor setup
943
        // Editor setup
739
        editor = new MARCEditor( {
944
        editor = new MARCEditor( {
Lines 783-788 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
783
                    $(this).height( $(window).height() * .8 - $(this).prevAll('.modal-header').height() );
988
                    $(this).height( $(window).height() * .8 - $(this).prevAll('.modal-header').height() );
784
                } );
989
                } );
785
            }, 100);
990
            }, 100);
991
786
        }
992
        }
787
993
788
        $( '#macro-ui' ).on( 'shown.bs.modal', function() {
994
        $( '#macro-ui' ).on( 'shown.bs.modal', function() {
Lines 823-831 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
823
        $.each( backends, function( id, backend ) {
1029
        $.each( backends, function( id, backend ) {
824
            if ( backend.save ) saveableBackends.push( [ backend.saveLabel, id ] );
1030
            if ( backend.save ) saveableBackends.push( [ backend.saveLabel, id ] );
825
        } );
1031
        } );
826
        saveableBackends.sort();
1032
827
        $.each( saveableBackends, function( undef, backend ) {
1033
        var batch_list = [];
828
            $( '#save-dropdown' ).append( '<li><a href="#" data-backend="' + backend[1] + '">' + backend[0] + '</a></li>' );
1034
1035
        $.each( editable_batches, function( batch_id, batch ) {
1036
            batch_list.push( $.extend( { batch_id: batch_id }, batch ) );
1037
        } );
1038
        batch_list.sort( function( a, b ) {
1039
            return a.name.localeCompare(b.name);
1040
        } );
1041
        $.each( batch_list, function() {
1042
            addImportBatch( this );
829
        } );
1043
        } );
830
1044
831
        var macro_format_list = $.map( Macros.formats, function( format, name ) {
1045
        var macro_format_list = $.map( Macros.formats, function( format, name ) {
Lines 840-854 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
840
1054
841
        // Click bindings
1055
        // Click bindings
842
        $( '#save-record, #save-dropdown a' ).click( function() {
1056
        $( '#save-record, #save-dropdown a' ).click( function() {
843
            $( '#save-record' ).find('i').attr( 'class', 'fa fa-spinner' ).siblings( 'span' ).text( _("Saving...") );
1057
            var enabledTargets = [];
1058
            var targetNames = [];
1059
            $.each( state.saveTargets, function() {
1060
                if ( this.checked ) {
1061
                    enabledTargets.push(this);
1062
                    targetNames.push(this.label);
1063
                }
1064
            } );
1065
            if ( enabledTargets.length == 0 ) {
1066
                humanMsg.displayAlert( _("Please select a save target"), { className: 'humanError' } );
1067
                return false;
1068
            }
1069
1070
            $( '#save-record' ).find('i').attr( 'class', 'icon-loading' ).siblings( 'span' ).text( _("Saving...") );
1071
1072
            var targets_left = enabledTargets.length;
1073
            var errors = false;
844
1074
845
            function finishCb(result) {
1075
            function finishCb(result) {
846
                if ( result.error == 'syntax' ) {
1076
                targets_left--;
847
                    humanMsg.displayAlert( _("Incorrect syntax, cannot save"), { className: 'humanError' } );
1077
                if ( result.error ) {
848
                } else if ( result.error == 'invalid' ) {
1078
                    if ( result.error == 'syntax' ) {
849
                    humanMsg.displayAlert( _("Record structure invalid, cannot save"), { className: 'humanError' } );
1079
                        humanMsg.displayAlert( _("Incorrect syntax, cannot save"), { className: 'humanError' } );
850
                } else if ( !result.error ) {
1080
                    } else if ( result.error == 'invalid' ) {
851
                    humanMsg.displayAlert( _("Record saved "), { className: 'humanSuccess' } );
1081
                        humanMsg.displayAlert( _("Record structure invalid, cannot save"), { className: 'humanError' } );
1082
                    } else if ( result.error.type == 'control_number_match' ) {
1083
                        humanMsg.displayAlert( _("Control number conflict, cannot save"), { className: 'humanError' } );
1084
                    } else {
1085
                        humanMsg.displayAlert( _("Unknown error, record not saved to one or more targets"), { className: 'humanError' } );
1086
                    }
1087
                    errors = true;
852
                }
1088
                }
853
1089
854
                $.each( result.errors || [], function( undef, error ) {
1090
                $.each( result.errors || [], function( undef, error ) {
Lines 884-903 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
884
                    }
1120
                    }
885
                } );
1121
                } );
886
1122
887
                $( '#save-record' ).find('i').attr( 'class', 'fa fa-hdd-o' );
888
1123
889
                if ( result.error ) {
1124
                if ( targets_left == 0 ) {
890
                    // Reset backend info
1125
                    if ( !errors ) {
891
                    setSource( [ state.backend, state.recordID ] );
1126
                        humanMsg.displayMsg( "<h3>" + _("Record saved to:</h3>") + "</h3>" + '<ul><li>' + targetNames.join('</li><li>') + '</li></ul>', { className: 'humanSuccess' } );
1127
                    }
1128
1129
                    $( '#save-record' ).find('i').attr( 'class', 'icon-hdd' ).end().find('span').text( _("Save") );
892
                }
1130
                }
893
            }
1131
            }
894
1132
895
            var backend = $( this ).data( 'backend' ) || ( state.saveBackend );
1133
            $.each( enabledTargets, function() {
896
            if ( state.backend == backend ) {
1134
                saveRecord( this.id, editor, finishCb, options );
897
                saveRecord( backend + '/' + state.recordID, editor, finishCb );
1135
            } );
898
            } else {
899
                saveRecord( backend + '/', editor, finishCb );
900
            }
901
1136
902
            return false;
1137
            return false;
903
        } );
1138
        } );
Lines 1038-1048 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1038
            }
1273
            }
1039
        } );
1274
        } );
1040
1275
1276
        $('#open-batches').click( function() {
1277
            $('#batches-ui').modal();
1278
1279
            return false;
1280
        } );
1281
1282
        $('#create-batch').click( function() {
1283
            var batch_name = prompt( _("Name of new import batch:") );
1284
            if (batch_name == null) return false;
1285
1286
            KohaBackend.CreateBatch( batch_name, function( data ) {
1287
                if ( data.error ) {
1288
                    humanMsg.displayAlert( _("Could not create import batch"), { className: 'humanError' } );
1289
                } else {
1290
                    humanMsg.displayAlert( _("Import batch created"), { className: 'humanSuccess' } );
1291
1292
                    addImportBatch( editable_batches[data.batch_id] = { batch_id: data.batch_id, name: batch_name } );
1293
1294
                    var backend_id = 'batch:' + data.batch_id;
1295
                    addSaveTarget( {
1296
                        label: backends[backend_id].saveLabel,
1297
                        id: backend_id + '/',
1298
                        description: '',
1299
                        enabled: false,
1300
                    } );
1301
                }
1302
            } );
1303
1304
            return false;
1305
        } );
1306
1307
        $('#manage-batches').click( function() {
1308
            window.open('/cgi-bin/koha/tools/manage-marc-import.pl');
1309
1310
            return false;
1311
        } );
1312
1041
        // Key bindings
1313
        // Key bindings
1042
        bindGlobalKeys();
1314
        bindGlobalKeys();
1043
1315
1044
        // Setup UI
1316
        // Setup UI
1045
        $("#advanced-search-ui, #search-results-ui, #macro-ui").each( function() {
1317
        $(".ui-modal").each( function() {
1046
            $(this).modal({ show: false });
1318
            $(this).modal({ show: false });
1047
        } );
1319
        } );
1048
1320
Lines 1092-1097 require( [ 'koha-backend', 'search', 'macros', 'marc-editor', 'marc-record', 'pr Link Here
1092
                { return undefined; }
1364
                { return undefined; }
1093
        };
1365
        };
1094
1366
1367
        $.each( backends, function( name ) {
1368
            if ( !this.save ) return; // Not a saving backend
1369
1370
            addSaveTarget( {
1371
                label: this.saveLabel,
1372
                id: name + '/',
1373
                description: '',
1374
            } );
1375
        } );
1376
1095
        // Start editor
1377
        // Start editor
1096
        Preferences.Load( [% USER_INFO.borrowernumber || 0 %] );
1378
        Preferences.Load( [% USER_INFO.borrowernumber || 0 %] );
1097
        displayPreferences(editor);
1379
        displayPreferences(editor);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt (-8 / +36 lines)
Lines 34-44 Link Here
34
    <div id="toolbar" class="btn-toolbar">
34
    <div id="toolbar" class="btn-toolbar">
35
        <button class="btn btn-default btn-sm" id="new-record" title="Open fresh record"><i class="fa fa-plus"></i> <span>New record</span></button>
35
        <button class="btn btn-default btn-sm" id="new-record" title="Open fresh record"><i class="fa fa-plus"></i> <span>New record</span></button>
36
        <div class="btn-group">
36
        <div class="btn-group">
37
            <button class="btn btn-default btn-sm" id="save-record" title="Save current record (Ctrl-S)"><i class="fa fa-hdd-o"></i> <span>Save</span></button>
37
            <button class="btn btn-default btn-sm" id="save-record" title="Save current record (Ctrl-S)"><i class="fa fa-save"></i> <span>Save </span></button>
38
            <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
38
            <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
39
            <span class="caret"></span>
39
            <ul id="save-dropdown" class="dropdown-menu">
40
            </button>
40
                <li><a id="save-with-override" href="#">Save overriding warnings</a></li>
41
            <ul class="dropdown-menu" id="save-dropdown">
42
            </ul>
41
            </ul>
43
        </div>
42
        </div>
44
        <button class="btn btn-default btn-sm" id="import-records" title="Import an ISO2709 or MARCXML record"><i class="fa fa-download"></i> <span>Import record...</span></button>
43
        <button class="btn btn-default btn-sm" id="import-records" title="Import an ISO2709 or MARCXML record"><i class="fa fa-download"></i> <span>Import record...</span></button>
Lines 48-53 Link Here
48
            <ul id="prefs-menu" class="dropdown-menu">
47
            <ul id="prefs-menu" class="dropdown-menu">
49
                <li><a id="switch-editor" href="#">Switch to basic editor</a></li>
48
                <li><a id="switch-editor" href="#">Switch to basic editor</a></li>
50
                <li><a id="set-field-widgets" href="#"></a></li>
49
                <li><a id="set-field-widgets" href="#"></a></li>
50
                <li><a id="open-batches" href="#">Import batches...</a></li>
51
                <li class="divider"></li>
51
                <li class="divider"></li>
52
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
52
                <li><a class="set-fontSize" style="font-size: .92em" href="#">Small text</a></li>
53
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
53
                <li><a class="set-fontSize" style="font-size: 1em" href="#">Normal text</a></li>
Lines 94-105 Link Here
94
    </fieldset>
94
    </fieldset>
95
</form>
95
</form>
96
96
97
<h3>Save to:</h3>
98
<form id="save-targets">
99
    <fieldset class="brief">
100
    <ol></ol>
101
    </fieldset>
102
</form>
103
97
</div>
104
</div>
98
105
99
</div>
106
</div>
100
</div>
107
</div>
101
108
102
<div id="advanced-search-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="advanced-search-title" aria-hidden="true">
109
<div id="advanced-search-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="advanced-search-title" aria-hidden="true">
103
<div class="modal-dialog modal-lg">
110
<div class="modal-dialog modal-lg">
104
<div class="modal-content">
111
<div class="modal-content">
105
112
Lines 180-186 Link Here
180
</div>
187
</div>
181
</div>
188
</div>
182
189
183
<div id="search-results-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="search-results-title" aria-hidden="true">
190
<div id="search-results-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="search-results-title" aria-hidden="true">
184
<div class="modal-dialog modal-lg">
191
<div class="modal-dialog modal-lg">
185
<div class="modal-content">
192
<div class="modal-content">
186
193
Lines 227-233 Link Here
227
234
228
</div>
235
</div>
229
236
230
<div id="macro-ui" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="macro-title" aria-hidden="true">
237
<div id="macro-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="macro-title" aria-hidden="true">
231
<div class="modal-dialog modal-lg">
238
<div class="modal-dialog modal-lg">
232
<div class="modal-content">
239
<div class="modal-content">
233
240
Lines 253-258 Link Here
253
</div>
260
</div>
254
</div>
261
</div>
255
262
263
<div id="batches-ui" class="ui-modal modal fade" tabindex="-1" role="dialog" aria-labelledby="batches-title" aria-hidden="true">
264
265
<div class="modal-header">
266
    <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
267
    <h3 id="batches-title">Import batch settings</h3>
268
</div>
269
270
<div class="modal-body row-fluid">
271
    <div class="span9">
272
        <div id="toolbar" class="btn-toolbar">
273
            <button class="btn btn-small" type="submit" id="create-batch"><i class="icon-plus"></i> <span>Create new batch...</span></button>
274
            <button class="btn btn-small" type="submit" id="manage-batches"><i class="icon-list"></i> <span>Manage import batches...</span></button>
275
        </div>
276
        <ul id="batches-list"></ul>
277
    </div>
278
    <div class="span3">
279
    </div>
280
</div>
281
282
</div>
283
256
<div id="shortcuts-contents" style="display: none">
284
<div id="shortcuts-contents" style="display: none">
257
<table class="table table-condensed">
285
<table class="table table-condensed">
258
    <thead>
286
    <thead>
(-)a/svc/cataloguing/import_batches (-1 / +212 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use C4::Biblio qw();
23
use C4::Context;
24
use C4::ImportBatch qw( AddBiblioToBatch AddImportBatch GetImportRecordMarcXML ModBiblioInBatch );
25
use C4::Service;
26
use DateTime;
27
use DateTime::Format::Strptime;
28
use Encode qw( encode_utf8 );
29
use Koha::Database;
30
use MARC::Record;
31
32
our ( $query, $response ) = C4::Service->init( tools => 'manage_staged_marc' );
33
34
sub _parse_005_timestamp {
35
    my ( $timestamp, $default_to_end ) = @_;
36
37
    # YYYYMMDD
38
    if ( $timestamp =~ /^\d{8}$/ ) {
39
        my $parser = DateTime::Format::Strptime->new( pattern => '%Y%m%d' );
40
        my $timestamp = $parser->parse_datetime($timestamp);
41
        if ( $timestamp && $default_to_end ) {
42
            $timestamp->set(
43
                hour => 23,
44
                minute => 59,
45
                second => 59
46
            );
47
        }
48
49
        return $timestamp;
50
    # YYYYMMDDHHMMSS
51
    } elsif ( $timestamp =~ /^\d{8}\d{6}$/ ) {
52
        my $parser = DateTime::Format::Strptime->new( pattern => '%Y%m%d%H%M%S' );
53
        return $parser->parse_datetime($timestamp);
54
    }
55
}
56
57
sub download_batch {
58
    my ( $batch_id ) = @_;
59
60
    my $schema = Koha::Database->new()->schema();
61
62
    my %extra_conditions;
63
64
    my $start_control_number = $query->param( 'start_control_number' );
65
    my $end_control_number = $query->param( 'end_control_number' );
66
67
    if ( $start_control_number && $end_control_number ) {
68
        $extra_conditions{control_number} = { -between => [ $start_control_number, $end_control_number ] };
69
    }
70
71
    my $start_timestamp = $query->param( 'start_timestamp' );
72
    my $end_timestamp = $query->param( 'end_timestamp' );
73
74
    if ( $start_timestamp && $end_timestamp ) {
75
        my $start_timestamp = _parse_005_timestamp( $start_timestamp, 0 );
76
        my $end_timestamp = _parse_005_timestamp( $end_timestamp, 1 );
77
78
        my $dtf = $schema->storage->datetime_parser;
79
80
        $extra_conditions{'import_record.upload_timestamp'} = {
81
            -between => [
82
                $dtf->format_datetime($start_timestamp),
83
                $dtf->format_datetime($end_timestamp)
84
            ]
85
        };
86
    }
87
88
    my $records = $schema->resultset('ImportBiblio')->search(
89
        {
90
            'import_record.import_batch_id' => $batch_id,
91
            %extra_conditions
92
        },
93
        {
94
            join => 'import_record',
95
        }
96
    );
97
98
    my $mimetype = 'application/octet-stream';
99
    my $charset  = 'utf-8';
100
    my $filename = DateTime->now->strftime("batch-$batch_id-%Y-%m-%d-%H-%M-%S.mrc");
101
    my $content_length = $records->get_column( { length => 'import_record.marc' } )->sum || 0;
102
103
    print $query->header(
104
        -type => $mimetype,
105
        -charset => $charset,
106
        -attachment => $filename,
107
        -Content_length => $content_length
108
    );
109
110
    for my $marc ( $records->get_column( 'import_record.marc' )->all ) {
111
        print $marc;
112
    }
113
}
114
115
sub get_record {
116
    my ( $batch_id, $import_record_id ) = @_;
117
118
    my $marcxml = GetImportRecordMarcXML( $import_record_id );
119
120
    if ( !$marcxml ) {
121
        C4::Service->return_error( 'not_found' );
122
    }
123
124
    $response->param( record => $marcxml );
125
126
    C4::Service->return_success( $response );
127
}
128
129
sub _control_number_already_used {
130
    my ( $marc_record, $batch_id, $import_record_id ) = @_;
131
132
    return unless ( $marc_record->field('001') );
133
134
    my %extra_conditions;
135
136
    $extra_conditions{'import_record.import_record_id'} = { '!=', $import_record_id } if ( $import_record_id );
137
138
    my $control_number = $marc_record->field('001')->data;
139
140
    my $schema = Koha::Database->new()->schema();
141
    return $schema->resultset('ImportBiblio')->count(
142
        {
143
            control_number => $control_number,
144
            'import_record.import_batch_id' => $batch_id,
145
            %extra_conditions
146
        },
147
        {
148
            join => 'import_record',
149
        }
150
    );
151
}
152
153
sub create_record {
154
    my ( $batch_id ) = @_;
155
156
    my $marcflavour = C4::Context->preference('marcflavour') || 'marc21';
157
    my $marc_record = eval { MARC::Record::new_from_xml( $query->param('record'), "utf8", $marcflavour) };
158
    if ($@) {
159
        C4::Service->return_error( 'failed', $@ );
160
    }
161
162
    if ( !$query->param('allow_control_number_conflict') && _control_number_already_used( $marc_record, $batch_id ) ) {
163
        C4::Service->return_error( 'control_number_match', '' );
164
    }
165
166
    my $import_record_id = AddBiblioToBatch( $batch_id, 0, $marc_record, "utf8", int( rand(99999) ) );
167
    $response->param( import_record_id => $import_record_id );
168
169
    C4::Service->return_success( $response );
170
}
171
172
sub update_record {
173
    my ( $batch_id, $import_record_id ) = @_;
174
175
    my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
176
    my $marc_record = eval { MARC::Record::new_from_xml( $query->param('record'), "utf8", $marcflavour) };
177
    if ($@) {
178
        C4::Service->return_error( 'failed', $@ );
179
    }
180
181
    if ( !$query->param('allow_control_number_conflict') &&  _control_number_already_used( $marc_record, $batch_id, $import_record_id ) ) {
182
        C4::Service->return_error( 'control_number_match', '' );
183
    }
184
185
    C4::Biblio::UpdateMarcTimestamp( $marc_record );
186
    ModBiblioInBatch( $import_record_id, $marc_record );
187
188
    $response->param( updated_record => $marc_record->as_xml_record( C4::Context->preference('marcflavour') ) );
189
190
    C4::Service->return_success( $response );
191
}
192
193
sub create_batch {
194
    my ( $batch_name ) = C4::Service->require_params( 'batch_name' );
195
196
    my $batch_id = AddImportBatch({
197
        file_name => $batch_name,
198
        record_type => 'biblio'
199
    });
200
201
    $response->param( batch_id => $batch_id );
202
203
    C4::Service->return_success( $response );
204
}
205
206
C4::Service->dispatch(
207
    [ 'GET /(\d+)', [ 'download' ], \&download_batch ],
208
    [ 'GET /(\d+)/(\d+)', [], \&get_record ],
209
    [ 'POST /(\d+)/', [], \&create_record ],
210
    [ 'POST /(\d+)/(\d+)', [], \&update_record ],
211
    [ 'POST /', [], \&create_batch ],
212
);

Return to bug 18823