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

use as export #5

Open
Avtonom opened this issue Apr 29, 2016 · 10 comments
Open

use as export #5

Avtonom opened this issue Apr 29, 2016 · 10 comments

Comments

@Avtonom
Copy link

Avtonom commented Apr 29, 2016

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
Copy link
Author

Avtonom commented Apr 29, 2016

rewrite:

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

but jms_serializer not use

        accessor:
          getter: getFuu

@mathielen
Copy link
Owner

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

@Avtonom
Copy link
Author

Avtonom commented Apr 29, 2016

@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 )

@mathielen
Copy link
Owner

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

@Avtonom
Copy link
Author

Avtonom commented Apr 29, 2016

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
Copy link
Author

Avtonom commented Apr 29, 2016

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
Copy link
Author

Avtonom commented May 10, 2016

["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
Copy link
Author

Avtonom commented May 10, 2016

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

@mathielen
Copy link
Owner

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.

@Avtonom
Copy link
Author

Avtonom commented May 10, 2016

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

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

2 participants