Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

really delete cached attachments

Markus Kahl39d455752347
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 2d4ce1dbbaa..db409e877ce 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -285,6 +285,19 @@ class Attachment < ApplicationRecord
end
end
+ ##
+ # Deletes locally cached files. This is mostly relevant for remote attachments
+ # but would also apply for local attachments if things such as carrierwave
+ # filters were used.
+ #
+ # @param age_in_seconds [Integer] Delete all cached files older than this many seconds.
+ def self.clean_cached_files!(age_in_seconds: 60 * 60 * 24)
+ uploader = OpenProject::Configuration.file_uploader
+ cache_storage = uploader.cache_storage
+
+ cache_storage.new(uploader.new).clean_cache! age_in_seconds
+ end
+
def pending_direct_upload?
digest == "" && downloads == -1
end
diff --git a/lib/tasks/attachments.rake b/lib/tasks/attachments.rake
index 79bdd1ba1a9..ad68151f468 100644
--- a/lib/tasks/attachments.rake
+++ b/lib/tasks/attachments.rake
@@ -31,7 +31,7 @@
namespace :attachments do
desc 'Clear all attachments created before yesterday'
task clear: [:environment] do
- CarrierWave.clean_cached_files!
+ Attachment.clean_cached_files!
end
desc 'Copies all attachments from the current to the given storage.'