From 946d54a1a4d72fe04e649cd3843904e17fbb61e3 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Fri, 3 Nov 2023 10:22:04 +0100 Subject: [PATCH] (feat) add rake task fablab:maintenance:delete_all_reservations_and_invoices --- lib/tasks/fablab/maintenance.rake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/tasks/fablab/maintenance.rake b/lib/tasks/fablab/maintenance.rake index 0a1359152..d937379e8 100644 --- a/lib/tasks/fablab/maintenance.rake +++ b/lib/tasks/fablab/maintenance.rake @@ -171,5 +171,22 @@ namespace :fablab do abuse.destroy if abuse.signaled.nil? end end + + desc "Removes all reservations, invoice, invoice_items, chained_elements (of invoices)" + task delete_all_reservations_and_invoices: :environment do + print 'Are you sure you want to erase all reservations and invoices ? (y/n) ' + confirm = $stdin.gets.chomp + next unless confirm == 'y' + + ChainedElement.where(element_type: %w[Invoice InvoiceItem PaymentSchedule PaymentScheduleItem PaymentScheduleObject]).delete_all + Order.destroy_all + PaymentSchedule.destroy_all + PaymentScheduleItem.destroy_all + PaymentScheduleObject.destroy_all + Invoice.destroy_all + Reservation.destroy_all + + FileUtils.rm_rf Dir.glob(Rails.root.join("invoices/*")) + end end end