From 36e55551448608f676969a4f856d8bd3dabe24ae Mon Sep 17 00:00:00 2001
From: Jonathan Druart
Date: Wed, 31 Jan 2024 12:11:10 +0100
Subject: [PATCH] Bug 34478: Add 'op' to opac-tags
There are way more to do in this controller!...
Signed-off-by: Jonathan Druart
---
.../bootstrap/en/modules/opac-detail.tt | 1 +
.../bootstrap/en/modules/opac-tags.tt | 1 +
opac/opac-tags.pl | 86 ++++++++++---------
3 files changed, 47 insertions(+), 41 deletions(-)
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
index fb7cd51139..25342d6efd 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
@@ -251,6 +251,7 @@
+
(done)
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt
index 3130733f19..6c8bf4b18d 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-tags.tt
@@ -178,6 +178,7 @@
[% END %]
+
[% END # /MY_TAGS %]
diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl
index d62977200c..c346417e76 100755
--- a/opac/opac-tags.pl
+++ b/opac/opac-tags.pl
@@ -129,48 +129,52 @@ if ($add_op) {
}
}
-my $scrubber;
-my @newtags_keys = (keys %newtags);
-if (scalar @newtags_keys) {
- $scrubber = C4::Scrubber->new();
- foreach my $biblionumber (@newtags_keys) {
- my $bibResults = {adds=>0, errors=>[]};
- my @values = split /[;,]/, $newtags{$biblionumber};
- foreach (@values) {
- s/^\s*(.+)\s*$/$1/;
- my $clean_tag = $scrubber->scrub($_);
- unless ($clean_tag eq $_) {
- if ($clean_tag =~ /\S/) {
- push @errors, {scrubbed=>$clean_tag};
- push @{$bibResults->{errors}}, {scrubbed=>$clean_tag};
- } else {
- push @errors, {scrubbed_all_bad=>1};
- push @{$bibResults->{errors}}, {scrubbed_all_bad=>1};
- next; # we don't add it if there's nothing left!
- }
- }
- my $result = ($openadds) ?
- add_tag($biblionumber,$clean_tag,$loggedinuser,$loggedinuser) : # pre-approved
- add_tag($biblionumber,$clean_tag,$loggedinuser) ;
- if ($result) {
- $counts{$biblionumber}++;
- $bibResults->{adds}++;
- } else {
- push @errors, {failed_add_tag=>$clean_tag};
- push @{$bibResults->{errors}}, {failed_add_tag=>$clean_tag};
- Koha::Logger->get->warn("add_tag($biblionumber,$clean_tag,$loggedinuser...) returned bad result (" . (defined $result ? $result : 'UNDEF') .")");
- }
- }
- $perBibResults->{$biblionumber} = $bibResults;
- }
-}
+my $op = $query->param('op') || q{};
my $dels = 0;
-foreach (@deltags) {
- if (remove_tag($_,$loggedinuser)) {
- $dels++;
- } else {
- push @errors, {failed_delete=>$_};
- }
+if ( $op eq 'cud-add' ) {
+ my $scrubber;
+ my @newtags_keys = (keys %newtags);
+ if (scalar @newtags_keys) {
+ $scrubber = C4::Scrubber->new();
+ foreach my $biblionumber (@newtags_keys) {
+ my $bibResults = {adds=>0, errors=>[]};
+ my @values = split /[;,]/, $newtags{$biblionumber};
+ foreach (@values) {
+ s/^\s*(.+)\s*$/$1/;
+ my $clean_tag = $scrubber->scrub($_);
+ unless ($clean_tag eq $_) {
+ if ($clean_tag =~ /\S/) {
+ push @errors, {scrubbed=>$clean_tag};
+ push @{$bibResults->{errors}}, {scrubbed=>$clean_tag};
+ } else {
+ push @errors, {scrubbed_all_bad=>1};
+ push @{$bibResults->{errors}}, {scrubbed_all_bad=>1};
+ next; # we don't add it if there's nothing left!
+ }
+ }
+ my $result = ($openadds) ?
+ add_tag($biblionumber,$clean_tag,$loggedinuser,$loggedinuser) : # pre-approved
+ add_tag($biblionumber,$clean_tag,$loggedinuser) ;
+ if ($result) {
+ $counts{$biblionumber}++;
+ $bibResults->{adds}++;
+ } else {
+ push @errors, {failed_add_tag=>$clean_tag};
+ push @{$bibResults->{errors}}, {failed_add_tag=>$clean_tag};
+ Koha::Logger->get->warn("add_tag($biblionumber,$clean_tag,$loggedinuser...) returned bad result (" . (defined $result ? $result : 'UNDEF') .")");
+ }
+ }
+ $perBibResults->{$biblionumber} = $bibResults;
+ }
+ }
+} elsif ( $op eq 'cud-del' ) {
+ foreach (@deltags) {
+ if (remove_tag($_,$loggedinuser)) {
+ $dels++;
+ } else {
+ push @errors, {failed_delete=>$_};
+ }
+ }
}
if ($is_ajax) {
--
2.39.5