mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-24 01:57:46 -05:00
Add rake task for clean up of old content (#3644)
This commit is contained in:
@@ -77,6 +77,17 @@ module PredictPlanting
|
||||
finish_predicted_at <= Time.zone.today
|
||||
end
|
||||
|
||||
# Deactivate any plantings over time_limit that are super late in small batches.
|
||||
def self.archive!(time_limit: 3.years.ago, limit: 100)
|
||||
active_plantings = Planting.annual.active.where("planted_at < ?", time_limit).order(planted_at: :asc).limit(limit)
|
||||
active_plantings.each do |planting|
|
||||
if planting.finish_is_predicatable? && planting.super_late?
|
||||
planting.finished = true
|
||||
planting.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def calculate_percentage_grown
|
||||
|
||||
@@ -78,6 +78,16 @@ class Garden < ApplicationRecord
|
||||
|
||||
def reindex(refresh: false); end
|
||||
|
||||
# Deactivate any gardens with no active plantings
|
||||
def self.archive!(time_limit: 3.years.ago, limit: 100)
|
||||
Garden.active.where("updated_at < ?", time_limit).order(updated_at: :asc).limit(limit).each do |active_garden|
|
||||
unless active_garden.plantings.active.any?
|
||||
garden.active = false
|
||||
garden.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def strip_blanks
|
||||
|
||||
10
lib/tasks/gardens.rake
Normal file
10
lib/tasks/gardens.rake
Normal file
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
namespace :gardens do
|
||||
|
||||
desc "Mark old gardens inactive"
|
||||
task archive: :environment do
|
||||
Planting.archive!
|
||||
Garden.archive!
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user