Problem/Motivation
locale.translations.inc is the bottom of the chain of circular dependencies.
Let's convert this to services.
- locale_translation_get_projects
- locale_translation_clear_cache_projects
- locale_translation_load_sources
- locale_translation_build_sources
- locale_translation_source_check_file
- locale_translation_source_build
- locale_translation_build_server_pattern
- locale_cron_fill_queue
- _locale_translation_file_is_remote
- _locale_translation_source_compare
- _locale_translation_default_update_options
Steps to reproduce
Open the module
Proposed resolution
Analyze the functions and outline new services.
Constants should be deprecated, there are no uses in contrib and they are only used in one function.
I propose the following organization.
Move to new service: LocaleSources
- locale_translation_load_sources
- locale_translation_build_sources
- locale_translation_source_check_file
- locale_translation_source_build
- locale_translation_build_server_pattern
- make protected and delete _locale_translation_file_is_remote
Move to LocaleProjectStorage
- locale_translation_get_projects
Replace with static cache
- locale_translation_clear_cache_projects
Move logic to LocaleHooks and deprecate without replacement
- locale_cron_fill_queue
Inline and simplify logic in TranslationStatusForm: Delete function
- _locale_translation_source_compare
Deprecate without replacement now that the logic is inline
- comparison constants
New api LanguageDefaultOptions
- _locale_translation_default_update_options
Remaining tasks
Scope discussion:
Since this is both manually included with require_once and included with moduleHandler->loadInclude handling the file at once reduces circular dependencies.
The CR is a great overview of where the code went
Use the command git diff main --color-moved=dimmed_zebra --color-moved-ws=ignore-all-space to compare moved code vs changed code.
User interface changes
Introduced terminology
API changes
New: LanguageDefaultOptions
New: LocaleSources
LocaleProjectStorage->getProjects
Data model changes
Release notes snippet
Issue fork drupal-3569328
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
nicxvan commentedComment #3
nicxvan commentedComment #5
nicxvan commentedComment #6
nicxvan commentedComment #7
nicxvan commentedComment #8
nicxvan commentedComment #9
nicxvan commentedComment #10
nicxvan commentedComment #11
nicxvan commentedComment #12
nicxvan commentedComment #13
nicxvan commentedComment #14
nicxvan commentedComment #15
dcam commentedI only found one thing to comment on. If you want to leave the code as close to the original as possible, then this could be delayed to a follow-up. But I feel like it's appropriate to deal with it now due to the addition of the enum.
Everything else looks good. I validated all of the moved code. I still need to try manual testing. I'll keep working on it.
Comment #16
dcam commentedI tried to put Locale through its paces to do manual testing. I'm not sure I tested all paths, but so far it's working correctly. It downloaded translations from the server. It checked remotely-hosted translations versus ones I already had downloaded. It downloaded translations when a language was enabled. I was able to trigger manual downloads from the translation status form. As far as I can tell, the module is still working correctly.
I think the only thing to figure out is whether we want to deal with the enum as indicated in my previous comments.
Comment #17
nicxvan commentedLet me create a separate MR with those suggestions we can see more clearly.
Comment #19
nicxvan commentedThat's a great suggestion, please double check my new MR and confirm it's working.
That makes this significantly smaller too.
If you're testing confirms and this looks right I'll update the IS and CR
Comment #20
nicxvan commentedComment #22
dcam commentedYeah, this looks great to me. I re-reviewed the MR changes, but for the sake of being thorough I also diffed the raw diffs of the two MR so I'd know exactly what changed between them. The constants and function are now deprecated without replacement. The IS and CR were updated to reflect this change. I'm glad this worked out so we could simplify the code.
Actually, I'm amazed there was such an opportunity for simplification. It makes me wonder if this API has changed a lot over time. Two of the three constants basically weren't used. Maybe they were in the past. It isn't worth taking the time to do Git archaeology to check.
Comment #23
claudiu.cristeaComment #24
claudiu.cristeaPlease collect also the credits from #3036982: [pp-1] Deprecate locale_translation_get_projects() and locale_translation_clear_cache_projects()
Comment #25
nicxvan commentedAll closed issues grant credit now, when I close the other I'll take care of credit.
Comment #26
nicxvan commentedWe got new direction that we should stick to the normal BC policy for underscore which is to just delete them.
I pushed up deleting the underscore functions and replacing the remaining deprecated functions to use the new api.
I then updated the deprecation version to 12 since the deletions need to target the next major since we're so close.
Comment #27
nicxvan commentedComment #28
dcam commentedI left one question on the MR.
Comment #29
nicxvan commentedI updated it, I'll keep an eye on tests.
Comment #30
dcam commentedMy feedback on the recent changes was addressed.
Comment #31
nicxvan commentedSorry for the ping pong, I added the underscore back as the decision is to keep them and deprecate for removal in 12.
There is a mix of removal versions in this MR.
All functions / constants are deprecated in 11.4
Removal is 13 if it is api
Removal is 12 if it is not api
I also addressed @berdir's new feedback around the drupal_static deprecation
Comment #32
dcam commentedThe non-API functions have been restored and deprecated in 11.4 for removal in 12. The additional change to bootstrap.inc looks good. LGTM.
Comment #33
nicxvan commentedI just updated $timestamp1 to $local_timestamp and $timestamp2 to $remote_timestamp for clarity.
It was just a couple of lines for clarity and tests are still green so I'm leaving RTBC
Comment #35
catchReviewed this. It's not easy to see what the final result will end up like, but I don't see anything particularly troublesome either.
Committed/pushed to main and 11.x, thanks! Also published the change record.
Comment #41
grimreaperI have a fatal error with Drush 13.7.3 and Core 11.4.0-RC2
I guess due to the fact that even if marked as deprecated if the file is no more loaded automatically, it provokes fatal errors:
PS: I forgot to add the link to the Github issue: https://github.com/drush-ops/drush/issues/6579
Comment #42
nicxvan commentedShould be fixed in #3601433: Fix local_status deprecation by clearing source in a post update
Comment #43
grimreaperSorry, I forgot to post the link to the Github issue I have created.
https://github.com/drush-ops/drush/issues/6579
I have edited my previous comment but you already reacted (thanks!).
I am not sure this is the same problem.
PS: I will test tomorrow
PS2: maybe same problem, I was focused on the post_update hook, but the
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.translation');may do the trick.Comment #44
grimreaperTested this fixes the problem.
Thanks!