From 2f1b35ea56f01d05ba187fc8385ab883490c3ad9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 6 Apr 2023 15:57:35 +0200 Subject: [PATCH] Bug 30708: Keep item attributes when editing a new processing Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: BULAC - http://www.bulac.fr/ Signed-off-by: Heather Hernandez Signed-off-by: Laurence Rault Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- Koha/Preservation/Processing.pm | 25 +++++++++++++++++-- .../SettingsProcessingsFormAdd.vue | 20 +++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Koha/Preservation/Processing.pm b/Koha/Preservation/Processing.pm index ee21b727b2..e3c5ef95dc 100644 --- a/Koha/Preservation/Processing.pm +++ b/Koha/Preservation/Processing.pm @@ -46,10 +46,31 @@ sub attributes { my $schema = $self->_result->result_source->schema; $schema->txn_do( sub { - $self->attributes->delete; + my @existing_ids = map { $_->{processing_attribute_id} || () } @$attributes; + if (@existing_ids || !@$attributes) { + $self->attributes->search( + { + ( + # If no attributes passed we delete all the existing ones + @$attributes + ? ( + processing_attribute_id => { + -not_in => \@existing_ids + } + ) + : () + ) + } + )->delete; + } for my $attribute (@$attributes) { - $self->_result->add_to_preservation_processing_attributes($attribute); + my $existing_attribute = $self->attributes->find( $attribute->{processing_attribute_id} ); + if ($existing_attribute) { + $existing_attribute->set($attribute)->store; + } else { + $self->_result ->add_to_preservation_processing_attributes( $attribute ); + } } } ); diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsFormAdd.vue index 14b29cd639..338eb0dcac 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessingsFormAdd.vue @@ -25,6 +25,17 @@
{{ $__("Attributes") }} +
+ {{ + $__( + "Be careful removing attribute to this processing, the items using it will be impacted as well!" + ) + }} +
- keepAttrs + ({ processing_id, ...keepAttrs }) => keepAttrs ) const client = APIClient.preservation @@ -284,3 +294,9 @@ export default { name: "SettingsProcessingsFormAdd", } + + -- 2.39.5