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

[Bug]: isEmptyWhen never gets called in ModelImporter #3827

Closed
1 task done
quantumwebco opened this issue Dec 10, 2022 · 4 comments
Closed
1 task done

[Bug]: isEmptyWhen never gets called in ModelImporter #3827

quantumwebco opened this issue Dec 10, 2022 · 4 comments

Comments

@quantumwebco
Copy link
Contributor

quantumwebco commented Dec 10, 2022

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.44

What version of Laravel are you using?

9.38

What version of PHP are you using?

8.1

Describe your issue

Using SkipsEmptyRows suggests that the method isEmptyWhen(array $row): bool will be called for custom empty row validation

It never gets called

How can the issue be reproduced?

implement SkipsEmptyRows, add isEmptyWhen(array $row): bool log something and/or return false and the method never gets called

What should be the expected behaviour?

isEmptyWhen should be called in the foreach loop on line 60 of Maatwebsite\Excel\Imports\ModelImporter

foreach ($worksheet->getRowIterator($startRow, $endRow) as $spreadSheetRow) {
            $i++;
            $row = new Row($spreadSheetRow, $headingRow, $headerIsGrouped);
            if (!$import instanceof SkipsEmptyRows || ($import instanceof SkipsEmptyRows && !$row->isEmpty($withCalcFormulas))) {
                $rowArray = $row->toArray(null, $withCalcFormulas, $formatData, $endColumn);

                if ($import instanceof SkipsEmptyRows && method_exists($import, 'isEmptyWhen') && $import->isEmptyWhen($rowArray)) {
                    continue;
                }
                
                if ($withValidation) {
                    $rowArray = $import->prepareForValidation($rowArray, $row->getIndex());
                }
            ...

Can I PR this? Not sure if that is the best way of doing it but the $rowArray isn't instantiated until after the initial if statement against instanceof SkipsEmptyRows. I can refactor that section a bit more if required?

@stale stale bot added the stale label Feb 9, 2023
@stale
Copy link

stale bot commented Feb 10, 2023

This bug report has been automatically closed because it has not had recent activity. If this is still an active bug, please comment to reopen. Thank you for your contributions.

@stale stale bot closed this as completed Feb 10, 2023
@touiminao
Copy link

Reopen

@typingbeaver
Copy link
Contributor

It indeed seems to be ignored.

@sergejostir
Copy link

sergejostir commented Dec 27, 2023

It works in version 3.1.51.

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

No branches or pull requests

4 participants