From e636f61d135e97f3c253cbe7f23e115a8f160be1 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Fri, 12 Oct 2018 00:33:23 +0200 Subject: [PATCH] Add reset_export_projects_counter rake task --- lib/tasks/exportable_items.rake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/tasks/exportable_items.rake b/lib/tasks/exportable_items.rake index c1775d87e..2f9946b6e 100644 --- a/lib/tasks/exportable_items.rake +++ b/lib/tasks/exportable_items.rake @@ -6,4 +6,22 @@ namespace :exportable_items do puts "All exportable zip files older than " \ "'#{num.days.ago}' have been removed" end + + desc 'Resets export project counter to 0' + task reset_export_projects_counter: :environment do + User.all.each do |user| + User.transaction do + begin + user.export_vars['num_of_export_all_last_24_hours'] = 0 + user.save + rescue ActiveRecord::ActiveRecordError, + ArgumentError, + ActiveRecord::RecordNotSaved => e + puts "Error creating user, transaction reverted: #{e}" + end + end + end + puts 'Export project counter successfully ' \ + 'reset on all users' + end end