Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code injected to core module produces 'redefined' warnings #31

Open
jesusbagpuss opened this issue Nov 1, 2023 · 2 comments
Open

Code injected to core module produces 'redefined' warnings #31

jesusbagpuss opened this issue Nov 1, 2023 · 2 comments

Comments

@jesusbagpuss
Copy link
Collaborator

This block:

{
package EPrints::Script::Compiled;
use strict;
sub run_people_with_orcids
{
my( $self, $state, $value ) = @_;
my $session = $state->{session};
my $r = $state->{session}->make_doc_fragment;
my $contributors = $value->[0];
my $field = $value->[1];
my $f = $field->get_property( "fields_cache" );
my $browse_links = {};
my $views = $session->config( "browse_views" );
foreach my $sub_field ( @{$f} )
{
if( defined $sub_field->{browse_link} )
{
my $linkview;
foreach my $view ( @{$views} )
{
$linkview = $view if( $view->{id} eq $sub_field->{browse_link} );
}
$browse_links->{$sub_field->property("sub_name")}->{view} = $linkview;
$browse_links->{$sub_field->property("sub_name")}->{field} = $sub_field;
}
}
foreach my $i ( 0..$#$contributors )
{
my $contributor = @$contributors[$i];
my $url = $session->config( "rel_path" );
my $contributors = $value->[0];
if( $i > 0 )
{
# not first item (or only one item)
if( $i == $#$contributors )
{
# last item
$r->appendChild( $session->make_text( " and " ) );
}
else
{
$r->appendChild( $session->make_text( ", " ) );
}
}
my $person_span = $session->make_element( "span", "class" => "person" );
# only looking for browse_link in the name sub field for now...
if( defined( $browse_links->{name} ) )
{
my $linkview = $browse_links->{name}->{view};
my $sub_field = $browse_links->{name}->{field};
my $link_id = $sub_field->get_id_from_value( $session, $contributor->{name} );
if(
( defined $linkview->{fields} && $linkview->{fields} =~ m/,/ ) ||
( defined $linkview->{menus} && scalar(@{$linkview->{menus}}) > 1 )
)
{
# has sub pages
$url .= "/view/".$sub_field->{browse_link}."/".
EPrints::Utils::escape_filename( $link_id )."/";
}
else
{
# no sub pages
$url .= "/view/".$sub_field->{browse_link}."/".
EPrints::Utils::escape_filename( $link_id ).
".html";
}
my $a = $session->render_link( $url );
$a->appendChild( $session->render_name( $contributor->{name} ) );
$person_span->appendChild( $a );
}
else
{
$person_span->appendChild( $session->render_name( $contributor->{name} ) );
}
my $orcid = $contributor->{orcid};
my $uri = "";
$uri = $session->get_request->uri if defined $session->get_request;
if( $uri !~ m/exportview/ && $uri !~ m!/export_! && $uri !~ m!/cgi/export/! && defined $orcid && $orcid =~ m/^(?:orcid.org\/)?(\d{4}\-\d{4}\-\d{4}\-\d{3}(?:\d|X))$/ )
{
my $orcid_link = $session->make_element( "a",
"class" => "orcid",
"href" => "https://orcid.org/$1",
"target" => "_blank",
);
$orcid_link->appendChild( $session->make_element( "img", "src" => "/images/orcid_id.svg", "class" => "orcid-icon", "alt" => "ORCID logo" ) );
my $orcid_span = $session->make_element( "span", "class" => "orcid-tooltip" );
$orcid_span->appendChild( $session->make_text( "ORCID: " ) );
$orcid_span->appendChild( $session->make_text( "https://orcid.org/$1" ) );
$orcid_link->appendChild( $orcid_span );
$person_span->appendChild( $session->make_text( " " ) );
$person_span->appendChild( $orcid_link );
$person_span->setAttribute( "class", "person orcid-person" );
}
$r->appendChild( $person_span );
}
return [ $r, "XHTML" ];
}
}

when used in a multiple-archive configuration results in:
Subroutine run_people_with_orcids redefined at (eval 2408) line 171.

Possibly move this method to a site_lib or lib file.

@drn05r
Copy link
Contributor

drn05r commented Nov 1, 2023

Hmm, that is a bit worrying as it no suggest their is no isolation between the other archives. When do you see this warning? When you run epadmin test or even when your run epadmin test ARCHIVEID?

However, I agree by default this does not really need to be in the archive level configuration. Most modifications will likely be aesthetic so can be done in CSS. However, for repository that already augment their creators, editors, etc, in citations (e.g. display institutional creators in bold or link to their browse view) they may need to modify this function, although they are probably best of creating a new function to merge this and their existing augmentations, which would probably avoid the 'redefined' issue.

@jesusbagpuss
Copy link
Collaborator Author

jesusbagpuss commented Nov 1, 2023

Yes - from bin/epadmin test and when apache is reloaded, in the error_log.

no isolation between the other archives

NB Under 3.3.16 this is normal I believe. IIRC you (or someone) added some additional segregation to archives/modules in newer versions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants