Bugzilla – Attachment 183814 Details for
Bug 40309
New authority framework plugin for MARC21 (marc21_field_082a_authorities.pl)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40309: add new Authority Framework plugin for MARC21 082$a
Bug-40309-add-new-Authority-Framework-plugin-for-M.patch (text/plain), 6.74 KB, created by
Andreas Roussos
on 2025-07-07 00:18:52 UTC
(
hide
)
Description:
Bug 40309: add new Authority Framework plugin for MARC21 082$a
Filename:
MIME Type:
Creator:
Andreas Roussos
Created:
2025-07-07 00:18:52 UTC
Size:
6.74 KB
patch
obsolete
>From 29c52d8c6e857fa4086f130ab0d436b045835863 Mon Sep 17 00:00:00 2001 >From: Andreas Roussos <a.roussos@dataly.gr> >Date: Mon, 7 Jul 2025 03:01:04 +0300 >Subject: [PATCH] Bug 40309: add new Authority Framework plugin for MARC21 > 082$a > >This Authority Framework plugin should be attached to MARC21 authority >subfield 082$a, which will then allow the cataloguer to lookup a single >DDC in exchange for a Dewey Linked Data URL that will be copied to >subfield 082$1. > >Test plan: > >1) Go to Administration > Authority types, and for each authtype > associate subfield 082$a with the marc21_field_082a_authorities.pl > plugin. > >2) Create a new authority, or edit an existing one. Click on the > 'Tag editor' button on the far right of the 082$a subfield. > Experiment with the behaviour of the plugin when no DDC has > been filled in, or when an erroneous DDC has been filled in. > Monitor your browser's JavaScript console for warnings/errors > (there shouldn't be any!). > >3) Experiment with changing the values of the related System > Preferences (found under the 'OCLC Dewey Linked Data API' > heading) and seeing how it affects the behaviour of the > plugin. >--- > .../marc21_field_082a_authorities.pl | 161 ++++++++++++++++++ > 1 file changed, 161 insertions(+) > create mode 100755 cataloguing/value_builder/marc21_field_082a_authorities.pl > >diff --git a/cataloguing/value_builder/marc21_field_082a_authorities.pl b/cataloguing/value_builder/marc21_field_082a_authorities.pl >new file mode 100755 >index 0000000000..cd07e9f7a0 >--- /dev/null >+++ b/cataloguing/value_builder/marc21_field_082a_authorities.pl >@@ -0,0 +1,161 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Copyright (C) 2025 Dataly Tech >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use C4::Auth qw( check_cookie_auth get_template_and_user ); >+use C4::Context qw( preference ); >+use C4::Output qw( output_html_with_http_headers ); >+ >+use Koha::Caches; >+use Koha::ExternalContent::OCLC; >+ >+use CGI qw( -utf8 ); >+use JSON qw( from_json ); >+use LWP::UserAgent; >+ >+use YAML; >+ >+my $input = CGI->new; >+my ($auth_status) = >+ check_cookie_auth( $input->cookie('CGISESSID'), { catalogue => 1 } ); >+if ( $auth_status ne "ok" ) { >+ print $input->header( -type => 'text/plain', -status => '403 Forbidden' ); >+ exit 0; >+} >+ >+my $builder = sub { >+ my ($params) = @_; >+ >+ my $function_name = $params->{id}; >+ >+ my $ddcregex = '^((T([1-6])--([0-9]+)))$|^([0-9]{3})$|^(([0-9]{3})\.([0-9]+))$'; >+ >+ my $res = " >+<script> >+ function Click$function_name(event) { >+ event.preventDefault(); >+ >+ const ddcregex = /$ddcregex/; >+ >+ const subfield_a = document.getElementById(event.data.id); >+ const subfield_1 = subfield_a.closest(\".sortable_subfield\").querySelector(\"li[id^=subfield0821] input[id^=tag_082_subfield_1_]\"); >+ >+ subfield_1.style.transition = \"background-color 1000ms linear\"; >+ >+ if ( ! subfield_a.value ) { >+ updateContent( subfield_1, \"No DDC number provided\" ); >+ return 1; >+ } else if ( ! ddcregex.test(subfield_a.value) ) { >+ updateContent( subfield_1, \"Invalid DDC number provided in subfield \$a\" ); >+ return 1; >+ } >+ >+ const url = \"../cataloguing/plugin_launcher.pl?plugin_name=marc21_field_082a_authorities.pl&ddc=\" + subfield_a.value; >+ var request = \$.get(url); >+ >+ request.done( function(response) { >+ const failregex = />Access denied/; >+ if ( failregex.test(response) ) { >+ updateContent( subfield_1, \"Access denied, you need at least the \\\"catalogue\\\" and \\\"editauthorities\\\" user permissions\" ); >+ return 1; >+ } else { >+ updateContent( subfield_1, response ); >+ } >+ return 0; >+ }); >+ } >+ >+ // Credit to: https://stackoverflow.com/a/62468495 >+ function updateContent( element, content ) { >+ // update content >+ element.value = content; >+ // change the background color (will trigger the CSS configured transition) >+ element.style.backgroundColor = \"yellow\"; >+ // change the background color back (with a delay equal to transition length) >+ setTimeout(() => { element.style.backgroundColor = \"white\"; }, 2000); >+ } >+</script> >+"; >+ return $res; >+}; >+ >+my $launcher = sub { >+ my ($params) = @_; >+ my $input = $params->{cgi}; >+ my $ddc_number = $input->param('ddc'); >+ >+ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "cataloguing/value_builder/ajax.tt", >+ query => $input, >+ type => "intranet", >+ flagsrequired => { editauthorities => 1 }, >+ } >+ ); >+ >+ my $ret; >+ my $msg; >+ >+ my $enabled = C4::Context->preference('OCLCDeweyLinkedDataAPI') ? 1 : 0; >+ if ( not $enabled ) { >+ $ret = 'Please enable the OCLCDeweyLinkedDataAPI System Preference in order to use this Framework Plugin'; >+ } >+ >+ my $access_token; >+ if ( not $ret ) { >+ my $scope = 'deweyLinkedData'; >+ >+ ( $access_token, $msg ) = Koha::ExternalContent::OCLC->get_access_token( >+ { >+ scope => $scope, >+ } >+ ); >+ if ( not $access_token ) { >+ $ret = "Cannot obtain API token ($msg)"; >+ } >+ } >+ >+ if ( not $ret ) { >+ >+ # Trim leading 'T' (uppercase 't') from DDC number before looking it up >+ my $ddc_lookup = $ddc_number =~ s/^T//r; >+ >+ my $ddc_url; >+ ( $ddc_url, $msg ) = Koha::ExternalContent::OCLC->get_ddc_url( >+ { >+ access_token => $access_token, >+ ddc_number => $ddc_lookup >+ } >+ ); >+ if ( not $ddc_url and $msg eq 'Unauthorized' ) { >+ $ret = 'The API access token has expired'; >+ } elsif ( $ddc_url eq '' ) { >+ $ret = "No Dewey Linked Data URL found for DDC '$ddc_number'"; >+ } else { >+ $ret = $ddc_url; >+ } >+ } >+ >+ $template->param( return => $ret ); >+ output_html_with_http_headers $input, $cookie, $template->output; >+ >+}; >+ >+return { builder => $builder, launcher => $launcher }; >-- >2.39.5
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 40309
: 183814