app/jobs/decidim/initiatives/export_initiatives_job.rb in decidim-initiatives-0.24.3 vs app/jobs/decidim/initiatives/export_initiatives_job.rb in decidim-initiatives-0.25.0.rc1

- old
+ new

@@ -1,21 +1,28 @@ # frozen_string_literal: true module Decidim module Initiatives class ExportInitiativesJob < ApplicationJob - queue_as :default + queue_as :exports - def perform(user, format) - export_data = Decidim::Exporters.find_exporter(format).new(collection, serializer).export + def perform(user, organization, format, collection_ids = nil) + export_data = Decidim::Exporters.find_exporter(format).new( + collection_to_export(collection_ids, organization), + serializer + ).export ExportMailer.export(user, "initiatives", export_data).deliver_now end private - def collection - Decidim::Initiative.all + def collection_to_export(ids, organization) + collection = Decidim::Initiative.where(organization: organization) + + collection = collection.where(id: ids) if ids.present? + + collection.order(id: :asc) end def serializer Decidim::Initiatives::InitiativeSerializer end