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

Conimex import fails when collection is empty #3291

Open
michaelborn opened this issue Aug 17, 2022 · 4 comments
Open

Conimex import fails when collection is empty #3291

michaelborn opened this issue Aug 17, 2022 · 4 comments

Comments

@michaelborn
Copy link

I get a warning "Warning: Undefined array key "order" after running a conimex import:

./bin/console -vvv conimex:import my-site-export-2022-08-08.yaml

I believe this is a new / more strict warning in PHP 8?

https://stackoverflow.com/questions/71025115/dealing-with-php-8-1-warning-for-undefined-array-key

Details

  • Bolt 5.0.6
  • PHP 8.1.8

Reproduction

./bin/console -vvv conimex:import my-site-export-2022-08-08.yaml

Stack trace:

In ContentEditController.php line 439:
                                        
  [ErrorException]                      
  Warning: Undefined array key "order"  
                                        

Exception trace:
  at /home/user/myBoltSite/vendor/bolt/core/src/Controller/Backend/ContentEditController.php:439
 Bolt\Controller\Backend\ContentEditController->updateCollections() at /home/user/myBoltSite/vendor/bobdenotter/conimex/src/Import.php:295
 BobdenOtter\Conimex\Import->importRecord() at /home/user/myBoltSite/vendor/bobdenotter/conimex/src/Import.php:122
 BobdenOtter\Conimex\Import->importContentType() at /home/user/myBoltSite/vendor/bobdenotter/conimex/src/Import.php:91
 BobdenOtter\Conimex\Import->import() at /home/user/myBoltSite/vendor/bobdenotter/conimex/src/Command/ImportCommand.php:62
 BobdenOtter\Conimex\Command\ImportCommand->execute() at /home/user/myBoltSite/vendor/symfony/console/Command/Command.php:299
 Symfony\Component\Console\Command\Command->run() at /home/user/myBoltSite/vendor/symfony/console/Application.php:996
 Symfony\Component\Console\Application->doRunCommand() at /home/user/myBoltSite/vendor/symfony/framework-bundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /home/user/myBoltSite/vendor/symfony/console/Application.php:295
 Symfony\Component\Console\Application->doRun() at /home/user/myBoltSite/vendor/symfony/framework-bundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/user/myBoltSite/vendor/symfony/console/Application.php:167
 Symfony\Component\Console\Application->run() at /home/user/myBoltSite/bin/console:48

conimex:import <filename>

Steps to reproduce

Evidently, importing a conimex import which does not include the order key.

Expected result

I expected that my content would import.

Actual result

A failed import, with no ability to skip the warning.

@michaelborn
Copy link
Author

It's worth noting that this same export also fails in Bolt 5.1.12 on PHP 7.4. (Albeit with a slightly different error message.) So this is not just a PHP 8 issue, as I previously thought.

// Importing ContentType content                                                                                       

  8/72 [=====>--------------------------------------------]  11%  1 sec/9 secs 54.5 MiB
In ContentEditController.php line 442:
                                  
  [ErrorException]                
  Notice: Undefined index: order  
                                  

Exception trace:
  at /home/user/myBoltSite/vendor/bolt/core/src/Controller/Backend/ContentEditController.php:442
 Bolt\Controller\Backend\ContentEditController->updateCollections() at /home/user/myBoltSite/vendor/bobdenotter/conimex/src/Import.php:344
 BobdenOtter\Conimex\Import->importRecord() at /home/user/myBoltSite/vendor/bobdenotter/conimex/src/Import.php:118
 BobdenOtter\Conimex\Import->importContentType() at /home/user/myBoltSite/vendor/bobdenotter/conimex/src/Import.php:87
 BobdenOtter\Conimex\Import->import() at /home/user/myBoltSite/vendor/bobdenotter/conimex/src/Command/ImportCommand.php:62
 BobdenOtter\Conimex\Command\ImportCommand->execute() at /home/user/myBoltSite/vendor/symfony/console/Command/Command.php:298
 Symfony\Component\Console\Command\Command->run() at /home/user/myBoltSite/vendor/symfony/console/Application.php:1042
 Symfony\Component\Console\Application->doRunCommand() at /home/user/myBoltSite/vendor/symfony/framework-bundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /home/user/myBoltSite/vendor/symfony/console/Application.php:299
 Symfony\Component\Console\Application->doRun() at /home/user/myBoltSite/vendor/symfony/framework-bundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/user/myBoltSite/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at /home/user/myBoltSite/bin/console:48

conimex:import <filename>

@michaelborn
Copy link
Author

I'm guessing this is a case of an old conimex version, and not an issue in Bolt Core.

I can see the order set on the collection field in the Conimex extension here:

https://github.com/bobdenotter/conimex/blame/04f0d30dd4d038177080519f7bbea1af0f5bd5aa/src/Import.php#L224

@michaelborn
Copy link
Author

Nope - this still occurs on the latest conimex v 2.1.2. Unsure whether the issue is in conimex or in bolt/core.

@michaelborn
Copy link
Author

I still don't know if this is a Conimex bug or a Bolt core bug, but I was able to fix by adding a check for array length in the collections array in ContentEditController.php:

        if (isset($formData['collections'])) {
            foreach ($formData['collections'] as $collectionName => $collectionItems) {
                if ( !count( $collectionItems ) ) continue; // NEW LINE HERE

This prevents line 433 from flipping out (pun!) because $collectionItems['order'] doesn't exist.

https://github.com/bolt/core/blob/master/src/Controller/Backend/ContentEditController.php#L433

Is this a newbie fix, or should I PR this?

@michaelborn michaelborn changed the title Conimex import fails with "undefined array key order" on PHP 8.x Conimex import fails when collection is empty Aug 17, 2022
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

No branches or pull requests

1 participant