Sha256: 788206b2927925bdc3071939c45b0d071fdf48c3e3054232bd5febf290cfe079

Contents?: true

Size: 750 Bytes

Versions: 13

Compression:

Stored size: 750 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Surveys
    class CleanSurveyAnswersJob < ApplicationJob
      def perform(_event_name, data)
        @component = data[:resource]
        return unless component&.manifest_name == "surveys"

        @survey = Survey.find_by(component:)
        return unless survey&.questionnaire

        case data[:event_class]
        when "Decidim::ComponentPublishedEvent"
          clean_answers
        end
      end

      private

      attr_reader :survey, :component

      def clean_answers
        return unless survey.clean_after_publish?

        survey.questionnaire.answers.destroy_all
        component.settings[:clean_after_publish] = false
        component.save
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-surveys-0.29.1 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.28.4 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.29.0 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.28.3 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.29.0.rc4 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.29.0.rc3 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.29.0.rc2 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.29.0.rc1 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.28.2 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.28.1 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.28.0 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.28.0.rc5 app/jobs/decidim/surveys/clean_survey_answers_job.rb
decidim-surveys-0.28.0.rc4 app/jobs/decidim/surveys/clean_survey_answers_job.rb