Skip to content

Add a task to fix locale issues#6510

Merged
Leusev merged 3 commits intodevelopfrom
feature/fix-locales-tasks
Sep 29, 2020
Merged

Add a task to fix locale issues#6510
Leusev merged 3 commits intodevelopfrom
feature/fix-locales-tasks

Conversation

@microstudi
Copy link
Copy Markdown
Contributor

🎩 What? Why?

In certain cases is necessary to manipulate locales of an organization through the database. This adds a new task namespace and some commands to solve common issues.
It also provides a new documentation file explaining the usage.

📋 Subtasks

  • Add documentation regarding the feature

mrcasals
mrcasals previously approved these changes Sep 9, 2020
Copy link
Copy Markdown
Contributor

@mrcasals mrcasals left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I left a few suggestions

desc "Rebuild the search index"
task rebuild_search: :environment do
Decidim::SearchableResource.destroy_all
Decidim::Searchable.searchable_resources.pluck(0).each do |resource|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Decidim::Searchable.searchable_resources.pluck(0).each do |resource|
Decidim::Searchable.searchable_resources.keys.each do |resource|

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep!

bundle exec rake decidim:locales:sync_all
```

Run this task if you want have changed your `config/initializers/decidim.rb` `available_locales` or `default_locale` and you want to modify all the organizations so they have the same settings.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Run this task if you want have changed your `config/initializers/decidim.rb` `available_locales` or `default_locale` and you want to modify all the organizations so they have the same settings.
Run this task if you want to have changed `available_locales` or `default_locale` in your `config/initializers/decidim.rb` and you want to modify all the organizations so they have the same settings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In here I've rephrase it.

mrcasals
mrcasals previously approved these changes Sep 10, 2020
Copy link
Copy Markdown
Contributor

@mrcasals mrcasals left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

task rebuild_search: :environment do
Decidim::SearchableResource.destroy_all
Decidim::Searchable.searchable_resources.keys.each do |resource|
resource.constantize.all.each(&:try_update_index_for_search_resource)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resource.constantize.all.each(&:try_update_index_for_search_resource)
resource.constantize.find_each(&:try_update_index_for_search_resource)

This is more performant, memory-wise, as it loads the resources in chunks instead of all of them at the same time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the Decidim::Searchable.searchable_resources has the classes as values. I'm not sure if you're constantizing for some specific reason, but the whole block could be changed to this:

      Decidim::Searchable.searchable_resources.values.each do |searchable_klass|
        searchable_klass.find_each(&:try_update_index_for_search_resource)
      end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I don't even remember. I guess I saw the key and my brain executed a return!
Thanks for your insights! I'll make the changes!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prefer, you can just ignore these lastc hangees and keep only the find_each suggestion 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I like it. I'll continue in the afternoon, I have a busy morning.
Thinking out loud, we could add a task to add or remove a language from an organization and perform all the associated task for that organization.

@microstudi
Copy link
Copy Markdown
Contributor Author

@mrcasals in the end, I've refactored a little to show more information when performing the task. Also changed some docs that where wrong. The result of both commands looks like this:
image

Decidim.available_locales is :es, :en, :ca:
image

@mrcasals
Copy link
Copy Markdown
Contributor

@microstudi nice!! Good job!

I've restarted a teest run that failede, looked like some Ruby setup problem

Copy link
Copy Markdown
Contributor

@Leusev Leusev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fantastic for me @microstudi
Liked the idea about what you pointed out about to add some new tasks in order to add or remove a new language, since it is not a rare thing and it has also been requested on some occasion...
Thanks for your job 😄

@Leusev Leusev merged commit 6731a77 into develop Sep 29, 2020
@Leusev Leusev deleted the feature/fix-locales-tasks branch September 29, 2020 07:15
@Leusev Leusev mentioned this pull request Oct 6, 2020
1 task
andreslucena added a commit that referenced this pull request Oct 6, 2020
roxanaopr pushed a commit to i-need-another-coffee/decidim that referenced this pull request Oct 15, 2020
* Add a task to fix locale issues

* spell fixes

* print more information on the console and optimize code
andreslucena added a commit that referenced this pull request Nov 19, 2020
Leusev pushed a commit that referenced this pull request Dec 2, 2020
* Remove Markdown doc

* Add documentation with Antora (AsciiDoc format - .adoc)

Adds sections:
* configure
* customize
* develop
* install
* services

Also adds:
* a README explaining the relationship with the documentation repository
available in https://github.com/decidim/documentation
* antora metadata file so we can build these sections in the same website

* Fix Antora name for docs

* Rename advanced pages to Concerns

* Add Authorizations customize from module's README

* Move 'add_authorizable_action' to 'permissions'

* Move 'adding_fixtures_aka_dummy_content' to 'components'

* Move 'how_to_create_a_module' to 'components'

* Remove 'upgrading', now it's in 'update'

* Install guide: fix error in 'whatever' gem (it's 'whenever')

* Install guide: fix error in RAILS_ENV order in commands

* Install guide: fix command for open_data export

* Install guide: fix link to Contribution guide

* Develop guide: add example apps

* Architecture docs

Add first version of c4model diagrams with PlantUML

* https://c4model.com/
* https://plantuml.com/
* https://github.com/RicardoNiepel/C4-PlantUML

* Add some explanation of modules types (with Components link)

* Configure: ENV VARS and Initializer

This moves ENV VARS configuration docs to its own page.
We also create a new page for explaining Decidim's initializer settings
(config/initializer/decidim.rb). For the moment is mostly a copy paste with
nice formating, but the idea is to expand it.

* Sync "Make maps actually configurable" by @ahukkanen

Extracted from #6340

* Sync "Templates module" by @verarojman

Extracted from #6247

* Sync "Configure Decidim Bulletin Board" by @leio10

Extracted from #6420

* Sync "Add a task to fix locale issues" by @microstudi

Extracted from #6510

* Update versions in SECURITY.adoc

* Convert CONTRIBUTING.md to AsciiDoc

* Convert README.md to AsciiDoc

* Clarify CONTRIBUTING and links to docs site

* Remove Markdown linter CI

* Sync "Update documentation for `decidim` OAuth social provider" by @tramuntanal

Extracted from #6607

* Sync "Generate changelog entries" by @tramuntanal

Extracted from #6794

* Fix link in oauth.adoc

* Sync "Improve moderation panel" by @beagleknight

Extracted from #6677

* Removes trailing whitespaces

Co-authored-by: Oliver Valls <199462+tramuntanal@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants