Skip to content

Conversation

@cyberhobo
Copy link
Contributor

When there are more than 1000 replacements to be done and the replacement string does not contain the search string, not all replacements are made.

@scribu
Copy link
Member

scribu commented May 27, 2013

The test currently fails because the test suite doesn't support nested calls, like $(wp option get).

We use the And save STDOUT as {VAR} step as a workaround.

@scribu
Copy link
Member

scribu commented May 27, 2013

I suppose it wouldn't be impossible to devise a regex that replaces this:

$(wp option get)

with this:

$(/absolute/path/to/bin/wp option get)

and get rid of the workaround.

@scribu
Copy link
Member

scribu commented May 27, 2013

Or we could just set wp as an alias in the subprocess, leaving bash to do the rest.

@scribu
Copy link
Member

scribu commented May 28, 2013

See #475

cyberhobo added 3 commits May 27, 2013 18:57
The wp aliases in my PATH made me oblivious before...
In this case the current code works, but alternatives I was considering
might not.

Also removed the small test - that case is already covered.
@scribu
Copy link
Member

scribu commented May 28, 2013

I'm still not convinced there's a bug. In https://travis-ci.org/wp-cli/wp-cli/builds/7552302 the test fails because STDOUT also contains a confirmation message:

Success: Made 1003 replacements.

@scribu
Copy link
Member

scribu commented May 28, 2013

In this case the current code works, but alternatives I was considering might not.

You mean there's some edge case where the command wouldn't work correctly? Please explain.

@cyberhobo
Copy link
Contributor Author

The test that fails makes 1000 replacements in the guid column, changing http://example.com to http://newdomain.com. The bug happens when the iterator then tries to get the next chunk using WHERE guid LIKE %http://example.com% LIMIT 1000 OFFSET 1000, but the columns that have been changed no longer match the LIKE. There are 200 matches left to change still, but they are now in the first chunk and the OFFSET 1000 skips them.

@cyberhobo
Copy link
Contributor Author

The tests for this are slow. Would it be worth making chunk size a parameter to facilitate smaller tests?

@scribu
Copy link
Member

scribu commented May 28, 2013

The bug happens when the iterator then tries to get the next chunk using WHERE guid LIKE %http://example.com% LIMIT 1000 OFFSET 1000, but the columns that have been changed no longer match the LIKE.

Now I get it. Thanks!

The tests for this are slow. Would it be worth making chunk size a parameter to facilitate smaller tests?

I would prefer not to make it an explicit parameter.

Copy link
Member

Choose a reason for hiding this comment

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

The query string is duplicated (once here and once at line 76). You should move it to a helper method.

Or maybe we could add an extra parameter to Iterators\Table to make it have this behaviour (repeat the same query until there are no more results).

@cyberhobo
Copy link
Contributor Author

I took a stab at handling this in the iterator instead.

@scribu
Copy link
Member

scribu commented May 30, 2013

The code looks solid now. Thanks!

scribu pushed a commit that referenced this pull request May 30, 2013
Replace all occurrences in large search-replace operations
@scribu scribu merged commit 584ebbb into wp-cli:master May 30, 2013
@scribu
Copy link
Member

scribu commented May 30, 2013

Man, those tests really are slow.

scribu added a commit that referenced this pull request May 30, 2013
@cyberhobo cyberhobo deleted the fix-incomplete-search-replace branch May 30, 2013 02:03
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.

2 participants