From b195bd6c8c3f5b7ac5c6c25218429941dd2a1cfb Mon Sep 17 00:00:00 2001 From: David R Newman Date: Thu, 19 Dec 2024 11:57:52 +0000 Subject: [PATCH] Adds Update Coversheet to force recoversheeting of item's documents --- cfg.d/z_coversheet.pl | 2 +- lang/en/phrases/coversheet.xml | 5 + .../Plugin/Screen/EPrint/Staff/Coversheet.pm | 117 ++++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 plugins/EPrints/Plugin/Screen/EPrint/Staff/Coversheet.pm diff --git a/cfg.d/z_coversheet.pl b/cfg.d/z_coversheet.pl index 769be12..75ea86d 100644 --- a/cfg.d/z_coversheet.pl +++ b/cfg.d/z_coversheet.pl @@ -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 diff --git a/lang/en/phrases/coversheet.xml b/lang/en/phrases/coversheet.xml index 2da4de8..2fca4a3 100644 --- a/lang/en/phrases/coversheet.xml +++ b/lang/en/phrases/coversheet.xml @@ -81,6 +81,11 @@ Activate Coversheet Create New Coversheet +Update Coversheet +Force the coversheets to be regenerated on all documents for this item that can be coversheeted. +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. +Could not update coversheets for documents of this item. + Current File: Upload New File: diff --git a/plugins/EPrints/Plugin/Screen/EPrint/Staff/Coversheet.pm b/plugins/EPrints/Plugin/Screen/EPrint/Staff/Coversheet.pm new file mode 100644 index 0000000..2be7cef --- /dev/null +++ b/plugins/EPrints/Plugin/Screen/EPrint/Staff/Coversheet.pm @@ -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; +