From 578f3459817d3a41a6a4c69b15e73522c2dbdb91 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/ --- 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 ee21b727b2e..e3c5ef95dc0 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 14b29cd639b..338eb0dcacc 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.25.1