ImportEngineBundle icon indicating copy to clipboard operation
ImportEngineBundle copied to clipboard

use as export

Open Avtonom opened this issue 8 years ago • 10 comments

mathielen_import_engine:
    storageprovider:
        default:
            type: doctrine
            queries:
                - AppBundle\Entity\Client
    importers:
        avantage_importer:
            object_factory:
                type: default
                class: AppBundle\Entity\Client
            target:
                type: service
                service: service_writer
                method: writeItem
    public function writeItem(Client $client)
    {
        var_dump($client);
Bobject(AppBundle\Entity\Client)#587
(4) {
  ["id":protected]=>  NULL
  ["name":protected]=>   NULL
  ["id"]=>  string(0) "123"
  ["name"]=>  string(0) "Anton"  

if use:

    $client->getName()

view:

NULL

Avtonom avatar Apr 29 '16 12:04 Avtonom

rewrite:

            object_factory:
#                type: default
#                class: AppBundle\Entity\Client
                type: jms_serializer
                class: AppBundle\Entity\Client

but jms_serializer not use

        accessor:
          getter: getFuu

Avtonom avatar Apr 29 '16 12:04 Avtonom

Hi Avtonom, If you are using the 'default' serializer, your properties (id, name) must be public, as the serializer just writes to the properties, without doing any magic :) Using the jms-serializer is recommended though.

I dont know what you mean with the accessor/getter thing in your second example? Could you elaborate it a little more?

Regards Markus

mathielen avatar Apr 29 '16 13:04 mathielen

@mathielen thank you for quick response! Configurator "getter" should call my method to get the value for the variable ( http://jmsyst.com/libs/serializer/master/reference/annotations#accessor )

Avtonom avatar Apr 29 '16 13:04 Avtonom

Ok, I see. Well, the serializer is used to build the object from the underlying array. So there wont be any getter involved, only setters. See: https://github.com/mathielen/import-engine/blob/master/src/Mathielen/DataImport/Writer/ObjectWriter/JmsSerializerObjectFactory.php

mathielen avatar Apr 29 '16 13:04 mathielen

Tell me, please, as it to solve two problems:

  1. get the value "Card" of the class ServiceWriter
    public function getCard()
    {
        return $this->card->code();
    }
  1. to get the value for the field type DateTime
    /**
     * @return \DateTime
     */
    public function getDateCreated()
    {
        return $this->dateCreated;
    }

    /**
     * @param \DateTime $dateCreated
     */
    public function setDateCreated($dateCreated)
    {
        $this->dateCreated = $dateCreated;
    }

var_dump:

 ["dateCreated":protected]=>   NULL
 ["card":protected]=>   NULL

Avtonom avatar Apr 29 '16 13:04 Avtonom

problems 2 if type = default

            object_factory:
                type: default

to var_dump

 ["dateCreated":protected]=>  NULL
 ["dateCreated"]=>  object(DateTime)#614 (3) {

but I can not get this value

Avtonom avatar Apr 29 '16 15:04 Avtonom

["dateCreated":protected]=> NULL ["dateCreated"]=> object(DateTime)#614 (3) {

solved by commenting the line "object_factory". But we get the array instead of an object. Because "Query::HYDRATE_ARRAY" in mathielen/import-engine/src/Mathielen/DataImport/Reader/DoctrineQueryReader.php:42

Avtonom avatar May 10 '16 14:05 Avtonom

now we have to get Entity->relation->Entity->name =(

Avtonom avatar May 10 '16 14:05 Avtonom

Dude, it seems like you just want to query doctrine and process the entities. You really should just use doctrine the old fashioned way :) The ImportEngineBundle is way more abstracted then you need to have. It is a wrapper around https://github.com/ddeboer/data-import, which is already very abstract. Only use the ImportEngineBundle if you have a lot of different import/export scenarios with different kind of sources and targets and complex validation and transformation requirements.

mathielen avatar May 10 '16 14:05 mathielen

Yes, I understand what you write. I develop export and want to do it on the basis of this solution. But I do not have Reader flat Entities. I need to relation. I tried using \Mathielen\DataImport\Reader\ServiceReader use that to write doctrine the old fashioned, but I get Segmentation fault

Avtonom avatar May 10 '16 14:05 Avtonom