Forums › Forums › OroPlatform › OroPlatform – Programming Questions › Import Export bundle buttons
This topic contains 6 replies, has 3 voices, and was last updated by sakhrimedamine 8 years, 12 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- January 14, 2015 at 7:10 pm #33683
Hi there,
I have created a new entity which needs to be able to be imported and exported. I have done this by copying the logic in oro’s account bundle (importexport.yml, etc etc).
The problem is, when I upload a csv within the modal Nothing happens. After more investigation i found the error ‘Processor with type “import_validation” and alias “” is not exist’ however it is declared within importexport.yml.
The button code is as follows:
12345678{% include 'OroImportExportBundle:ImportExport:buttons.html.twig' with {entity_class: '%atf.vehicle.entity.class%',exportProcessor: 'atf_vehicle',exportTemplateProcessor: 'atf_vehicle',importProcessor: 'atf_vehicle.add_or_replace',importTitle: 'oro.importexport.import.entity'|trans({'%entityName%': 'atf.quotes.vehicle.entity_label'|trans}),dataGridName: gridName} %}Any help would be appreciated
Cheers
- CreatorTopic
- AuthorReplies
- January 19, 2015 at 6:22 am #33684
Hi Alex!
Please post your importexport.yml file content here
January 19, 2015 at 3:44 pm #33685Hi mate,
Here is the file as is. It currently exports and shows my import template fine, however throws an error on import.
1234567891011121314151617181920212223242526272829303132333435363738394041424344parameters:oro_user.importexport.template_fixture.account.class: Atf\Bundle\LocateBundle\ImportExport\TemplateFixture\UserFixtureservices:oro_user.importexport.data_converter:parent: oro_importexport.data_converter.configurableoro_user.importexport.template_fixture.data_converter.account:parent: oro_importexport.data_converter.template_fixture.configurable# Strategyoro_user.importexport.strategy.account.add_or_replace:parent: oro_importexport.strategy.configurable_add_or_replace# Import processororo_user.importexport.processor.import:parent: oro_importexport.processor.import_abstractcalls:- [setDataConverter, [@orocrm_account.importexport.data_converter]]- [setStrategy, [@orocrm_account.importexport.strategy.account.add_or_replace]]tags:- { name: oro_importexport.processor, type: import, entity: %oro_user.entity.class%, alias: oro_user.add_or_replace }- { name: oro_importexport.processor, type: import_validation, entity: %oro_user.entity.class%, alias: oro_user.add_or_replace }# Export processororo_user.importexport.processor.export:parent: oro_importexport.processor.export_abstractcalls:- [setDataConverter, [@oro_user.importexport.data_converter]]tags:- { name: oro_importexport.processor, type: export, entity: %oro_user.entity.class%, alias: oro_user }oro_user.importexport.processor.export_template:parent: oro_importexport.processor.export_abstractcalls:- [setDataConverter, [@oro_user.importexport.template_fixture.data_converter.account]]tags:- { name: oro_importexport.processor, type: export_template, entity: %oro_user.entity.class%, alias: oro_user }oro_user.importexport.template_fixture.account:class: %oro_user.importexport.template_fixture.account.class%tags:- { name: oro_importexport.template_fixture }Thanks again,
Alex
January 20, 2015 at 8:13 am #33686First of all you should use own aliases
Next, if you configure `importProcessor: ‘atf_vehicle.add_or_replace’,` import processor you should define proper import processor:
12345678910your_entity.importexport.processor.import:parent: oro_importexport.processor.import_abstractcalls:- [setDataConverter, [@your_data_converter_or_default_one]]- [setStrategy, [@your_strategy_or_use_default_one]]tags:- { name: oro_importexport.processor, type: import, entity: %atf.vehicle.entity.class%, alias: atf_vehicle.add_or_replace }- { name: oro_importexport.processor, type: import_validation, entity: %atf.vehicle.entity.class%, alias: atf_vehicle.add_or_replace }Entity class and tag alias should in button and service configuration
January 20, 2015 at 6:58 pm #33687Hi mate
Sorry that was the wrong file,
End of a long day….
1234567891011121314151617181920212223242526272829303132333435363738394041424344parameters:atf_vehicle.importexport.template_fixture.vehicle.class: Atf\Bundle\QuotesBundle\ImportExport\TemplateFixture\VehicleFixtureservices:atf_vehicle.importexport.data_converter:parent: oro_importexport.data_converter.configurableatf_vehicle.importexport.template_fixture.data_converter.vehicle:parent: oro_importexport.data_converter.template_fixture.configurable# Strategyatf_vehicle.importexport.strategy.vehicle.add_or_replace:parent: oro_importexport.strategy.configurable_add_or_replace# Import processoratf_vehicle.importexport.processor.import:parent: oro_importexport.processor.import_abstractcalls:- [setDataConverter, [@atf_vehicle.importexport.data_converter]]- [setStrategy, [@atf_vehicle.importexport.strategy.vehicle.add_or_replace]]tags:- { name: oro_importexport.processor, type: import, entity: %atf.vehicle.entity.class%, alias: atf_vehicle.add_or_replace }- { name: oro_importexport.processor, type: import_validation, entity: %atf.vehicle.entity.class%, alias: atf_vehicle.add_or_replace }# Export processoratf_vehicle.importexport.processor.export:parent: oro_importexport.processor.export_abstractcalls:- [setDataConverter, [@atf_vehicle.importexport.data_converter]]tags:- { name: oro_importexport.processor, type: export, entity: %atf.vehicle.entity.class%, alias: atf_vehicle }atf_vehicle.importexport.processor.export_template:parent: oro_importexport.processor.export_abstractcalls:- [setDataConverter, [@atf_vehicle.importexport.template_fixture.data_converter.vehicle]]tags:- { name: oro_importexport.processor, type: export_template, entity: %atf.vehicle.entity.class%, alias: atf_vehicle }atf_vehicle.importexport.template_fixture.vehicle:class: %atf_vehicle.importexport.template_fixture.vehicle.class%tags:- { name: oro_importexport.template_fixture }This is the actual file, the entity obviously is atf_vehicle
Thanks again for your quick help,
Alex
January 21, 2015 at 4:06 am #33688Got it, thanks!
entity_class does not accept parameter name, please pass entity class to button configuration from controller
12345return ['entity_class' => $this->container->getParameter('atf.vehicle.entity.class')];button configuration:
1entity_class: entity_class,May 4, 2015 at 10:42 am #33689Hi,
I’m new developper with or_platform and i have an error just with doing an import process
I want to test the import functionality
I have created an entity named RcUser using doctrine1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889use Doctrine\ORM\Mapping as ORM;use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;use Oro\Bundle\DataAuditBundle\Metadata\Annotation as Oro;use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;/*** RcUser** @ORM\Table(name="rc_user")* @ORM\Entity*/class RcUser{/*** @var integer** @ORM\Column(name="id", type="integer")* @ORM\Id* @ORM\GeneratedValue(strategy="AUTO")* @ConfigField(* defaultValues={* "importexport"={* "identity"=true,* "order"=10* }* }* )*/private $id;/*** @var string** @ORM\Column(name="username", type="string", length=255)* @ConfigField(* defaultValues={* "importexport"={* "order"=20* }* }* )*/private $username;/*** @var string** @ORM\Column(name="firstname", type="string", length=255)* @ConfigField(* defaultValues={* "importexport"={* "order"=30* }* }* )*/private $firstname;/*** @var string** @ORM\Column(name="lastname", type="string", length=255)* @ConfigField(* defaultValues={* "importexport"={* "order"=40* }* }* )*/private $lastname;/*** @var string** @ORM\Column(name="email", type="string", length=255)* @ConfigField(* defaultValues={* "importexport"={* "order"=50* }* }* )*/private $email;in my import-export.yml i have this configuration that i didn’t understand so much
1234567891011121314151617181920212223242526272829303132333435363738394041424344services:user.importexport.template_fixture.user:class: %orocrm_contact.importexport.template_fixture.contact.class%tags:- { name: oro_importexport.template_fixture }# Normalizersorocrm_rc_user.importexport.normalizer.rc_user:class: %rc_user.importexport.normalizer.rc_user.class%parent: oro_importexport.serializer.configurable_entity_normalizertags:- { name: oro_importexport.normalizer }# Converterorocrm_rc_user.importexport.data_converter.rc_user:parent: oro_importexport.data_converter.configurableorocrm_rc_user.importexport.template_fixture.data_converter.rc_user:parent: oro_importexport.data_converter.template_fixture.configurable#Strategyorocrm_rc_user.importexport.strategy.rc_user.add_or_replace:class: %rc_user.importexport.strategy.rc_user.add_or_replace.class%parent: oro_importexport.strategy.configurable_add_or_replace# Import processororocrm_rc_user.importexport.processor.import.add_or_replace:parent: oro_importexport.processor.import_abstractcalls:- [setDataConverter, [@orocrm_rc_user.importexport.data_converter.rc_user]]- [setStrategy, [@orocrm_rc_user.importexport.strategy.rc_user.add_or_replace]]tags:- { name: oro_importexport.processor, type: import, entity: %rc_user_crud.entity.class%, alias: orocrm_rc_user.add_or_replace }- { name: oro_importexport.processor, type: import_validation, entity: %rc_user_crud.entity.class%, alias: orocrm_rc_user.add_or_replace }# Export processororocrm_rc_user.importexport.processor.export:parent: oro_importexport.processor.export_abstractcalls:- [setDataConverter, [@orocrm_rc_user.importexport.data_converter.rc_user]]tags:- { name: oro_importexport.processor, type: export, entity: %rc_user_crud.entity.class%, alias: rc_user }orocrm_contact.importexport.processor.export_template:parent: oro_importexport.processor.export_abstractcalls:- [setDataConverter, [@orocrm_rc_user.importexport.template_fixture.data_converter.rc_user]]tags:- { name: oro_importexport.processor, type: export_template, entity: %rc_user_crud.entity.class%, alias: rc_user }the normalizer, i didn’t change anything just doing with the default configuration
123456789101112131415161718192021222324252627282930313233343536373839404142class RcuserNormalizer extends ConfigurableEntityNormalizer{const RCUSER_TYPE = 'RC\PlatformBundle\Entity\RcUser';/*** {@inheritdoc}*/public function normalize($object, $format = null, array $context = array()){error_log("\n>>" . var_export("this is normalizer", true), 3, '/Applications/MAMP/htdocs/oroplatform/error.log');$result = parent::normalize($object, $format, $context);return $result;}/*** {@inheritdoc}*/public function denormalize($data, $class, $format = null, array $context = array()){error_log("\n>> this is denormalizer before result" . var_export( $data, true), 3, '/Applications/MAMP/htdocs/oroplatform/error.log');$res= parent::denormalize($data, $class, $format, $context);error_log("\n>> this is denormalizer result" . var_export( $res, true), 3, '/Applications/MAMP/htdocs/oroplatform/error.log');return $res;}/*** {@inheritdoc}*/public function supportsNormalization($data, $format = null, array $context = array()){return $data instanceof RcUser;}/*** {@inheritdoc}*/public function supportsDenormalization($data, $type, $format = null, array $context = array()){return is_array($data) && $type == static::RCUSER_TYPE;}}also for the strategy
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859class RcUserAddOrReplaceStrategy extends ConfigurableAddOrReplaceStrategy{/*** {@inheritdoc}*/protected function importExistingEntity($entity,$existingEntity,$itemData=null,array $excludedFields = array()) {error_log("\n>>" . var_export("this is strategy importExistingEntity", true), 3, '/Applications/MAMP/htdocs/oroplatform/error.log');parent::importExistingEntity($entity, $existingEntity, $itemData, $excludedFields);}/*** {@inheritdoc}*/public function process($entity){error_log("\n>> this is strategy PROCESS" . var_export($entity, true), 3, '/Applications/MAMP/htdocs/oroplatform/error.log');$entity = parent::process($entity);return $entity;}/*** {@inheritdoc}*/protected function beforeProcessEntity($entity){/** @var RcUser $entity */$entity = parent::beforeProcessEntity($entity);error_log("\n>> this is strategy beforeProcessEntity" . var_export($entity, true), 3, '/Applications/MAMP/htdocs/oroplatform/error.log');return $entity;}/*** {@inheritdoc}*/protected function afterProcessEntity($entity){/** @var RcUser $entity */$entity = parent::afterProcessEntity($entity);error_log("\n>> this is strategy afterProcessEntity" . var_export($entity, true), 3, '/Applications/MAMP/htdocs/oroplatform/error.log');return $entity;}/*** {@inheritdoc}*/protected function findEntityByIdentityValues($entityName, array $identityValues){return parent::findEntityByIdentityValues($entityName, $identityValues);}}in my dev log there is this is error
batch.ERROR: Encountered an error executing the step: An exception occurred while executing ‘INSERT INTO rc_user (username, firstname, lastname, email) VALUES (?, ?, ?, ?)’ with params [null, null, null, null]:in the log that i generate to see from where the problem is
>> this is denormalizer resultRC\PlatformBundle\Entity\RcUser::__set_state(array(
‘id’ => NULL,
‘username’ => NULL,
‘firstname’ => NULL,
‘lastname’ => NULL,
’email’ => NULL,
))
>>this is process ObjectRC\PlatformBundle\Entity\RcUser::__set_state(array(
‘id’ => NULL,
‘username’ => NULL,
‘firstname’ => NULL,
‘lastname’ => NULL,
’email’ => NULL,
)i have also add some log in the parent class of ConfigurableEntityNormalizer
12345public function denormalize($data, $class, $format = null, array $context = []){$result = $this->createObject($class);$fields = $this->fieldHelper->getFields($class, true);error_log("\n>> this is denormalizer parent class fields" . var_export( $fields, true), 3, '/Applications/MAMP/htdocs/oroplatform/error.log');i have this log
>> this is denormalizer parent class class’RC\\PlatformBundle\\Entity\\RcUser’
>> this is denormalizer parent fieldhelper objectclass’Oro\\Bundle\\ImportExportBundle\\Field\\FieldHelper’
>> this is denormalizer parent class fieldsarray (
)please help,
Thanks - AuthorReplies
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.