Sha256: 2fc5f1eabb78db82d7840220381275ad717de8a3e9dbcccd85afc30840cdb37d

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

namespace :decidim_comments do
  namespace :upgrade do
    desc "Adds participatory_process_id to comments if they are associated with a participatory process"
    task participatory_process_in_comments: :environment do
      puts "Updating comments..."
      ok = errors = 0

      log = ActiveSupport::Logger.new(Rails.root.join("log/update_participatory_process_in_comments.log"))
      Decidim::Comments::Comment.where(participatory_space: nil).find_each do |c|
        c.participatory_space = if c.root_commentable.is_a?(Decidim::Participable)
                                  c.root_commentable
                                else
                                  c.commentable.try(:participatory_space)
                                end
        c.save(validate: false)
        ok += 1
      rescue StandardError => e
        errors += 1
        log.info "Error updating comment ##{c.id}: #{e.message}"
      end

      puts "#{ok} comments updated."
      puts "#{errors} errors found. Check the file 'log/update_participatory_process_in_comments.log' for more information." if errors.positive?
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-comments-0.29.1 lib/tasks/upgrade/decidim_comments.rake
decidim-comments-0.29.0 lib/tasks/upgrade/decidim_comments.rake
decidim-comments-0.29.0.rc4 lib/tasks/upgrade/decidim_comments.rake
decidim-comments-0.29.0.rc3 lib/tasks/upgrade/decidim_comments.rake
decidim-comments-0.29.0.rc2 lib/tasks/upgrade/decidim_comments.rake
decidim-comments-0.29.0.rc1 lib/tasks/upgrade/decidim_comments.rake