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

(-)a/cataloguing/addbiblio.pl (-6 / +9 lines)
Lines 44-51 use C4::ClassSource qw( GetClassSources ); Link Here
44
use C4::ImportBatch qw( GetImportRecordMarc );
44
use C4::ImportBatch qw( GetImportRecordMarc );
45
use C4::Charset qw( SetMarcUnicodeFlag );
45
use C4::Charset qw( SetMarcUnicodeFlag );
46
use C4::MarcModificationTemplates;
46
use C4::MarcModificationTemplates;
47
use Koha::MarcModificationTemplates;
47
use Koha::BiblioFrameworks;
48
use Koha::BiblioFrameworks;
48
use Koha::DateUtils qw( dt_from_string );
49
use Koha::DateUtils qw( dt_from_string );
50
use Carp;
49
51
50
use Koha::Biblios;
52
use Koha::Biblios;
51
use Koha::ItemTypes;
53
use Koha::ItemTypes;
Lines 57-63 use Koha::Patrons; Link Here
57
use MARC::File::USMARC;
59
use MARC::File::USMARC;
58
use MARC::File::XML;
60
use MARC::File::XML;
59
use URI::Escape qw( uri_escape_utf8 );
61
use URI::Escape qw( uri_escape_utf8 );
60
use List::MoreUtils qw(firstval);
61
62
62
if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
63
if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
63
    MARC::File::XML->default_record_format('UNIMARC');
64
    MARC::File::XML->default_record_format('UNIMARC');
Lines 886-901 if ( $op eq "addbiblio" ) { Link Here
886
    # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
887
    # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
887
    if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
888
    if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
888
        my $oldbibitemnum;
889
        my $oldbibitemnum;
889
        my $marc_modification_template_name = C4::Context->preference("SaveBiblioMarcModificationTemplate");
890
890
        if ($marc_modification_template_name) {
891
        my $template_id = C4::Context->preference("SaveBiblioMarcModificationTemplate");
891
            my $template = firstval { $_->{'name'} eq $marc_modification_template_name } GetModificationTemplates();
892
        if ($template_id) {
893
            my $template = Koha::MarcModificationTemplates->find($template_id);
892
            if ($template) {
894
            if ($template) {
893
                ModifyRecordWithTemplate($template->{'template_id'}, $record);
895
                ModifyRecordWithTemplate($template_id, $record);
894
            }
896
            }
895
            else {
897
            else {
896
                warn "No MARC modification template exists with name \"$marc_modification_template_name\"";
898
                croak "No MARC modification template exists with id \"$template_id\"";
897
            }
899
            }
898
        }
900
        }
901
899
        if ( $is_a_modif ) {
902
        if ( $is_a_modif ) {
900
            my $member = Koha::Patrons->find($loggedinuser);
903
            my $member = Koha::Patrons->find($loggedinuser);
901
            ModBiblio(
904
            ModBiblio(
(-)a/svc/bib (-5 / +7 lines)
Lines 26-34 use C4::Auth qw( check_api_auth ); Link Here
26
use C4::Biblio qw( GetFrameworkCode );
26
use C4::Biblio qw( GetFrameworkCode );
27
use C4::Items;
27
use C4::Items;
28
use C4::MarcModificationTemplates;
28
use C4::MarcModificationTemplates;
29
use Koha::MarcModificationTemplates;
29
use XML::Simple;
30
use XML::Simple;
30
use Koha::Biblios;
31
use Koha::Biblios;
31
use List::MoreUtils qw(firstval);
32
use List::MoreUtils qw(firstval);
33
use Carp;
32
34
33
my $query = CGI->new;
35
my $query = CGI->new;
34
binmode STDOUT, ':encoding(UTF-8)';
36
binmode STDOUT, ':encoding(UTF-8)';
Lines 117-130 sub update_bib { Link Here
117
            }
119
            }
118
        }
120
        }
119
121
120
        my $marc_modification_template_name = C4::Context->preference("SaveBiblioMarcModificationTemplate");
122
        my $template_id = C4::Context->preference("SaveBiblioMarcModificationTemplate");
121
        if ($marc_modification_template_name) {
123
        if ($id) {
122
            my $template = firstval { $_->{'name'} eq $marc_modification_template_name } GetModificationTemplates();
124
            my $template = Koha::MarcModificationTemplates->find($template_id);
123
            if ($template) {
125
            if ($template) {
124
                ModifyRecordWithTemplate($template->{'template_id'}, $record);
126
                ModifyRecordWithTemplate($template_id, $record);
125
            }
127
            }
126
            else {
128
            else {
127
                warn "No MARC modification template exists with name \"$marc_modification_template_name\"";
129
                croak "No MARC modification template exists with id \"$template_id\"";
128
            }
130
            }
129
        }
131
        }
130
132
(-)a/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t (-6 / +8 lines)
Lines 23-28 require HTTP::Request; Link Here
23
use MARC::Record;
23
use MARC::Record;
24
use XML::Simple;
24
use XML::Simple;
25
use C4::MarcModificationTemplates;
25
use C4::MarcModificationTemplates;
26
use Koha::MarcModificationTemplates;
26
use C4::Biblio qw(AddBiblio ModBiblioMarc GetMarcBiblio);
27
use C4::Biblio qw(AddBiblio ModBiblioMarc GetMarcBiblio);
27
28
28
eval{
29
eval{
Lines 47-56 subtest 'Templates applied using simple and advanced MARC Editor' => sub { Link Here
47
    plan tests => 13;
48
    plan tests => 13;
48
49
49
    # Create "Test" MARC modification template
50
    # Create "Test" MARC modification template
50
    my $template_id = AddModificationTemplate('TEST');
51
    #my $template_id = AddModificationTemplate('TEST');
51
    ok($template_id, 'MARC modification template successfully created');
52
    my $template = Koha::MarcModificationTemplate->new({ name => 'TEST' })->store;
53
54
    ok($template, 'MARC modification template successfully created');
52
    my $add_template_action_result = AddModificationTemplateAction(
55
    my $add_template_action_result = AddModificationTemplateAction(
53
        $template_id,
56
        $template->id,
54
        'update_field', # Action
57
        'update_field', # Action
55
        0,
58
        0,
56
        250, # Field
59
        250, # Field
Lines 88-94 subtest 'Templates applied using simple and advanced MARC Editor' => sub { Link Here
88
    is($saved_record_250_field->subfield('a'), '250 bottles of beer on the wall', 'Field 250a has the same value passed to AddBiblio');
91
    is($saved_record_250_field->subfield('a'), '250 bottles of beer on the wall', 'Field 250a has the same value passed to AddBiblio');
89
92
90
    my $old_template_preference = C4::Context->preference('SaveBiblioMarcModificationTemplate');
93
    my $old_template_preference = C4::Context->preference('SaveBiblioMarcModificationTemplate');
91
    C4::Context->set_preference('SaveBiblioMarcModificationTemplate', 'TEST');
94
    C4::Context->set_preference('SaveBiblioMarcModificationTemplate', $template->id);
92
95
93
    my $agent = Test::WWW::Mechanize->new(autocheck => 1);
96
    my $agent = Test::WWW::Mechanize->new(autocheck => 1);
94
97
Lines 149-154 EOF Link Here
149
152
150
    # Clean up
153
    # Clean up
151
    DelBiblio($biblionumber);
154
    DelBiblio($biblionumber);
152
    DelModificationTemplate($template_id);
155
    $template->delete;
153
    C4::Context->set_preference('SaveBiblioMarcModificationTemplate', $old_template_preference);
156
    C4::Context->set_preference('SaveBiblioMarcModificationTemplate', $old_template_preference);
154
};
157
};
155
- 

Return to bug 18138