Skip to content

Run wp cache flush and wp search-replace on multisite even when site isn't found#4527

Merged
danielbachhuber merged 5 commits intomasterfrom
cache-17-flush
Nov 27, 2017
Merged

Run wp cache flush and wp search-replace on multisite even when site isn't found#4527
danielbachhuber merged 5 commits intomasterfrom
cache-17-flush

Conversation

@danielbachhuber
Copy link
Member

@danielbachhuber danielbachhuber commented Nov 22, 2017

Avoids annoying "Error: Site not found" failure when you'd expect these commands to work.

Because these operations can be global (cache flush always, search-replace with specific arguments), they're safe to run as long as the cache / database have been initialized.

In considering all possible implementations (e.g. registering a new @when invoke, etc.), this approach seems to have the least possible impact.

Fixes wp-cli/cache-command#17
Fixes wp-cli/search-replace-command#41

Avoids annoying "Error: Site not found" failure when an old host value
may be stored in the lookup cache.

Because flushing the cache is a global operation (not site-specific),
it's safe to run as long as the cache has been initialized.

In considering all possible implementations (e.g. registering a new
`@when` invoke, etc.), this approach seems to have the least possible
impact.
@danielbachhuber danielbachhuber added this to the 1.5.0 milestone Nov 22, 2017
@danielbachhuber danielbachhuber changed the title Run wp cache flush on multisite even when site isn't found Run wp cache flush and wp search-replace on multisite even when site isn't found Nov 22, 2017
"""
And the return code should be 1

When I run `wp search-replace foo bar --network`
Copy link
Contributor

Choose a reason for hiding this comment

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

Noticed that if you change this to something that will get replaced, eg wp search-replace example bar --network then Search_Command will throw a PHP fatal as it relies on the WP functions esc_sql() (and like_escape()) being available so will need to shim these in Search_Command.

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitlost But Search_Command runs after WordPress has loaded, which means WordPress would be loaded for wp search-replace?

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't followed the logic but it's probably some multisite peculiarity in loading - if you make that change to the test do you see the fatal?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I see what you're referring to:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

They're trivial functions so I'll do a PR on search-command with them copied in...

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can / should accommodate in Runner. Doing so now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok - will hold fire...

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. (Shimming those functions might still be something to consider as it leaves search-replace only dependent on $wpdb, which could be useful.)

@gitlost gitlost dismissed their stale review November 23, 2017 01:20

Prob solved.

@schlessera
Copy link
Member

I think that // Table-specified should be // Table-specific, but not sure:
https://github.com/wp-cli/wp-cli/pull/4527/files#diff-d5c3b8c65ee5ccc5dd15286817c05a2cR1312

Other than that, ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants