wp-cli / language-command

Installs, activates, and manages language packs.
MIT License
13 stars 21 forks source link

Fail to install if languages folder is empty #123

Closed runthis closed 12 months ago

runthis commented 12 months ago

Bug Report

Describe the current, buggy behavior

If the current languages folder is empty, running wp language core install <lang> will result in a warning followed by a failed install.

Describe how other contributors can replicate this bug

If assuming this is not related to our non-standard WordPress setup, replication steps are:

Describe what you would expect as the correct outcome

If the issue is difficult to resolve, a potentially better error message would be convenient in this use-case. Tracking down the issue didn't take -too long- but on a hunch I created an empty file in the languages folder after ruling out other issues (which resolved the issue). I then deleted all files in the languages folder and was able to consistently replicate the failed install.

Let us know what environment you are running this on

Docker, bedrock, php 8.2, wordpress 6.2

$ docker-compose exec -u www-data -w /var/www/html wordpress wp language core install da_DK
Using cached file '/home/www-data/.wp-cli/cache/translation/core-default-6.2.2-da_DK-1689336729.zip'...
Unpacking the update...
Installing the latest version...
Removing the old version of the translation...
Warning: The destination directory already exists and could not be removed.
Translation update failed.
Warning: Could not install language 'da_DK'.
Language 'da_DK' not installed.
Error: No languages installed (1 failed).

Provide a possible solution

I could not find directly where this happens to offer a better solution, my apologies.

swissspidy commented 12 months ago

This sounds like a file permission issue specific to your setup. I am unable to reproduce this and the following Behat test passes:

  Scenario: Install language with an empty languages directory
    Given a WP install
    And an empty cache
    And an empty wp-content/languages directory

    When I run `wp language core install da_DK`
    Then the wp-content/languages/admin-da_DK.po file should exist
    And the wp-content/languages/da_DK.po file should exist
    And STDOUT should contain:
      """
      Success: Installed 1 of 1 languages.
      """
    And STDERR should be empty

Some background:

If the languages directory is empty, \WP_Upgrader::install_package() in WordPress calls move_dir() to move the downloaded translations to the desired location. The error happens in move_dir() because it can't delete the target directory.

If the directory is not empty, WP uses a different function copy_dir() to copy the files around. That's why you see different behavior in that scenario.

runthis commented 12 months ago

Fair enough. I have a pretty non-standard installation going. If it works for you I think this issue can be closed. For anyone in the future who sees something similar, The work-around I chose when running an initial setup script is to touch a new file in the folder and delete it after all the languages needed are installed.