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

Event "data_definitions.import.total" never gets dispatched #320

Merged
merged 7 commits into from
Aug 18, 2021
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/DataDefinitionsBundle/Provider/TraversableImportDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2019 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
* @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3
paulverdu marked this conversation as resolved.
Show resolved Hide resolved
* (GPLv3)
*/

declare(strict_types=1);

namespace Wvision\Bundle\DataDefinitionsBundle\Provider;

use Closure;
use Iterator;
use Countable;
use IteratorIterator;
use Traversable;

class TraversableImportDataSet implements ImportDataSetInterface
class TraversableImportDataSet implements ImportDataSetInterface, Countable
{
private \IteratorIterator $iterator;
private IteratorIterator $iterator;
paulverdu marked this conversation as resolved.
Show resolved Hide resolved
private int $count;

public function __construct(\Traversable $iterator)
public function __construct(Traversable $iterator)
{
$this->iterator = new \IteratorIterator($iterator);
$this->count = iterator_count($iterator);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this lazy? Only count it if the count is requested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not possible to do a count on a iterator since you can only rewind ones. That's why im doing this in the constructor before the IteratorIterator object is created. The count is also always requested in the importer.

$this->iterator = new IteratorIterator($iterator);
}

/**
Expand Down Expand Up @@ -83,4 +87,13 @@ public function rewind()
{
$this->iterator->rewind();
}

/**
* Return the number of elements in the Iterator
* @return int
*/
public function count(): int
{
return $this->count;
}
}