Sha256: 6e0f1375609c30846313c45debc84e419dbd216f1074698af12ac6b9c3a4e46e

Contents?: true

Size: 1.07 KB

Versions: 34

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

namespace :decidim_comments do
  desc "Adds participatory_process_id to comments if they are associated with a participatory process"
  task update_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

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
decidim-comments-0.28.4 lib/tasks/decidim_comments.rake
decidim-comments-0.27.9 lib/tasks/decidim_comments.rake
decidim-comments-0.28.3 lib/tasks/decidim_comments.rake
decidim-comments-0.27.8 lib/tasks/decidim_comments.rake
decidim-comments-0.28.2 lib/tasks/decidim_comments.rake
decidim-comments-0.27.7 lib/tasks/decidim_comments.rake
decidim-comments-0.28.1 lib/tasks/decidim_comments.rake
decidim-comments-0.27.6 lib/tasks/decidim_comments.rake
decidim-comments-0.26.10 lib/tasks/decidim_comments.rake
decidim-comments-0.26.9 lib/tasks/decidim_comments.rake
decidim-comments-0.28.0 lib/tasks/decidim_comments.rake
decidim-comments-0.27.5 lib/tasks/decidim_comments.rake
decidim-comments-0.28.0.rc5 lib/tasks/decidim_comments.rake
decidim-comments-0.28.0.rc4 lib/tasks/decidim_comments.rake
decidim-comments-0.26.8 lib/tasks/decidim_comments.rake
decidim-comments-0.27.4 lib/tasks/decidim_comments.rake
decidim-comments-0.27.3 lib/tasks/decidim_comments.rake
decidim-comments-0.26.7 lib/tasks/decidim_comments.rake
decidim-comments-0.26.5 lib/tasks/decidim_comments.rake
decidim-comments-0.27.2 lib/tasks/decidim_comments.rake