Created
November 28, 2011 13:26
-
-
Save ozzyaaron/1400389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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