-
Notifications
You must be signed in to change notification settings - Fork 1k
Implement \Countable for \WP_CLI\Iterators\CSV
#5282
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
Conversation
This makes it possible to start a progress bar for a CSV file: ```php $iterator = new \WP_CLI\Iterators\CSV( $csv_file ); $progress = \WP_CLI\Utils\make_progress_bar( 'Processing list', count( $iterator ) ); ``` The use of `SplFileObject` avoids reading the entire file to memory.
|
Not sure what the build failure is now... |
|
Seems to be signature changes due to refactoring in Core trunk. I'll take a look at fixing this. |
|
Tried to fix the build failure through #5283, let's see what Travis thinks of my approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to have the count() here. However, I don't think it's a good idea to combine two different ways of reading from the file in a same class.
Instead of storing the filename as a property and then using SplFileObject for the count only, it might make sense to convert everything to use SplFileObject and store that object as a property instead. It will overall end up producing simpler code and not introduce inconsistencies between these two read mechanisms.
Using the SplFileObject makes total sense here for the count, but is there a valid reason for not just using it all the way?
To avoid an unnecessary refactor. I suspect it makes zero functional difference that two separate approaches are used. |
|
Can you pull latest |
Yep, done. |
This makes it possible to start a progress bar for a CSV file:
The use of
SplFileObjectavoids reading the entire file to memory.