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

(-)a/C4/Biblio.pm (-1 / +7 lines)
Lines 257-262 in the C<biblio> and C<biblioitems> tables, as well as Link Here
257
which fields are used to store embedded item, biblioitem,
257
which fields are used to store embedded item, biblioitem,
258
and biblionumber data for indexing.
258
and biblionumber data for indexing.
259
259
260
The C<$options> argument is a hashref with additional parameters
261
that currently has one available option: C<context>. C<context>
262
is forwared to L<ApplyMarcMergeRules> where it is used for selecting the
263
current rule set if Marc Merge Rules is enabled.
264
See L<ApplyMarcMergeRules> for more details.
265
260
Returns 1 on success 0 on failure
266
Returns 1 on success 0 on failure
261
267
262
=cut
268
=cut
Lines 3279-3285 sub _koha_delete_biblio_metadata { Link Here
3279
3285
3280
=head2 ModBiblioMarc
3286
=head2 ModBiblioMarc
3281
3287
3282
  &ModBiblioMarc($newrec, $biblionumber, $frameworkcode, $options);
3288
  ModBiblioMarc($newrec, $biblionumber, $frameworkcode);
3283
3289
3284
Add MARC XML data for a biblio to koha
3290
Add MARC XML data for a biblio to koha
3285
3291
(-)a/Koha/MarcMergeRule.pm (+12 lines)
Lines 39-44 sub store { Link Here
39
    $self->SUPER::store(@_);
39
    $self->SUPER::store(@_);
40
}
40
}
41
41
42
=head2 delete
43
44
Override C<delete> to clear marc merge rules cache.
45
46
=cut
47
48
sub delete {
49
    my $self = shift @_;
50
    $cache->clear_from_cache('marc_merge_rules');
51
    $self->SUPER::delete(@_);
52
}
53
42
sub _type {
54
sub _type {
43
    return 'MarcMergeRule';
55
    return 'MarcMergeRule';
44
}
56
}
(-)a/admin/marc-merge-rules.pl (-2 / +2 lines)
Lines 15-22 Link Here
15
# You should have received a copy of the GNU General Public License
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use strict;
18
use Modern::Perl;
19
use warnings;
20
19
21
# standard or CPAN modules used
20
# standard or CPAN modules used
22
use CGI qw ( -utf8 );
21
use CGI qw ( -utf8 );
Lines 144-149 elsif ($op eq 'doedit' || $op eq 'add') { Link Here
144
        };
143
        };
145
        if (!@{$errors}) {
144
        if (!@{$errors}) {
146
            my $rule = Koha::MarcMergeRules->find_or_create($rule_data);
145
            my $rule = Koha::MarcMergeRules->find_or_create($rule_data);
146
            # Need to call set and store here in case we have an update
147
            $rule->set($rule_data);
147
            $rule->set($rule_data);
148
            $rule->store();
148
            $rule->store();
149
        }
149
        }
