Bugzilla – Attachment 56274 Details for
Bug 15996
Bibliographic records diffing tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15996 - Bibliographic records diffing tool - Grep changed elements
Bug-15996---Bibliographic-records-diffing-tool---G.patch (text/plain), 5.55 KB, created by
Olli-Antti Kivilahti
on 2016-10-12 13:05:34 UTC
(
hide
)
Description:
Bug 15996 - Bibliographic records diffing tool - Grep changed elements
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2016-10-12 13:05:34 UTC
Size:
5.55 KB
patch
obsolete
>From ddaad74e85acf7d4d4c86bb299011e6745a69a65 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Wed, 12 Oct 2016 16:04:53 +0300 >Subject: [PATCH] Bug 15996 - Bibliographic records diffing tool - Grep changed > elements > >--- > C4/Biblio/Diff.pm | 52 +++++++++++++++++++++++++++++++++++++++ > C4/Biblio/Diff/Change.pm | 45 +++++++++++++++++++++++++++++++++ > t/db_dependent/Biblio/Diff/diff.t | 44 +++++++++++++++++++++++++++++++++ > 3 files changed, 141 insertions(+) > create mode 100644 C4/Biblio/Diff/Change.pm > >diff --git a/C4/Biblio/Diff.pm b/C4/Biblio/Diff.pm >index 3a7b981..ce1a2e1 100644 >--- a/C4/Biblio/Diff.pm >+++ b/C4/Biblio/Diff.pm >@@ -21,6 +21,8 @@ use Modern::Perl; > use Scalar::Util qw(blessed); > use Try::Tiny; > >+use C4::Biblio::Diff::Change; >+ > use Koha::Exception::BadParameter; > > =head SYNOPSIS >@@ -307,4 +309,54 @@ sub _valuesDiff { > return 0; > } > >+=head2 grepChangedElements >+ >+@PARAM1 HASHMonster from diffRecords() >+@PARAM2 ARRAYRef of HASHRefs, the MARC field-subfield tuples to search for, >+ [ >+ { >+ f => '084', >+ sf => 'a' >+ }, >+ ... >+ ] >+@RETURNS Arrayref of Arrayrefs, >+ [ >+ [ >+ '084', #Field >+ 'a', #Subfield >+ 'YKL', #Old value >+ 'AKT' #New value >+ ], >+ ... >+ ] >+ >+=cut >+ >+sub grepChangedElements { >+ my ($diff, $selectors) = @_; >+ >+ my @changes; >+ >+ foreach my $n (@$selectors) { #$n as in the "needle in the haystack" >+ if (int($n->{f}) < 10) { #Control fields >+ my $fieldDiffs = $diff->{$n->{f}}; >+ push(@changes, C4::Biblio::Diff::Change->new($n->{f}, $n->{sf}, @$fieldDiffs)); >+ } >+ else { #Data fields >+ my $fieldReps = $diff->{$n->{f}}; #fieldReps as in Field Repetitons, not all Fields but the repetitions of a selected MARC Field >+ next unless $fieldReps; >+ foreach my $field (@$fieldReps) { >+ >+ my $subfieldReps = $field->{$n->{sf}}; >+ next unless $subfieldReps; >+ foreach my $subfieldDiffs (@$subfieldReps) { >+ push(@changes, C4::Biblio::Diff::Change->new($n->{f}, $n->{sf}, @$subfieldDiffs)); >+ } >+ } >+ } >+ } >+ return \@changes; >+} >+ > 1; >diff --git a/C4/Biblio/Diff/Change.pm b/C4/Biblio/Diff/Change.pm >new file mode 100644 >index 0000000..afc492d >--- /dev/null >+++ b/C4/Biblio/Diff/Change.pm >@@ -0,0 +1,45 @@ >+package C4::Biblio::Diff::Change; >+ >+# Copyright KohaSuomi 2016 >+# >+# This file is part of Koha. >+# >+ >+use Modern::Perl; >+ >+=head SYNOPSIS >+ >+ Change is a single row of changes between two or more records >+ >+=cut >+ >+=head new >+ >+ my $change = C4::Biblio::Diff::Change->new($fieldCode, $subfieldCode, @diffedValues); >+ my $change = C4::Biblio::Diff::Change->new('084', 'a', 'Text and subfield content', ... , 'Moar text'); >+ >+=cut >+ >+sub new { >+ my $class = shift @_; >+ my $self = \@_; >+ bless($self, $class); >+ return $self; >+} >+ >+sub getFieldCode { >+ return shift->[0]; >+} >+sub getSubfieldCode { >+ return shift->[1]; >+} >+sub getVal { >+ my ($self, $i) = @_; >+ return $self->[$i+2]; >+} >+sub getVals { >+ my ($self) = @_; >+ return $self->[2..@$self]; >+} >+ >+1; >diff --git a/t/db_dependent/Biblio/Diff/diff.t b/t/db_dependent/Biblio/Diff/diff.t >index d91fb69..88d25d8 100644 >--- a/t/db_dependent/Biblio/Diff/diff.t >+++ b/t/db_dependent/Biblio/Diff/diff.t >@@ -230,4 +230,48 @@ sub biblioDiffUndefIndexes { > t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); > } > >+ >+ >+subtest "Grep changes", \&grepChanges; >+sub grepChanges { >+ my $testContext = {}; >+ eval { >+ my $records = t::db_dependent::Biblio::Diff::localRecords::create($testContext); >+ my @recKeys = sort(keys(%$records)); >+ >+ my $diff = C4::Biblio::Diff->new( >+ {excludedFields => ['999', '942', '952']}, >+ $records->{ $recKeys[0] }, >+ $records->{ $recKeys[1] }, >+ $records->{ $recKeys[2] }, >+ ); >+ my $d = $diff->diffRecords(); >+ >+ my $changes = C4::Biblio::Diff::grepChangedElements($d, [{f=>'020', sf=>'a'}, >+ {f=>'041', sf=>'a'}, >+ {f=>'003'}]); >+ is(@$changes, 5, "Got five separate changes"); >+ ok(blessed($changes->[0]) && $changes->[0]->isa('C4::Biblio::Diff::Change'), "Change is of correct type"); >+ is($changes->[0]->getFieldCode, '020', "Field"); >+ is($changes->[0]->getSubfieldCode, 'a', "Subfield"); >+ is($changes->[0]->getVal(0), '9510108303', "Val1"); >+ is($changes->[0]->getVal(1), '9510108304', "Val2"); >+ is($changes->[0]->getVal(2), '9510108305', "Val3"); >+ ok(blessed($changes->[4]) && $changes->[4]->isa('C4::Biblio::Diff::Change'), "Change is of correct type"); >+ is($changes->[4]->getFieldCode, '003', "Field"); >+ is($changes->[4]->getSubfieldCode, undef, "No subfield"); >+ is($changes->[4]->getVal(0), 'KYYTI', "Val1"); >+ is($changes->[4]->getVal(1), 'OUTI', "Val2"); >+ is($changes->[4]->getVal(2), undef, "Val3"); >+ >+ >+ }; >+ if ($@) { >+ ok(0, $@); >+ } >+ t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); >+} >+ >+ >+ > done_testing(); >\ No newline at end of file >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15996
:
48743
| 56274