Skip to content

Instantly share code, notes, and snippets.

@ozzyaaron
Created November 28, 2011 13:26
Show Gist options
  • Save ozzyaaron/1400389 to your computer and use it in GitHub Desktop.
Save ozzyaaron/1400389 to your computer and use it in GitHub Desktop.
class BulkActivityUpdate < Struct.new(:uuid, :user, :farm, :season, :task)
def perform
activities = Activity.with_permission_to(:update, { :user => user, :scope => farm })
case task
when :refresh_pricing, :assign_missing_pricing
activities = activities.joins(:activity_paddocks).where(["activity_paddocks.planned_season_id = ?", season.id])
activities.each { |activity| activity.refresh_pricing(task == :refresh_pricing) } # Force the refresh if :refresh_pricing
when :auto_assign_season
activities.joins(:activity_paddocks).where("activity_paddocks.planned_season_id is null").each do |activity_paddock|
if activity_paddock.paddock && activity_paddock.paddock.current_planned_season
activity_paddock.update_attribute(:planned_season, activity_paddock.paddock.current_planned_season)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment