Skip to content

Commit

Permalink
Adds Update Coversheet to force recoversheeting of item's documents
Browse files Browse the repository at this point in the history
  • Loading branch information
drn05r committed Dec 19, 2024
1 parent d221289 commit b195bd6
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cfg.d/z_coversheet.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$c->{plugins}{"Screen::Coversheet::Edit"}{params}{disable} = 0;
$c->{plugins}{"Screen::Coversheet::New"}{params}{disable} = 0;
$c->{plugins}{"Screen::EPMC::Coversheet"}{params}{disable} = 0;

$c->{plugins}{"Screen::EPrint::Staff::Coversheet"}{params}{disable} = 0;


# Stores the id of the Coversheet Dataobj that was used to generated the CS'ed document
Expand Down
5 changes: 5 additions & 0 deletions lang/en/phrases/coversheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
<epp:phrase id="Plugin/Screen/Coversheet/Activate:title">Activate Coversheet</epp:phrase>
<epp:phrase id="Plugin/Screen/Coversheet/New:action:create:title">Create New Coversheet</epp:phrase>

<epp:phrase id="Plugin/Screen/EPrint/Staff/Coversheet:action:update:title">Update Coversheet</epp:phrase>
<epp:phrase id="Plugin/Screen/EPrint/Staff/Coversheet:action:update:description">Force the coversheets to be regenerated on all documents for this item that can be coversheeted.</epp:phrase>
<epp:phrase id="Plugin/Screen/EPrint/Staff/Coversheet:updating_coversheet">All documents associated with this item that can be coversheeted have been set to have their coversheets regenerated. It may take some time for this to happen.</epp:phrase>
<epp:phrase id="Plugin/Screen/EPrint/Staff/Coversheet:coversheet_not_updated">Could not update coversheets for documents of this item.</epp:phrase>

<epp:phrase id='current_file'>Current File: </epp:phrase>
<epp:phrase id='upload_file'>Upload New File: </epp:phrase>

Expand Down
117 changes: 117 additions & 0 deletions plugins/EPrints/Plugin/Screen/EPrint/Staff/Coversheet.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package EPrints::Plugin::Screen::EPrint::Staff::Coversheet;

@ISA = ( 'EPrints::Plugin::Screen::EPrint' );

use strict;

sub new
{
my( $class, %params ) = @_;

my $self = $class->SUPER::new(%params);

# $self->{priv} = # no specific priv - one per action

$self->{actions} = [qw/ update /];

$self->{appears} = [ {
place => "eprint_editor_actions",
action => "update",
position => 1982,
}, ];

return $self;
}

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

return $self->could_obtain_eprint_lock;
}

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

$self->EPrints::Plugin::Screen::EPrint::View::about_to_render;
}

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

return 0 unless $self->could_obtain_eprint_lock;

my $repo = $self->repository;
my $eprint = $self->{processor}->{eprint};

my $documents = $eprint->get_all_documents;
my $has_pdf_doc = 0;
foreach my $doc ( $eprint->get_all_documents )
{
if ( $doc->get_value( 'mime_type' ) eq 'application/pdf' )
{
$has_pdf_doc = 1;
last;
}
}

return 0 unless $has_pdf_doc;

return 1;
}


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

return 0 unless $self->could_obtain_eprint_lock;
return $self->allow( "eprint/edit:editor" );
}

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

my $session = $self->{session};
my $eprint = $self->{processor}->{eprint};

foreach my $doc ( $eprint->get_all_documents() )
{
if ( $doc->get_value( 'coversheet_error' ) eq "1" )
{
$doc->set_value( 'coversheet_error', undef );
$doc->commit;
}
}

if ( $eprint->get_value( 'coversheets_dirty' ) ne 'TRUE' )
{
$eprint->set_value( 'coversheets_dirty', 'TRUE' );
$eprint->commit;
}
$self->add_result_message( 1 );
}

sub add_result_message
{
my( $self, $ok ) = @_;

if( $ok )
{
$self->{processor}->add_message( "message",
$self->html_phrase( "updating_coversheet" ) );
}
else
{
$self->{processor}->add_message( "coversheet_not_updated" );
}

$self->{processor}->{screenid} = "EPrint::View";
}


1;

0 comments on commit b195bd6

Please sign in to comment.