Bugzilla – Attachment 61682 Details for
Bug 18269
Move field mappings related code to Koha::FieldMapping[s]
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18269: Move field mappings related code to Koha::FieldMapping[s]
Bug-18269-Move-field-mappings-related-code-to-Koha.patch (text/plain), 8.48 KB, created by
Nick Clemens
on 2017-03-29 14:35:49 UTC
(
hide
)
Description:
Bug 18269: Move field mappings related code to Koha::FieldMapping[s]
Filename:
MIME Type:
Creator:
Nick Clemens
Created:
2017-03-29 14:35:49 UTC
Size:
8.48 KB
patch
obsolete
>From 2c9457b7a2fd01bde3ff450a5456ccaf9457b656 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 13 Mar 2017 18:17:13 -0300 >Subject: [PATCH] Bug 18269: Move field mappings related code to > Koha::FieldMapping[s] >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >The 3 subroutines GetFieldMapping, SetFieldMapping and >DeleteFieldMapping from the C4::Biblio module were only used from the >field mappings admin page. >They can easily replaced with new packages Koha::FieldMappings based on >Koha::Object[s] > >Test plan: >Add and delete field mappings (admin/fieldmapping.pl, Home ⺠>Administration ⺠Keyword to MARC mapping). >Add an existing mapping > Nothing should be added > >Note that this page has not been rewritten and you will not get any >feedbacks, but it's not the goal of this page to improve it. > >Followed test plan, works as expected. >Signed-off-by: Marc Véron <veron@veron.ch> > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > C4/Biblio.pm | 63 ---------------------- > admin/fieldmapping.pl | 46 ++++++++-------- > .../prog/en/modules/admin/fieldmapping.tt | 11 ++-- > t/db_dependent/Charset.t | 2 +- > 4 files changed, 31 insertions(+), 91 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 07f2b16..4b33d9a 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -72,9 +72,6 @@ BEGIN { > GetBiblionumberFromItemnumber > > &GetRecordValue >- &GetFieldMapping >- &SetFieldMapping >- &DeleteFieldMapping > > &GetISBDView > >@@ -686,66 +683,6 @@ sub GetRecordValue { > return \@result; > } > >-=head2 SetFieldMapping >- >- SetFieldMapping($framework, $field, $fieldcode, $subfieldcode); >- >-Set a Field to MARC mapping value, if it already exists we don't add a new one. >- >-=cut >- >-sub SetFieldMapping { >- my ( $framework, $field, $fieldcode, $subfieldcode ) = @_; >- my $dbh = C4::Context->dbh; >- >- my $sth = $dbh->prepare('SELECT * FROM fieldmapping WHERE fieldcode = ? AND subfieldcode = ? AND frameworkcode = ? AND field = ?'); >- $sth->execute( $fieldcode, $subfieldcode, $framework, $field ); >- if ( not $sth->fetchrow_hashref ) { >- my @args; >- $sth = $dbh->prepare('INSERT INTO fieldmapping (fieldcode, subfieldcode, frameworkcode, field) VALUES(?,?,?,?)'); >- >- $sth->execute( $fieldcode, $subfieldcode, $framework, $field ); >- } >-} >- >-=head2 DeleteFieldMapping >- >- DeleteFieldMapping($id); >- >-Delete a field mapping from an $id. >- >-=cut >- >-sub DeleteFieldMapping { >- my ($id) = @_; >- my $dbh = C4::Context->dbh; >- >- my $sth = $dbh->prepare('DELETE FROM fieldmapping WHERE id = ?'); >- $sth->execute($id); >-} >- >-=head2 GetFieldMapping >- >- GetFieldMapping($frameworkcode); >- >-Get all field mappings for a specified frameworkcode >- >-=cut >- >-sub GetFieldMapping { >- my ($framework) = @_; >- my $dbh = C4::Context->dbh; >- >- my $sth = $dbh->prepare('SELECT * FROM fieldmapping where frameworkcode = ?'); >- $sth->execute($framework); >- >- my @return; >- while ( my $row = $sth->fetchrow_hashref ) { >- push @return, $row; >- } >- return \@return; >-} >- > =head2 GetBiblioData > > $data = &GetBiblioData($biblionumber); >diff --git a/admin/fieldmapping.pl b/admin/fieldmapping.pl >index 75fd892..631e7d4 100755 >--- a/admin/fieldmapping.pl >+++ b/admin/fieldmapping.pl >@@ -1,5 +1,6 @@ > #!/usr/bin/perl > # Copyright 2009 SARL BibLibre >+# Copyright 2017 Koha Development Team > # > # This file is part of Koha. > # >@@ -16,15 +17,14 @@ > # You should have received a copy of the GNU General Public License > # along with Koha; if not, see <http://www.gnu.org/licenses>. > >-use strict; >-use warnings; >+use Modern::Perl; > use CGI qw ( -utf8 ); > use C4::Auth; > use C4::Biblio; >-use C4::Koha; > use C4::Output; > > use Koha::BiblioFrameworks; >+use Koha::FieldMappings; > > my $query = new CGI; > >@@ -35,34 +35,36 @@ my $subfieldcode = $query->param('marcsubfield'); > my $op = $query->param('op') || q{}; > my $id = $query->param('id'); > >-my ($template, $loggedinuser, $cookie) >- = get_template_and_user({template_name => "admin/fieldmapping.tt", >- query => $query, >- type => "intranet", >- authnotrequired => 0, >- flagsrequired => {parameters => 'parameters_remaining_permissions'}, >- debug => 1, >- }); >- >-if($op eq "delete" and $id){ >- DeleteFieldMapping($id); >- print $query->redirect("/cgi-bin/koha/admin/fieldmapping.pl?framework=".$frameworkcode); >- exit; >-} >+my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "admin/fieldmapping.tt", >+ query => $query, >+ type => "intranet", >+ authnotrequired => 0, >+ flagsrequired => { parameters => 'parameters_remaining_permissions' }, >+ debug => 1, >+ } >+); > >-# insert operation >-if($field and $fieldcode){ >- SetFieldMapping($frameworkcode, $field, $fieldcode, $subfieldcode); >+# FIXME Add exceptions >+if ( $op eq "delete" and $id ) { >+ Koha::FieldMappings->find($id)->delete; >+} elsif ( $field and $fieldcode ) { >+ my $params = { frameworkcode => $frameworkcode, field => $field, fieldcode => $fieldcode, subfieldcode => $subfieldcode }; >+ my $exists = Koha::FieldMappings->search( $params )->count;; >+ unless ( $exists ) { >+ Koha::FieldMapping->new( $params )->store; >+ } > } > >-my $fieldloop = GetFieldMapping($frameworkcode); >+my $fields = Koha::FieldMappings->search({ frameworkcode => $frameworkcode }); > > my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); > my $framework = $frameworks->search( { frameworkcode => $frameworkcode } )->next; > $template->param( > frameworks => $frameworks, > framework => $framework, >- fields => $fieldloop, >+ fields => $fields, > ); > > output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt >index fed90a9..d182750 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt >@@ -24,9 +24,9 @@ $(document).ready(function() { > <div id="yui-main"> > <div class="yui-b"> > <h2>Keyword to MARC mapping</h2> >- [% UNLESS ( fields ) %] >- <div class="dialog message"><p>There are no mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework. </p></div> >- [% END %] >+ [% UNLESS ( fields.count ) %] >+ <div class="dialog message"><p>There are no mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework. </p></div> >+ [% END %] > <form method="get" action="/cgi-bin/koha/admin/fieldmapping.pl" id="selectframework"> > <label for="framework">Framework:</label> > <select name="framework" id="framework" style="width:20em;"> >@@ -58,7 +58,8 @@ $(document).ready(function() { > </fieldset> > </form> > >- [% IF ( fields ) %]<table> >+ [% IF ( fields.count ) %] >+ <table> > <caption>Mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework</caption> > <tr> > <th>Field</th> >@@ -71,7 +72,7 @@ $(document).ready(function() { > <td>[% field.field %]</td> > <td>[% field.fieldcode %]</td> > <td>[% field.subfieldcode %]</td> >- <td><a class="btn btn-default btn-xs" href="?op=delete&id=[% field.id %]&framework=[% field.framework %]"><i class="fa fa-trash"></i> Delete</a></td> >+ <td><a class="btn btn-default btn-xs" href="?op=delete&id=[% field.id %]&framework=[% field.frameworkcode %]"><i class="fa fa-trash"></i> Delete</a></td> > </tr> > [% END %] > </table>[% END %] >diff --git a/t/db_dependent/Charset.t b/t/db_dependent/Charset.t >index 9a48aef..ea649ae 100644 >--- a/t/db_dependent/Charset.t >+++ b/t/db_dependent/Charset.t >@@ -2,7 +2,7 @@ use Modern::Perl; > use Test::More tests => 4; > use MARC::Record; > >-use C4::Biblio qw( AddBiblio SetFieldMapping GetMarcFromKohaField ); >+use C4::Biblio qw( AddBiblio GetMarcFromKohaField ); > use C4::Context; > use C4::Charset qw( SanitizeRecord ); > >-- >2.1.4
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 18269
:
61091
|
61092
|
61093
|
61094
|
61681
| 61682