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

Templates carry over putcodes #49

Closed
dennmuel opened this issue Jul 12, 2019 · 6 comments · Fixed by #50
Closed

Templates carry over putcodes #49

dennmuel opened this issue Jul 12, 2019 · 6 comments · Fixed by #50

Comments

@dennmuel
Copy link
Contributor

dennmuel commented Jul 12, 2019

When using an exported item as a template for another item, the putcodes in the creators table are carried over. They must be deleted in order to prevent conflicts in import & export.
The problem is, that the he pre-commit trigger re-adds the putcode even after it has been deleted. Can the trigger somehow detect, whether it's handling a template and then not carry over the putcode? (@wfyson)

@wfyson
Copy link
Collaborator

wfyson commented Jul 15, 2019

Unfortunately I don't think there is a way of knowing one item is a template copy of another. The "New version" button creates a copy where the "succeeds" field links the new item to the old one, but the "Use as template" button just creates a copy.

Ultimately we need to rethink the way metadata about ORCIDs is stored and created so we also know where ORCIDs have come from. Therefore this may be something to think about with respect to eprints/orcid_support#25.

@wfyson
Copy link
Collaborator

wfyson commented Jul 15, 2019

However, I've just remembered, I think we can stop some fields from being copied when making a template, using the "can_clone" parameter in a field definition, e.g.

        @{$field->{fields}} = (@{$field->{fields}}, (
            {
                sub_name => 'putcode',
                type => 'text',
                allow_null => 1,
                show_in_html => 0, #we don't need this field to appear in the workflow
                export_as_xml => 0, #nor do we want it appearing in exports
                can_clone => 0, #don't copy when using item as a template
            }
        )); 

@dennmuel
Copy link
Contributor Author

Thanks for the quick reply, I'll give that a try. Alternatively we could change the template function like this, in order to remove putcodes and setting orcid_update to 1, so that the pre-commit trigger doesn't touch the putcodes at all.

sub action_use_as_template
{
	my( $self ) = @_;

	my $inbox_ds = $self->{session}->get_archive()->get_dataset( "inbox" );
	my $copy = $self->{processor}->{eprint}->clone( $inbox_ds, 0, 1 );
	$copy->set_value( "userid", $self->{session}->current_user->get_value( "userid" ) );

    # remove putcodes
    foreach my $role (@{$self->{repository}->config( "orcid","eprint_fields" )})
    {
        my @new_contributors;
        my $contributors = $copy->get_value("$role");
        foreach my $c (@{$contributors})
        {
            my $new_c = $c;
            $new_c->{putcode} = undef;
            push @new_contributors, $new_c;
        }
        $copy->set_value( $role, \@new_contributors );
    }

    $copy->{orcid_update} = 1;
	$copy->commit();

	$self->{processor}->add_message( "message",
		$self->html_phrase( "success" ) );

	$self->{processor}->{eprint} = $copy;
	$self->{processor}->{eprintid} = $copy->get_id;
}

@wfyson
Copy link
Collaborator

wfyson commented Jul 15, 2019

My concern with the above is that action_use_as_template defined in a screen in the EPrints core and therefore isn't an ideal thing for a Bazaar plugin to be overriding as we don't know how this screen is used across other repositories that may be using the plugin (ideally Bazaar plugins should really just add new functionality rather than change existing functionality).

@dennmuel
Copy link
Contributor Author

dennmuel commented Jul 15, 2019

I absolutely agree. I just happened to find this solution (or rather workaround) at about the same minute you posted yours and wanted to document it in case the "can_clone" didn't work. But it does and clearly is the preferable one! Thanks for your help!

@wfyson
Copy link
Collaborator

wfyson commented Jul 15, 2019

Ha ha, no worries - glad we found a good solution!

dennmuel added a commit to dennmuel/orcid_support_advance that referenced this issue Jul 15, 2019
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

Successfully merging a pull request may close this issue.

2 participants