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

(-)a/admin/preferences.pl (-1 / +2 lines)
Lines 115-121 sub _get_chunk { Link Here
115
                    $add_blank = 1;
115
                    $add_blank = 1;
116
                }
116
                }
117
            } elsif ( $options{choices} eq 'marcModTemplates' ) {
117
            } elsif ( $options{choices} eq 'marcModTemplates' ) {
118
                $options{choices} = { map { $_->template_id => $_->name } Koha::MarcModificationTemplates->search->as_list };
118
                $options{choices} =
119
                    { map { $_->template_id => $_->name } Koha::MarcModificationTemplates->search->as_list };
119
                $add_blank = 1;
120
                $add_blank = 1;
120
            } else {
121
            } else {
121
                die 'Unrecognized source of preference values: ' . $options{'choices'};
122
                die 'Unrecognized source of preference values: ' . $options{'choices'};
(-)a/cataloguing/addbiblio.pl (-3 / +2 lines)
Lines 673-681 if ( $op eq "addbiblio" ) { Link Here
673
        if ($template_id) {
673
        if ($template_id) {
674
            my $template = Koha::MarcModificationTemplates->find($template_id);
674
            my $template = Koha::MarcModificationTemplates->find($template_id);
675
            if ($template) {
675
            if ($template) {
676
                ModifyRecordWithTemplate($template_id, $record);
676
                ModifyRecordWithTemplate( $template_id, $record );
677
            }
677
            } else {
678
            else {
679
                croak "No MARC modification template exists with id \"$template_id\"";
678
                croak "No MARC modification template exists with id \"$template_id\"";
680
            }
679
            }
681
        }
680
        }
(-)a/installer/data/mysql/atomicupdate/bug_18138-edit-biblio-marc-modification-template-syspref.pl (-7 / +11 lines)
Lines 1-14 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "18138",
4
    bug_number  => "18138",
5
    description => "Add system preference",
5
    description => "Use MARC modification template when adding/updating bibliographic records",
6
    up => sub {
6
    up          => sub {
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
        # Do you stuffs here
10
        # Do you stuffs here
10
        $dbh->do(q{INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type`) VALUES ('SaveBiblioMarcModificationTemplate', '', NULL, 'MARC modification template applied when saving bibliographic record in staff client or HTTP API', 'marcModTemplates')});
11
        $dbh->do(
12
            q{INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type`) VALUES ('SaveBiblioMarcModificationTemplate', '', NULL, 'MARC modification template applied when saving bibliographic record in staff interface or HTTP API', 'marcModTemplates')}
13
        );
14
11
        # Print useful stuff here
15
        # Print useful stuff here
12
        say $out "System preference added";
16
        say $out "Added new system preference 'SaveBiblioMarcModificationTemplate'";
13
    },
17
    },
14
}
18
    }
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-1 / +1 lines)
Lines 651-658 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
651
('RoutingListAddReserves','0','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'),
651
('RoutingListAddReserves','0','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'),
652
('RoutingListNote','To change this note edit <a href=\"/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped\">RoutingListNote</a> system preference.','70|10','Define a note to be shown on all routing lists','Textarea'),
652
('RoutingListNote','To change this note edit <a href=\"/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped\">RoutingListNote</a> system preference.','70|10','Define a note to be shown on all routing lists','Textarea'),
653
('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'),
653
('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'),
654
('SaveBiblioMarcModificationTemplate', '', NULL, 'MARC modification template applied when saving bibliographic record in staff interface or HTTP API', 'marcModTemplates'),
654
('SavedSearchFilters', '0', NULL, 'Allow staff with permission to create/edit custom search filters', 'YesNo'),
655
('SavedSearchFilters', '0', NULL, 'Allow staff with permission to create/edit custom search filters', 'YesNo'),
655
('SaveBiblioMarcModificationTemplate', '', NULL, 'MARC modification template applied when saving bibliographic record in staff client or HTTP API', 'marcModTemplates'),
656
('SCOAllowCheckin','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'),
656
('SCOAllowCheckin','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'),
657
('SCOMainUserBlock','','70|10','Add a block of HTML that will display on the self checkout screen','Textarea'),
657
('SCOMainUserBlock','','70|10','Add a block of HTML that will display on the self checkout screen','Textarea'),
658
('SCOUserCSS','',NULL,'Add CSS to be included in the SCO module in an embedded <style> tag.','free'),
658
('SCOUserCSS','',NULL,'Add CSS to be included in the SCO module in an embedded <style> tag.','free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (-2 / +2 lines)
Lines 218-227 Cataloging: Link Here
218
                  0: "Don't strip"
218
                  0: "Don't strip"
219
            - leading and trailing whitespace characters (including spaces, tabs, line breaks and carriage returns) and inner newlines from data fields when cataloguing bibliographic and authority records. The leader and control fields will not be affected.
219
            - leading and trailing whitespace characters (including spaces, tabs, line breaks and carriage returns) and inner newlines from data fields when cataloguing bibliographic and authority records. The leader and control fields will not be affected.
220
        -
220
        -
221
            - Apply the MARC modification template with name
221
            - Apply the MARC modification template
222
            - pref: SaveBiblioMarcModificationTemplate
222
            - pref: SaveBiblioMarcModificationTemplate
223
              choices: marcModTemplates
223
              choices: marcModTemplates
224
            - on records saved using the staff client simple MARC editor, advanced editor or HTTP API.
224
            - on records saved using the staff interface simple MARC editor, advanced editor or HTTP API.
225
    Display:
225
    Display:
226
        -
226
        -
227
            - 'Separate main entry and subdivisions with '
227
            - 'Separate main entry and subdivisions with '
(-)a/svc/bib (-3 / +2 lines)
Lines 132-140 sub update_bib { Link Here
132
        if ($template_id) {
132
        if ($template_id) {
133
            my $template = Koha::MarcModificationTemplates->find($template_id);
133
            my $template = Koha::MarcModificationTemplates->find($template_id);
134
            if ($template) {
134
            if ($template) {
135
                ModifyRecordWithTemplate($template_id, $record);
135
                ModifyRecordWithTemplate( $template_id, $record );
136
            }
136
            } else {
137
            else {
138
                croak "No MARC modification template exists with id \"$template_id\"";
137
                croak "No MARC modification template exists with id \"$template_id\"";
139
            }
138
            }
140
        }
139
        }
(-)a/t/db_dependent/Koha/MarcModificationTemplates.t (-9 / +13 lines)
Lines 30-45 use t::lib::TestBuilder; Link Here
30
my $schema = Koha::Database->new->schema;
30
my $schema = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
31
$schema->storage->txn_begin;
32
32
33
my $builder = t::lib::TestBuilder->new;
33
my $builder    = t::lib::TestBuilder->new;
34
my $nb_of_mmts = Koha::MarcModificationTemplates->search->count;
34
my $nb_of_mmts = Koha::MarcModificationTemplates->search->count;
35
my $new_mmt_1 = Koha::MarcModificationTemplate->new({
35
my $new_mmt_1  = Koha::MarcModificationTemplate->new(
36
    name => 'my_mmt_name_for_test_1',
36
    {
37
})->store;
37
        name => 'my_mmt_name_for_test_1',
38
my $new_mmt_2 = Koha::MarcModificationTemplate->new({
38
    }
39
    name => 'my_mmt_name_for_test_2',
39
)->store;
40
})->store;
40
my $new_mmt_2 = Koha::MarcModificationTemplate->new(
41
41
    {
42
like( $new_mmt_1->template_id, qr|^\d+$|, 'Adding a new mmt should have set the id');
42
        name => 'my_mmt_name_for_test_2',
43
    }
44
)->store;
45
46
like( $new_mmt_1->template_id, qr|^\d+$|, 'Adding a new mmt should have set the id' );
43
is( Koha::MarcModificationTemplates->search->count, $nb_of_mmts + 2, 'The 2 templates should have been added' );
47
is( Koha::MarcModificationTemplates->search->count, $nb_of_mmts + 2, 'The 2 templates should have been added' );
44
48
45
my $retrieved_mmt_1 = Koha::MarcModificationTemplates->find( $new_mmt_1->template_id );
49
my $retrieved_mmt_1 = Koha::MarcModificationTemplates->find( $new_mmt_1->template_id );
(-)a/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t (-44 / +57 lines)
Lines 27-47 use Koha::MarcModificationTemplates; Link Here
27
use C4::Biblio qw(AddBiblio ModBiblioMarc DelBiblio);
27
use C4::Biblio qw(AddBiblio ModBiblioMarc DelBiblio);
28
use Koha::Biblios;
28
use Koha::Biblios;
29
29
30
eval{
30
eval { use C4::Context; };
31
    use C4::Context;
32
};
33
if ($@) {
31
if ($@) {
34
    plan skip_all => "Tests skip. You must have a working Context\n";
32
    plan skip_all => "Tests skip. You must have a working Context\n";
35
}
33
}
36
34
37
my $koha_conf = $ENV{KOHA_CONF};
35
my $koha_conf     = $ENV{KOHA_CONF};
38
my $koha_conf_xml = XMLin($koha_conf);
36
my $koha_conf_xml = XMLin($koha_conf);
39
37
40
my $user     = $ENV{KOHA_USER} || $koha_conf_xml->{config}->{user};
38
my $user     = $ENV{KOHA_USER} || $koha_conf_xml->{config}->{user};
41
my $password = $ENV{KOHA_PASS} || $koha_conf_xml->{config}->{pass};
39
my $password = $ENV{KOHA_PASS} || $koha_conf_xml->{config}->{pass};
42
my $intranet = $ENV{KOHA_INTRANET_URL};
40
my $intranet = $ENV{KOHA_INTRANET_URL};
43
41
44
if (not defined $intranet) {
42
if ( not defined $intranet ) {
45
    plan skip_all => "Tests skipped. You must set environment variable KOHA_INTRANET_URL to run tests\n";
43
    plan skip_all => "Tests skipped. You must set environment variable KOHA_INTRANET_URL to run tests\n";
46
}
44
}
47
45
Lines 50-65 subtest 'Templates applied using simple and advanced MARC Editor' => sub { Link Here
50
48
51
    # Create "Test" MARC modification template
49
    # Create "Test" MARC modification template
52
    #my $template_id = AddModificationTemplate('TEST');
50
    #my $template_id = AddModificationTemplate('TEST');
53
    my $template = Koha::MarcModificationTemplate->new({ name => 'TEST' })->store;
51
    my $template = Koha::MarcModificationTemplate->new( { name => 'TEST' } )->store;
54
52
55
    ok($template, 'MARC modification template successfully created');
53
    ok( $template, 'MARC modification template successfully created' );
56
    my $add_template_action_result = AddModificationTemplateAction(
54
    my $add_template_action_result = AddModificationTemplateAction(
57
        $template->id,
55
        $template->id,
58
        'update_field', # Action
56
        'update_field',                       # Action
59
        0,
57
        0,
60
        250, # Field
58
        250,                                  # Field
61
        'a', # Subfield
59
        'a',                                  # Subfield
62
        '251 bottles of beer on the wall', # Value
60
        '251 bottles of beer on the wall',    # Value
63
        '',
61
        '',
64
        '',
62
        '',
65
        '',
63
        '',
Lines 73-128 subtest 'Templates applied using simple and advanced MARC Editor' => sub { Link Here
73
        0,
71
        0,
74
        ''
72
        ''
75
    );
73
    );
76
    ok($add_template_action_result, 'MARC modification template action successfully created');
74
    ok( $add_template_action_result, 'MARC modification template action successfully created' );
77
    my $record =  MARC::Record->new();
75
    my $record = MARC::Record->new();
78
    $record->leader('     nam a22     7a 4500');
76
    $record->leader('     nam a22     7a 4500');
79
    $record->append_fields(
77
    $record->append_fields(
80
        MARC::Field->new('001', '12345'),
78
        MARC::Field->new( '001', '12345' ),
81
        MARC::Field->new('003', 'TEST'),
79
        MARC::Field->new( '003', 'TEST' ),
82
        MARC::Field->new('245', '1', '0', 'a' => 'TEST'),
80
        MARC::Field->new( '245', '1', '0', 'a' => 'TEST' ),
83
        MARC::Field->new('250', '','', 'a' => '250 bottles of beer on the wall'),
81
        MARC::Field->new( '250', '',  '',  'a' => '250 bottles of beer on the wall' ),
82
84
        # @FIXME: Create test item type? Not super safe to rely on existing 'BK' type
83
        # @FIXME: Create test item type? Not super safe to rely on existing 'BK' type
85
        MARC::Field->new('942', '','', 'c' => 'BK'),
84
        MARC::Field->new( '942', '', '', 'c' => 'BK' ),
86
    );
85
    );
87
    my ($biblionumber) = AddBiblio($record, '');
86
    my ($biblionumber) = AddBiblio( $record, '' );
88
87
89
    my $saved_record = Koha::Biblios->find($biblionumber)->metadata->record();
88
    my $saved_record           = Koha::Biblios->find($biblionumber)->metadata->record();
90
    my $saved_record_250_field = $saved_record->field('250');
89
    my $saved_record_250_field = $saved_record->field('250');
91
    isa_ok($saved_record_250_field, 'MARC::Field', 'Field with tag 250 has been saved');
90
    isa_ok( $saved_record_250_field, 'MARC::Field', 'Field with tag 250 has been saved' );
92
    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(
92
        $saved_record_250_field->subfield('a'), '250 bottles of beer on the wall',
93
        'Field 250a has the same value passed to AddBiblio'
94
    );
93
95
94
    my $old_template_preference = C4::Context->preference('SaveBiblioMarcModificationTemplate');
96
    my $old_template_preference = C4::Context->preference('SaveBiblioMarcModificationTemplate');
95
    C4::Context->set_preference('SaveBiblioMarcModificationTemplate', $template->id);
97
    C4::Context->set_preference( 'SaveBiblioMarcModificationTemplate', $template->id );
96
98
97
    my $agent = Test::WWW::Mechanize->new(autocheck => 1);
99
    my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
98
100
99
    $agent->get_ok("$intranet/cgi-bin/koha/mainpage.pl", 'Connect to intranet');
101
    $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'Connect to intranet' );
100
    $agent->form_name('loginform');
102
    $agent->form_name('loginform');
101
    $agent->field('password', $password);
103
    $agent->field( 'password', $password );
102
    $agent->field('userid', $user);
104
    $agent->field( 'userid',   $user );
103
    $agent->field('branch', '');
105
    $agent->field( 'branch',   '' );
104
    $agent->click_ok('', 'Login to staff interface');
106
    $agent->click_ok( '', 'Login to staff interface' );
105
    $agent->content_lacks('Invalid username or password', 'Logged in to staff interface');
107
    $agent->content_lacks( 'Invalid username or password', 'Logged in to staff interface' );
106
108
107
    $agent->get_ok("$intranet/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber", 'Load bibliographic record in simple MARC editor');
109
    $agent->get_ok(
110
        "$intranet/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber",
111
        'Load bibliographic record in simple MARC editor'
112
    );
108
    $agent->submit_form_ok(
113
    $agent->submit_form_ok(
109
        {
114
        {
110
            form_id => 'f',
115
            form_id => 'f',
111
            button => '',
116
            button  => '',
112
        },
117
        },
113
        'Save bibliographic record using simple MARC editor'
118
        'Save bibliographic record using simple MARC editor'
114
    );
119
    );
115
120
116
    $saved_record = Koha::Biblios->find($biblionumber)->metadata->record();
121
    $saved_record           = Koha::Biblios->find($biblionumber)->metadata->record();
117
    $saved_record_250_field = $saved_record->field('250');
122
    $saved_record_250_field = $saved_record->field('250');
118
    is($saved_record_250_field->subfield('a'), '251 bottles of beer on the wall', 'Field with tag 250 has been modified by MARC modification template');
123
    is(
124
        $saved_record_250_field->subfield('a'), '251 bottles of beer on the wall',
125
        'Field with tag 250 has been modified by MARC modification template'
126
    );
119
127
120
    # FIXME: Don't really need to to this, but could be useful so
128
    # FIXME: Don't really need to to this, but could be useful so
121
    # test below does not succed by accident
129
    # test below does not succeed by accident
122
    $saved_record->delete_fields($saved_record_250_field);
130
    $saved_record->delete_fields($saved_record_250_field);
123
    $saved_record->insert_fields_ordered(MARC::Field->new('250', '','', 'a' => '250 bottles of beer on the wall'));
131
    $saved_record->insert_fields_ordered( MARC::Field->new( '250', '', '', 'a' => '250 bottles of beer on the wall' ) );
124
    $biblionumber = ModBiblioMarc($saved_record, $biblionumber);
132
    $biblionumber = ModBiblioMarc( $saved_record, $biblionumber );
125
    ok($biblionumber, 'Field with tag 250 has been restored to original value');
133
    ok( $biblionumber, 'Field with tag 250 has been restored to original value' );
126
134
127
    # @FIXME: Leader record status n or c?
135
    # @FIXME: Leader record status n or c?
128
    my $record_xml = <<'EOF';
136
    my $record_xml = <<'EOF';
Lines 145-158 EOF Link Here
145
    my $headers = HTTP::Headers->new(
153
    my $headers = HTTP::Headers->new(
146
        Content_Type => 'text/xml',
154
        Content_Type => 'text/xml',
147
    );
155
    );
148
    my $request = HTTP::Request->new('POST', "$intranet/cgi-bin/koha/svc/bib/$biblionumber", $headers, $record_xml);
156
    my $request  = HTTP::Request->new( 'POST', "$intranet/cgi-bin/koha/svc/bib/$biblionumber", $headers, $record_xml );
149
    my $response = $agent->request($request);
157
    my $response = $agent->request($request);
150
158
151
    is($response->code, '200', 'Emulate save in advanced MARC editor, Koha REST API responded with 200 for update biblio request');
159
    is(
152
    like($response->decoded_content, qr/251 bottles of beer on the wall/, 'Field with tag 250 has been modified by MARC modification template');
160
        $response->code, '200',
161
        'Emulate save in advanced MARC editor, Koha REST API responded with 200 for update biblio request'
162
    );
163
    like(
164
        $response->decoded_content, qr/251 bottles of beer on the wall/,
165
        'Field with tag 250 has been modified by MARC modification template'
166
    );
153
167
154
    # Clean up
168
    # Clean up
155
    DelBiblio($biblionumber);
169
    DelBiblio($biblionumber);
156
    $template->delete;
170
    $template->delete;
157
    C4::Context->set_preference('SaveBiblioMarcModificationTemplate', $old_template_preference);
171
    C4::Context->set_preference( 'SaveBiblioMarcModificationTemplate', $old_template_preference );
158
};
172
};
159
- 

Return to bug 18138