Open dingo-d opened 3 years ago
I can look into it :slightly_smiling_face:
I think the issue might be on the chaining the echo $?
using a pipe.
Instead of: wp core is-installed | echo $?
Try:
wp core is-installed
echo $?
You can also test this with:
ls /nonexisting_dir &> /dev/null | echo $?
ls /nonexisting_dir &> /dev/null
echo $?
The issue is not in the output of the WP-CLI command, but more about the behavior of the command:
It would be good to throw 1 as long as there are no DB tables present. The command should be more robust. That way it will be easier to use them in CI/CD pipelines.
I 'solved' the issue by:
information_schema
tablewp core is-installed | echo $?
command outputWhat I'd think that command would have to do is combine the table check as well. As that is the part that is kinda failing.
@dingo-d I've replicated the behaviour. It seems that you are using the Symfony command library, you can get the return code of the command from the $outpout variable you pass to run() https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Console/Command/Command.php#LL278C60-L278C60
And then on this you can get the return code, as in exec
the 3rd argument return the code :
<?php
exec('wp core is-installed', $out, $code);
var_dump($out,$code);
Will print :
array(0) {
}
int(1)
As intended, the output is empty, the return code is 0.
Bug Report
Describe the current, buggy behavior
I am working on automatic WP deploy using deployer and GH Actions. The first task in my deploy process is to setup the
wp-config.php
, then build the theme, upload it, symlink the current release, and at the end I'm making a check for plugin and core updates using WP-CLI.In the last part of the deployer task that checks the core and plugins, I added
This will set the variable
$isInstalled
to 0 if the core is installed, and 1 if not. In the case it's 1 I doThen after that, I have
This will check the current core version, and compare it to the version I have set during my deployment process (
$coreVersion
variable). In my case, the$coreVersion
was set to 5.7, and the$currentCoreVersion
was 5.6, so the conditional was true and I tried to update my WP core. But I got the error that WP is not installed, because the tables weren't set yet in the DB.So in the end the command
wp core is-installed
doesn't do a good job really. Not sure why tho, because theis_blog_installed()
function should return false (or maybe it doesn't because of all the error suppressions 🤷🏼♂️ ).Describe how other contributors can replicate this bug
wp core download --version=5.6
)wp-config.php
that will point to empty DB (wp config create
)wp core update
and see the errorMore so, even after just downloading the core the command
Will return
So it says that it's installed but the config is missing, after creating the config it returns 0, but there are still no DB tables.
Describe what you would expect as the correct outcome
It would be good to throw 1 as long as there are no DB tables present. The command should be more robust. That way it will be easier to use them in CI/CD pipelines.
Let us know what environment you are running this on
Local:
Ubuntu: