Sha256: 72051bfd327452182dcf68c54c152c198d758d6d415e5a823d5c64aef9313a99

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

namespace :decidim do
  namespace :locales do
    desc "Ensures locales in organizations are in sync with Decidim initializer"
    task sync_all: :environment do
      allowed_locales = Decidim.available_locales.map(&:to_s)
      Decidim::Organization.find_each do |organization|
        print "#{organization.name} uses #{organization.available_locales} with [#{organization.default_locale}] as default"

        orphan = (organization.available_locales - allowed_locales)
        organization.available_locales = organization.available_locales - orphan
        default = organization.default_locale
        organization.default_locale = organization.available_locales.first unless organization.available_locales.include? default
        if default != organization.default_locale || orphan.present?
          organization.save!
          puts " [FIXED]"
        else
          puts " [OK]"
        end
      end
    end

    desc "Rebuilds the search index"
    task rebuild_search: :environment do
      Decidim::SearchableResource.destroy_all
      total = Decidim::Searchable.searchable_resources.count
      Decidim::Searchable.searchable_resources.values.each.with_index(1) do |klass, index|
        print "Indexing #{index}/#{total} #{klass}"
        klass.find_each(&:try_update_index_for_search_resource)
        puts " [DONE]"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.29.1 lib/tasks/decidim_locales_tasks.rake
decidim-core-0.29.0 lib/tasks/decidim_locales_tasks.rake
decidim-core-0.29.0.rc4 lib/tasks/decidim_locales_tasks.rake
decidim-core-0.29.0.rc3 lib/tasks/decidim_locales_tasks.rake
decidim-core-0.29.0.rc2 lib/tasks/decidim_locales_tasks.rake
decidim-core-0.29.0.rc1 lib/tasks/decidim_locales_tasks.rake