From 53e106f2688f8566e8191593fec84216ac6553ae Mon Sep 17 00:00:00 2001 From: Johanna Raisa Date: Thu, 7 Oct 2021 13:58:58 +0300 Subject: [PATCH] Block component parts from broadcast --- Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios.pm | 4 +- .../BroadcastBiblios/Modules/ActiveRecords.pm | 9 +++++ .../BroadcastBiblios/Modules/Broadcast.pm | 13 ++++++ .../cronjobs/runBroadcastBiblios.pl | 40 ++++++++++--------- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios.pm b/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios.pm index 5081e9a..1a5cb2e 100644 --- a/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios.pm +++ b/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios.pm @@ -13,7 +13,7 @@ use Koha::Plugin::Fi::KohaSuomi::BroadcastBiblios::Modules::Broadcast; use Koha::Plugin::Fi::KohaSuomi::BroadcastBiblios::Modules::ActiveRecords; ## Here we set our plugin version -our $VERSION = "1.2.2"; +our $VERSION = "1.2.3"; ## Here is our metadata, some keys are required, some are optional our $metadata = { @@ -59,6 +59,7 @@ sub new { $self->{verbose} = $args->{verbose}; $self->{start_time} = $args->{start_time}; $self->{blocked_encoding_level} = $args->{blocked_encoding_level}; + $self->{block_component_parts} = $args->{block_component_parts}; } @@ -117,6 +118,7 @@ sub run { log_table => $self->{logTable}, start_time => $self->{start_time}, blocked_encoding_level => $self->{blocked_encoding_level}, + block_component_parts => $self->{block_component_parts}, }); my $params = { diff --git a/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/Modules/ActiveRecords.pm b/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/Modules/ActiveRecords.pm index 3664f4b..e5ce3b8 100644 --- a/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/Modules/ActiveRecords.pm +++ b/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/Modules/ActiveRecords.pm @@ -137,4 +137,13 @@ sub checkEncodingLevel { return $encoding_level; } +sub checkComponentPart { + my ($self, $biblio) = @_; + + my $record = MARC::Record::new_from_xml($biblio->{metadata}, 'UTF-8'); + return 1 if $record->subfield('773', "w"); + return 0; +} + + 1; \ No newline at end of file diff --git a/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/Modules/Broadcast.pm b/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/Modules/Broadcast.pm index c73cc0e..fe402b0 100644 --- a/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/Modules/Broadcast.pm +++ b/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/Modules/Broadcast.pm @@ -149,6 +149,18 @@ sub blockByEncodingLevel { return 0; } +sub blockComponentParts { + my ($self, $biblio) = @_; + + my $block = shift->{_params}->{block_component_parts}; + + if ($block) { + return $self->activeRecords()->checkComponentPart($biblio); + } + + return 0; +} + sub broadcastBiblios { my ($self, $params) = @_; @@ -164,6 +176,7 @@ sub broadcastBiblios { my @pusharray; my ($error, $response); foreach my $biblio (@{$biblios}) { + next if $self->blockComponentParts($biblio); next if $self->blockByEncodingLevel($biblio); my $requestparams = $self->getEndpointParameters($biblio); if ($self->getEndpointType eq 'identifier_activation') { diff --git a/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/cronjobs/runBroadcastBiblios.pl b/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/cronjobs/runBroadcastBiblios.pl index c6c294b..0120af3 100755 --- a/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/cronjobs/runBroadcastBiblios.pl +++ b/Koha/Plugin/Fi/KohaSuomi/BroadcastBiblios/cronjobs/runBroadcastBiblios.pl @@ -63,6 +63,7 @@ BEGIN my $inactivity_timeout = 30; my $start_time; my $encoding_level; +my $block_component_parts = 0; GetOptions( 'h|help' => \$help, @@ -84,30 +85,32 @@ BEGIN 'inactivity_timeout:i' => \$inactivity_timeout, 'start_time:i' => \$start_time, 'blocked_encoding_level:s' => \$encoding_level, + 'block_component_parts' => \$block_component_parts, ); my $usage = < $verbose, start_time => $start_time, blocked_encoding_level => $encoding_level, + block_component_parts => $block_component_parts, }); $plugin->run(); \ No newline at end of file