From eaba43d8f1cf6b03b5e09a3451553e01462897e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 1 Nov 2016 11:54:38 +0100 Subject: [PATCH] Allow destroying a custom field even with invalid cost reports Fixes https://community.openproject.com/work_packages/24184 --- .../patches/custom_fields_controller_patch.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/open_project/reporting/patches/custom_fields_controller_patch.rb b/lib/open_project/reporting/patches/custom_fields_controller_patch.rb index d595737902..46df37498f 100644 --- a/lib/open_project/reporting/patches/custom_fields_controller_patch.rb +++ b/lib/open_project/reporting/patches/custom_fields_controller_patch.rb @@ -34,13 +34,17 @@ module OpenProject::Reporting::Patches def destroy_with_custom_fields id = @custom_field.id - - reports = CostQuery.where("serialized LIKE '%CustomField#{id}%'") - - remove_custom_field_from_cost_report(reports, id) - remove_custom_field_from_session(id) - - destroy_without_custom_fields + begin + reports = CostQuery.where("serialized LIKE '%CustomField#{id}%'") + + remove_custom_field_from_cost_report(reports, id) + remove_custom_field_from_session(id) + rescue => e + Rails.logger.error "Failed to remove custom_field #{id} from custom queries. " \ + "#{e.class}: #{e.message}" + ensure + destroy_without_custom_fields + end end private