Operator OperatorPHPCode for Import


#1

Hi,
iam testing with data imports. The documentation describes operators. If I try out the example of documentatation, the operator can not find the class. Where is to place the “MyImportCodeOperator” Class?
Here is the link of the PimcoreExample:
Docu

Thx


#2

I think you can put it into the src folder and call it without a namespace.
I, anyway, suggest you to put it under a namespace (adding the namespace statement on top of you php file) and put it under the correct folder depending on the namespace you chose.

For example I usually organize my CodeOperator classes like this:
src/CSVImport/MyImportCodeOperator.php

And in my class file I use:
namespace CSVImport;

Then in you import configuration you can refer to your class as “CSVImport/MyImportCodeOperator”

Hope this helps!


#3

Okay, yes I have give them a namespace

namespace AppBundle\Tool;

When I click Import, there is at “CSV File Priview” a mistake at the column priview:

Blockquote
Exception: Class mismatch for ID 1 in /mnt/pimcore5/docroot/pimcore/lib/Pimcore/DataObject/Import/Resolver/Id.php:43 Stack trace: #0 /mnt/pimcore5/docroot/pimcore/lib/Pimcore/Bundle/AdminBundle/Controller/Admin/DataObjectHelperController.php(1299): Pimcore\DataObject\Import\Resolver\Id->resolve(Object(stdClass), 2339, Array) #1 /mnt/pimcore5/docroot/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(151): Pimcore\Bundle\AdminBundle\Controller\Admin\DataObjectHelperController->importPreviewAction(Object(Symfony\Component\HttpFoundation\Request), Object(Pimcore\DataObject\Import\Service), Object(Pimcore\Localization\Locale), Object(Pimcore\Model\Factory), Object(Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher)) #2 /mnt/pimcore5/docroot/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #3 /mnt/pimcore5/docroot/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(202): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #4 /mnt/pimcore5/docroot/web/app.php(55): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #5 {main}


#4

Would you mind attaching the custom OperatorPHPCode class and your import configuration?