inpsyde / wp-translation-downloader

Composer plugin to download WordPress translations
MIT License
46 stars 3 forks source link

[Bug]: Doesn't download latest translations from WordPress API #30

Closed Furo42 closed 2 years ago

Furo42 commented 2 years ago

Description of the bug

After installing translations with wp-translation-downloader there is still the option to update translations within the WordPress backend. In the current case it concerns the translation "de_DE_formal" of the plugin "User Switching" from John Blackbourn. It's installed with Composer (wpackagist-plugin/user-switching) When I install the translation with wp-translation-downloader I got the version from 2018-11-06. Updating the translation within the backend I got the version from 2021-10-21

I also did serveral clean ups to reproduce this issue.

Reproduction instructions

  1. Execute "composer wp-translation-downloader:download"
  2. Head to update section in WordPress backend and click on translation update button
  3. Remember the updated plugins and compare if these are installed via Composer

Expected behavior

I expected to update the translations to the latest version.

Environment info

Relevant log output

No response

Additional context

No response

Code of Conduct

Chrico commented 2 years ago

Hey @Furo42 β˜•

Thanks for reporting. Could you please provide an example composer.json and wp-translation-downloader.json so that i can reproduce it locally? :)

Can you also provide the output of composer install and composer wp-translation-downloader::download -vvv so that i can see which version composer is actually installing and which API Endpoint wp-translation-downloader is calling?

Thanks a lot!

Furo42 commented 2 years ago

Sure! This the composer.json (a reduced version). A wp-translation-downloader.json doesn't exist, all the configuration is within the composer.json composer.txt

This is the output with -vvv argument

  wordpress: found 1 translations
  - Endpoint: https://api.wordpress.org/translations/core/1.0/?version=5.9.3
    [CACHED] /mnt/ddev-global-cache/composer/translations/wordpress-de_DE_formal-5.9.3.zip 
Executing command (CWD): unzip -qq  '/mnt/ddev-global-cache/composer/translations/wordpress-de_DE_formal-5.9.3.zip' -d '/var/www/html/web/app/languages/'
    βœ“ 5.9.3 | de_DE_formal
    Stats: 1 downloads, 0 locked.
  user-switching: found 1 translations
  - Endpoint: https://api.wordpress.org/translations/plugins/1.0/?slug=user-switching&version=1.5.8
    [CACHED] /mnt/ddev-global-cache/composer/translations/user-switching-de_DE_formal-1.5.8.zip 
Executing command (CWD): unzip -qq  '/mnt/ddev-global-cache/composer/translations/user-switching-de_DE_formal-1.5.8.zip' -d '/var/www/html/web/app/languages/plugins/'
    βœ“ 1.5.8 | de_DE_formal
    Stats: 1 downloads, 0 locked.

The translation at the endpoint is the latest one. But I got curious about the "cache" thing so I did a composer clearcache. After that it looks like it installed also the latest version.

I think the idea with the cache is great but in this stage it seems like it's prone to problems. Is it possible to clear the translations cache without throwing away the whole Composer cache?

Chrico commented 2 years ago

I think the idea with the cache is great but in this stage it seems like it's prone to problems. Is it possible to clear the translations cache without throwing away the whole Composer cache?

Right now Composer\Cache is in use and you can only purge full cache (including the composer one).

The Cache currently contains the ZIP files to skip the "download file"-process for re-run on same version. Those zip files normally have the version string in file name, so i guess what occurs here is, that the translation of the existing version 1.5.8 was updated, but the ZIP was already downloaded and cached --> no re-download.

I probably need to extend Downloader::downloadZipFile() to also keep track of the "lastUpdated" to see if an already downloaded existing version has changed. πŸ€”

Chrico commented 2 years ago

Here we go @Furo42 : https://github.com/inpsyde/wp-translation-downloader/commit/ad31a735cfc70d83054266870474bf58e2e72c41

Good catch! Thanks a lot for input. :) I'll create a release later this day πŸ’ͺ

Chrico commented 2 years ago

I just published 2.1.1: https://github.com/inpsyde/wp-translation-downloader/releases/tag/2.1.1 . I'll keep that issue open for a bit.

Furo42 commented 2 years ago

Thank you for fixing it so quickly! Unfortunately I can't reproduce this behaviour again after deleting the whole Cache (and it's difficult to access and manipulate the Cache in our environment because it's located within a Dockaer container).

But the fix looks good and is by far better than everything I could have imagined! I will keep my eyes to the translation updates in the backend and will keep reporting every suspicious behavior πŸ‘€

Chrico commented 2 years ago

Good morning,

glad to hear! β˜• I guess it's time for me to implement some composer wp-translation-downloader:cache-clean command 😬

I'll close for now the issue since it is resolved, but feel free to create a new one or ping me! πŸ’ͺ