Additiopnal code to deal with document pos when merging EPrints.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Based on EPrints::DataObj::Document::clone | |
| # NB Code duplication with Symplectic::RepoProcess::MergeManager | |
| # | |
| # Cloning documents can result in: | |
| # - two documents with the same 'pos' field - and therefore sharing the same folder | |
| # - 'spaces' in the document structure (e.g. pos=1 and pos=3, but no pos=2) | |
| # this isn't what is needed. The code below manages these scenarios. | |
| # EPrints' default behaviour is to remove the 'pos' during a clone *only* when the doc is being cloned to the same parent. | |
| sub clone_document | |
| { | |
| my ($self, %args ) = @_; | |
| my $eprint = $args{'eprint'}; | |
| my $doc = $args{'doc'}; | |
| my $reset_pos = $args{'reset_pos'}; | |
| my $data = EPrints::Utils::clone( $doc->{data} ); | |
| # cloning within the same eprint, in which case get a new position! | |
| #if( defined $doc->parent && $eprint->id eq $doc->parent->id ) | |
| if( ( defined $doc->parent && $eprint->id eq $doc->parent->id ) || $reset_pos ) | |
| { | |
| $data->{pos} = undef; | |
| } | |
| $data->{eprintid} = $eprint->get_id; | |
| $data->{_parent} = $eprint; | |
| # First create a new doc object | |
| my $new_doc = $doc->{dataset}->create_object( $doc->{session}, $data ); | |
| return undef if !defined $new_doc; | |
| my $ok = 1; | |
| # Copy files | |
| foreach my $file (@{$doc->get_value( "files" )}) | |
| { | |
| $file->clone( $new_doc ) or $ok = 0, last; | |
| } | |
| if( !$ok ) | |
| { | |
| $new_doc->remove(); | |
| return undef; | |
| } | |
| return $new_doc; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment