diff --git a/app/jobs/scheduled/weekly.rb b/app/jobs/scheduled/weekly.rb index 156cfd74e45..9a079efb05e 100644 --- a/app/jobs/scheduled/weekly.rb +++ b/app/jobs/scheduled/weekly.rb @@ -11,6 +11,7 @@ module Jobs Post.calculate_avg_time Topic.calculate_avg_time ScoreCalculator.new.calculate + ExportCsv.remove_old_exports # delete exported CSV files older than 2 days end end end diff --git a/app/models/export_csv.rb b/app/models/export_csv.rb index 214d650de55..ffebf6c1eee 100644 --- a/app/models/export_csv.rb +++ b/app/models/export_csv.rb @@ -9,6 +9,15 @@ class ExportCsv end end + def self.remove_old_exports + dir = Dir.new(ExportCsv.base_directory) + dir.each do |file| + if (File.mtime(File.join(ExportCsv.base_directory, file)) < 2.days.ago) + File.delete(File.join(ExportCsv.base_directory, file)) + end + end + end + def self.base_directory File.join(Rails.root, "public", "uploads", "csv_exports", RailsMultisite::ConnectionManagement.current_db) end