Problem/Motivation
Deprecate and replace:
- locale.bulk.inc
- locale_translate_get_interface_translation_files
- locale_translate_file_create
- locale_translate_file_attach_properties
- locale_translate_delete_translation_files
- locale.batch.inc
- locale_translation_http_check
- locale_translation_download_source
Steps to reproduce
N/A
Proposed resolution
Create LocaleFileManager
- downloadTranslationSource
- getInterfaceTranslationFiles
- deleteTranslationFiles
- checkRemoteFileStatus
Create LocaleFile value object
- add createFromPath static method to set some default properties from file names
-- This now has the regex to try to detect the project, version and language from the filename
- tracks locale file status, type, last updated, project, and other information
Create RemoteFileInfo value object
Create RemoteFileStatus enum
- tracks the download for success, error or 404
Remaining tasks
N/A
User interface changes
N/A
Introduced terminology
N/A
API changes
New LocaleFileManager
New LocaleFile
New RemoteFileInfo
New RemoteFileStatus
Data model changes
All LocaleFile operations must happen on the LocaleFile value object instead of a stdObject
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|
Issue fork drupal-3577671
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 #3
nicxvan commentedComment #4
nicxvan commentedI have some type questions I'm not sure if we should update.
Comment #5
berdirAdded a proposal on how to deal with those file objects. I'm certain it goes further than you had planned to go here, but I think it's still quite a manageable scope if we use public properties.
Didn't see any other functions that would fit here, but made a proposal for another small isolated service that we can extract for those file history functions.
Comment #6
nicxvan commentedI kind of figured we needed more cleanup which is why I didn't add more.
Even though there isn't much usage in contrib I think there is custom usage due to this: #3575678: Locale checks file mtime but this is tricky if the translation files are copied to an image by Docker use a hash of the file instead
I guess technically this should be postponed on that but I want to work out what the api looks like here first before postponing it, and the other issue will likely get in soon anyway.
Thanks for the review I'll work on it.
Comment #7
nicxvan commentedComment #8
nicxvan commentedObviously got some failures to work through, but I think I have the structure in place.
Also looking through the other files.
I think we should handle
locale_translation_http_check
locale_translation_download_source
here as well, they are the only two non batch related functions in locale.batch.inc and they both relate to files as well.
Compare has a bunch, but there is a separate issue for that. Once this, and the compare are in there are only batch related functions in .inc which can probably be done in one issue.
locale_translation_http_check I think should go on localeFileManager
locale_translation_download_source should also go on localeFileManager and return a LocaleFile, there is a type property on the file set in locale_translation_download_source, but it's not used so I think we drop it.
Happy to keep type if we think it's necessary.
Comment #9
nicxvan commentedComment #10
nicxvan commentedComment #11
nicxvan commentedWe did need type and a couple more that get added dynamically.
I think there is likely one test failure I could use help with, but I think this is ready for a general architecture review again.
Comment #12
nicxvan commentedThinking about this i have a theory that we need to check if project or version were set by the constructor, I suspect it's an order of operations issue.
Comment #13
nicxvan commentedFixed most comments and did some cleanup.
core/modules/locale/tests/src/Functional/LocaleUpdateTest.php has a bunch of failures now I can't look at at the moment.
There is a failure on HEAD too and a random as well, but I think this is close.
I suspect the new failures are due to the ImportForm change.
Comment #14
nicxvan commentedlocale_translation_get_file_historyis returning the timestamp.It gets set in
locale_translation_update_file_historyThis is called in three places:
locale bulk: locale_translate_batch_import_save
locale module: locale_translation_status_save
LocaleSource: sourceBuild
It seems to be set from timestampMedium which is offset by 200.
Seems to be something to do with the default:
Comment #15
nicxvan commentedThe failing test is:
core/modules/locale/tests/src/Functional/LocaleUpdateTest.phpIt seems that somehow the history lookup is returning stale information.I pushed up a debug only branch that adds some checks to make it easier to see what is happening, all line numbers are on that branch
I set a local variable for the two timestamps involved:
$mediumTimestamp = $this->timestampMedium;
$nowTimestamp = $this->timestampNow;
The medium is the default timestamp set on files, the now is what we compare against for updates.
Line 196 is asserting that the updated timestamp is greater than now and fails because the timestamp set is still set to the medium timestamp.
I initially got suspicious of
$history = locale_translation_get_file_history();so I looked at it and extracted the direct db call:I then checked that 6 separate times in the test to see if the timestamp for the files change.
It does not.
One this branch:
IMPORTANT NOTE you need to check the actual project in the result, since each run the order of the projects is different in results or history.
Make sure you're comparing the same project, they are named similarly.
Example test run checking values for "contrib_module_one"
On main
I then checked out main and copied the modified test in: it passes as expected.
Note you have to be careful to check for the same project since the order of the results can change.
Example test run checking values for "contrib_module_one"
The culprit seems to be somewhere in:
Which only submits:
core/modules/locale/src/Form/TranslationStatusForm.phpI can't dig further now, but I suspect something with type is getting changed so the logic in prepareUpdateData is not following the same path.
Comment #16
nicxvan commentedOk this has been super hard to debug, but I think I'm finally on track: because the test does this
$this->drupalGet('admin/reports/translations');xdebug doesn't stop in the form for the submission, so I added a file put contents and output the medium timestamp and added the type and printed the projects, I see the type is changing on something so I see it's not being set properly somewhere, I'll attach the debug so I can chase it down.Comment #17
nicxvan commentedHere is a better version on main with other tests commented out, the number of calls are higher since the test doesn't fail.
Edit: looking closer I think it's another red herring :/
Comment #19
alexpottI'm not sure about the approach of moving the regex into the LocaleFile constructor. Before locale_translate_file_attach_properties() was being called from two places. Now it is running much much more often. That makes me a bit uncomfortable. One we're likely to be doing unnecessary work, and two we have bugs like the one fixed in https://git.drupalcode.org/project/drupal/-/merge_requests/15013/diffs?c...
Comment #20
nicxvan commentedI will move those properties to the constructor and the regex to a method that only gets called in the path it was before. Thank you again!
Assigning to myself to rework.
Comment #22
nicxvan commentedI think this is ready for review!
I've addressed the concern with the regex being called in scenarios it didn't used to be called by moving it to
createFromPathand directly instantiating LocaleFile elsewhere.Edit: I just pushed up a parameter order change so the constructor and
createFromPathshare the order since all calls tocreateFromPathnow have both parameters.Comment #23
nicxvan commentedI've addressed almost all of your feedback, I really think we should leave
checkRemoteFileStatusto a follow up.We can easily add internal to it and update later.
Comment #24
nicxvan commentedI took another look and just updated
checkRemoteFileStatus, it now uses a value object with an enum for the status.Everything is green so it's ready for review again.
Comment #25
berdirThis was quite the journey and it's touching quite few places and introducing quite a few things, new value objects. It's not _perfect_ (nothing ever is, and this is locale module. We have a long way to go) but I think it has significant improvements (we get rid of hard-to-document array structures and stdClass objects, sometimes for functions that do not have a single known call to them in contrib and some only from drush_language which isn't even D11 compatible yet)
Comment #26
nicxvan commentedComment #27
nicxvan commentedComment #28
nicxvan commentedThank you for the reviews, it was quite a change, but as you mentioned I think it's a great improvement, and we have a lot of follow ups for the rest of locale.
I updated the IS and CR.
Comment #29
nicxvan commentedComment #32
nicxvan commentedComment #34
nicxvan commentedComment #35
berdirLets redo the 11.x MR now that #3549730: Enable LongLineDeclaration is in, should be almost identical to main now except the services.yml file.
Comment #36
nicxvan commentedThis is ready again!
Comment #37
berdirManually compared the two commits as files (is there really no better way to do this?), there's an empty line difference compared to main.
Comment #38
berdirThanks. Can confirm that this is now identical except the expected locale.services.yml changes.
Comment #39
catchI think my original commit comment here got eaten by the Drupal.org DDOS attack, just to confirm I did in fact commit this on purpose to main and it was still open for 11.x backport due to commit conflicts.
Now committed the 11.x backport MR to 11.x, thanks!
Comment #43
webflo commentedI profiled the installation process on a website with 38 languages and 290 enabled modules and opened #3586654: Avoid scanning the file system for local po files as a follow-up.
Comment #45
nicxvan commentedComment #46
ptmkenny commentedTesting 11.4.0-rc1, I found this commit broke
drush locale:importbecause the deprecated shim forces the import to be 'und' instead of the language you specify: #3600694: locale_translate_file_attach_properties() BC layer incorrectly always sets override langcode to undefined