package EPrints::Plugin::Screen::EPMC::ReCollect; @ISA = qw( EPrints::Plugin::Screen::EPMC ); use strict; sub new { my( $class, %params ) = @_; my $self = $class->SUPER::new( %params ); $self->{actions} = [qw( enable disable )]; $self->{disable} = 0; # always enabled, even in lib/plugins $self->{package_name} = "recollect"; return $self; } sub action_enable { my( $self, $skip_reload ) = @_; $self->SUPER::action_enable( 1 ); my $data_collection_workflow = ' removed for now Research Funders Time period Help text here Geographic location Enter if applicable the Longitude and Latitude values of a theoretical geographic bounding rectangle that would cover the region in which your data were collected. You can use Original Publication Details '; my $repo = $self->{repository}; my $xml = $repo->xml; my $filename = $repo->config( "config_path" )."/workflows/eprint/default.xml"; EPrints::XML::add_to_xml( $filename, $data_collection_workflow, $self->{package_name} ); my $dom = $xml->parse_file( $filename ); my @flow = $dom->getElementsByTagName("flow"); my $flow_elements = $xml->create_document_fragment(); foreach my $element ($flow[0]->childNodes()){ $element->unbindNode(); $flow_elements->appendChild($element); } my $choose_statement = $xml->create_element("epc:choose", required_by=>"recollect", id=>"recollect_choose"); $flow[0]->appendChild($choose_statement); my $when_statement = $xml->create_element("epc:when", test=>"type = 'data_collection'"); $choose_statement->appendChild($when_statement); $when_statement->appendChild($xml->create_element("stage", ref=>"recollect_files")); $when_statement->appendChild($xml->create_element("stage", ref=>"data_collection")); $when_statement->appendChild($xml->create_element("stage", ref=>"subjects")); my $otherwise_statement = $xml->create_element("epc:otherwise"); $choose_statement->appendChild($otherwise_statement); $otherwise_statement->appendChild($flow_elements); open( FILE, ">", $filename ); print FILE $xml->to_string($dom, indent=>1); close( FILE ); my $namedset; $namedset = EPrints::NamedSet->new( "licenses", repository => $repo ); $namedset->add_option( "odc_by", $self->{package_name} ); $namedset->add_option( "odc_odbl", $self->{package_name} ); $namedset->add_option( "odc_dbcl", $self->{package_name} ); $self->reload_config if !$skip_reload; } sub action_disable { my( $self, $skip_reload ) = @_; $self->SUPER::action_disable( 1 ); my $repo = $self->{repository}; my $xml = $repo->xml; my $filename = $repo->config( "config_path" )."/workflows/eprint/default.xml"; my $dom = $xml->parse_file( $filename ); my $choose; my @choices = $dom->getElementsByTagName("choose"); foreach my $element (@choices) { if($element->hasAttribute("required_by") && $element->getAttribute("required_by") eq $self->{package_name}) { $choose = $element; last; } } if(defined $choose) { my $choose_parent = $choose->parentNode; #probably the flow element but err on the side of caution my @otherwise = $choose->getElementsByTagName("otherwise"); foreach my $element ($otherwise[0]->childNodes()){ $element->unbindNode(); $choose_parent->appendChild($element); } open( FILE, ">", $filename ); print FILE $xml->to_string($dom, indent=>1); close( FILE ); } EPrints::XML::remove_package_from_xml( $filename, $self->{package_name} ); $dom = $xml->parse_file( $filename ); open( FILE, ">", $filename ); print FILE $xml->to_string($dom, indent=>1); close( FILE ); my $namedset; $namedset = EPrints::NamedSet->new( "licenses", repository => $repo ); $namedset->remove_option( "odc_by", $self->{package_name} ); $namedset->remove_option( "odc_odbl", $self->{package_name} ); $namedset->remove_option( "odc_dbcl", $self->{package_name} ); $self->reload_config if !$skip_reload; } 1;