Skip to content

Conversation

@danielbachhuber
Copy link
Member

This makes it possible to start a progress bar for a CSV file:

$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.

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.
@danielbachhuber danielbachhuber requested a review from a team as a code owner September 17, 2019 14:16
@danielbachhuber
Copy link
Member Author

Not sure what the build failure is now...

@schlessera
Copy link
Member

Seems to be signature changes due to refactoring in Core trunk. I'll take a look at fixing this.

@schlessera
Copy link
Member

Tried to fix the build failure through #5283, let's see what Travis thinks of my approach.

Copy link
Member

@schlessera schlessera left a 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?

@danielbachhuber
Copy link
Member Author

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.

@schlessera
Copy link
Member

Can you pull latest master to get the build failure fix?

@danielbachhuber
Copy link
Member Author

Can you pull latest master to get the build failure fix?

Yep, done.

@schlessera schlessera merged commit bc5aabd into master Sep 18, 2019
@schlessera schlessera deleted the csv-iterator-countable branch September 18, 2019 15:43
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.

3 participants