(-)a/t/db_dependent/Biblio/MarcMergeRules.t (-4 / +70 lines)
Lines 24-30 use C4::Context; Link Here
24
use C4::Biblio;
24
use C4::Biblio;
25
use Koha::Database; #??
25
use Koha::Database; #??
26
26
27
use Test::More tests => 22;
27
use Test::More tests => 23;
28
use Test::MockModule;
28
use Test::MockModule;
29
29
30
use Koha::MarcMergeRules;
30
use Koha::MarcMergeRules;
Lines 86-92 subtest 'Record fields has been overwritten when no merge rules are defined' => Link Here
86
86
87
my $rule =  Koha::MarcMergeRules->find_or_create({
87
my $rule =  Koha::MarcMergeRules->find_or_create({
88
    tag => '*',
88
    tag => '*',
89
    module => $modules[0]->id,
89
    module => $modules[0]->name,
90
    filter => '*',
90
    filter => '*',
91
    add => 0,
91
    add => 0,
92
    append => 0,
92
    append => 0,
Lines 585-591 subtest 'Record fields has been overwritten when add = 1, append = 1, remove = 1 Link Here
585
# Protect field 500 with more specific tag value
585
# Protect field 500 with more specific tag value
586
my $skip_all_rule = Koha::MarcMergeRules->find_or_create({
586
my $skip_all_rule = Koha::MarcMergeRules->find_or_create({
587
    tag => '500',
587
    tag => '500',
588
    module => $modules[0]->id,
588
    module => $modules[0]->name,
589
    filter => '*',
589
    filter => '*',
590
    add => 0,
590
    add => 0,
591
    append => 0,
591
    append => 0,
Lines 712-717 subtest 'An exception is thrown when rule tag is set to invalid regexp' => sub { Link Here
712
    ok($exception->isa('Koha::Exceptions::MarcMergeRule::InvalidTagRegExp'), "Exception is of correct class");
712
    ok($exception->isa('Koha::Exceptions::MarcMergeRule::InvalidTagRegExp'), "Exception is of correct class");
713
};
713
};
714
714
715
$skip_all_rule->delete();
716
717
subtest 'context option in ModBiblio is handled correctly' => sub {
718
    plan tests => 6;
719
    $rule->set(
720
        {
721
            tag => '250',
722
            module => $modules[0]->name,
723
            filter => '*',
724
            'add' => 0,
725
            'append' => 0,
726
            'remove' => 0,
727
            'delete' => 0,
728
        }
729
    );
730
    $rule->store();
731
    my ($biblionumber) = AddBiblio($orig_record, '');
732
733
    # Since marc merc rules are not run on save, only update
734
    # saved record should be identical to orig_record
735
    my $saved_record = GetMarcBiblio({ biblionumber => $biblionumber });
736
737
    my @all_fields = $saved_record->fields();
738
    # Koha also adds 999c field, therefore 4 not 3
739
    cmp_ok(scalar @all_fields, '==', 4, 'Saved record has the expected number of fields');
740
    is_deeply(
741
        [map { $_->subfield('a') } $saved_record->field('250') ],
742
        ['250 bottles of beer on the wall', '256 bottles of beer on the wall'],
743
        'All "250" fields of saved record are identical to original record passed to AddBiblio'
744
    );
745
746
    is_deeply(
747
        [map { $_->subfield('a') } $saved_record->field('500') ],
748
        ['One bottle of beer in the fridge'],
749
        'All "500" fields of saved record are identical to original record passed to AddBiblio'
750
    );
751
752
    $saved_record->append_fields(
753
        MARC::Field->new('250', '', '', 'a' => '251 bottles of beer on the wall'), # Appended
754
        MARC::Field->new('500', '', '', 'a' => 'One cold bottle of beer in the fridge'), # Appended
755
    );
756
757
    ModBiblio($saved_record, $biblionumber, '', { context => { $modules[0]->name => 'test' } });
758
759
    my $updated_record = GetMarcBiblio({ biblionumber => $biblionumber });
760
761
    @all_fields = $updated_record->fields();
762
    cmp_ok(scalar @all_fields, '==', 5, 'Updated record has the expected number of fields');
763
    is_deeply(
764
        [map { $_->subfield('a') } $updated_record->field('250') ],
765
        ['250 bottles of beer on the wall', '256 bottles of beer on the wall'],
766
        '"250" fields have retained their original values'
767
    );
768
769
    is_deeply(
770
        [map { $_->subfield('a') } $updated_record->field('500') ],
771
        ['One bottle of beer in the fridge', 'One cold bottle of beer in the fridge'],
772
        '"500" field has been appended'
773
    );
774
775
    # To trigger removal from search index etc
776
    DelBiblio($biblionumber);
777
};
778
779
# Explicityly delete rule to trigger clearing of cache
780
$rule->delete();
781
715
$schema->storage->txn_rollback;
782
$schema->storage->txn_rollback;
716
783
717
1;
784
1;
718
- 

Return to bug 14957