Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5686 Fix issue "Drush installation is not detected for other site al… #5687

Merged
merged 5 commits into from
Jul 7, 2023
Merged

Conversation

ordermind
Copy link
Contributor

…ias when having multiple local Drupal installations with aliases"

…ias when having multiple local Drupal installations with aliases"
@ordermind
Copy link
Contributor Author

fixes #5686

@@ -55,11 +55,11 @@ public function run($argv): int
protected function doRun($argv, $output): int
{
// Do the preflight steps
$status = $this->preflight->preflight($argv);
$preflightSuccess = $this->preflight->preflight($argv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false does not indicate failure, so I would rename this something like $preflightDidRedispatch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, this should be fixed now.


// If preflight signals that we are done, then exit early.
if ($status) {
return $status;
if ($preflightSuccess) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the real bug. The original code was if ($status !== false). That is, Preflight would return bool false if doRun should continue, and an integer status code if a redispatch happened. This sort of coding convention was common in the PHP 5 era, but is no longer considered de rigor in PHP 8, and in fact is a deprecated practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, this should be fixed now.

// integer. This method is supposed to return true when successful, so
// we need to convert it to a boolean accordingly.

return $status ? false : true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should always return true if it gets to this point. The comment in the header that says "and was returned successfully" was in error. See my other comment for a description of how the code used to work.

I think that the best fix would be to change this function to use return [false, 0]; wherever it currently uses return false, and change this line to return [true, $status];. Then, doRun must record both return values, call them $preflightDidRedispatch and $status or something similar. It should then return $status if $preflightDidRedispatch is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, this should be fixed now.

Copy link
Member

@greg-1-anderson greg-1-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this. The original bug was caused by optimizing away a type check (!== false). I suggest a better fix would be to change the return tupe of the preflight function. Since preflight is an internal function, I don't think we need to consider this a breaking change.

Copy link
Member

@greg-1-anderson greg-1-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you for working on this problem.

@weitzman Does this resolution look OK to you?

@weitzman
Copy link
Member

weitzman commented Jul 7, 2023

Yes, LGTM. The one suggesion I have is to replace the various new 0 with \Drush\Commands\DrushCommands::EXIT_SUCCESS

Copy link
Member

@greg-1-anderson greg-1-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use \Drush\Commands\DrushCommands::EXIT_SUCCESS as suggested by @weitzman

@weitzman weitzman merged commit ddc733f into drush-ops:12.x Jul 7, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants