OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM OroCRM – How do I? Questions The import (channel) doesn't update last sync date – onFinish() listener. Why?

This topic contains 17 replies, has 2 voices, and was last updated by  Adam 5 years, 11 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #29633

    Adam
    Participant

    Hello,

    I have an orders/customers import based on API which has been created on a channel. I have noticed that when an API call returns an empty array then the script jump to onFinish() in my listener import method where supposed to update last sync date, but when an API call is empty then the script doesn’t update this date. Why is that? There is no any PHP condition to prevent it. This part of code should be always done.

Viewing 15 replies - 1 through 15 (of 17 total)
  • Author
    Replies
  • #29634

    Andrey Yatsenko
    Moderator

    Hi Adam,
    Can you share code of the listener you created and the declaration in services.yml to understand to what event it subscribed and that subscription made right?

    #29635

    Adam
    Participant

    Hi Andrey,

    Part of the listener onFinish() method:

    services.yml

    There is nothing tricky. There is something in ORO CRM what prevents to update this last sync date when API request is empty, but I need to update this date. It’s crucial.

    • This reply was modified 5 years, 11 months ago by  Adam.
    • This reply was modified 5 years, 11 months ago by  Adam.
    • This reply was modified 5 years, 11 months ago by  Adam.
    #29639

    Adam
    Participant

    There are no error logs in log files as well. /app/logs/

    • This reply was modified 5 years, 11 months ago by  Adam.
    #29641

    Andrey Yatsenko
    Moderator

    Do you have any related errors in log. The event can not be triggered when sync finished with errors?

    #29642

    Adam
    Participant

    There are no errors in /app/logs/, nothing in there. It does not make any sense. I have tested couple different scenarios and if an API call doesn’t return anything then CRM doesn’t update last sync date. If there are orders in the API call ORO updates date.

    • This reply was modified 5 years, 11 months ago by  Adam.
    #29644

    Adam
    Participant

    Should I use this method:

    rather than:

    ????

    #29645

    Andrey Yatsenko
    Moderator

    Don’t think so, as computeChangeSet is internal doctrine thing and it should be used only on doctrine listeners. Also everything should be already flushed so event called out of transaction there is no reason to work directly with UnitOfWork

    #29646

    Andrey Yatsenko
    Moderator

    You can debug message consumer, starting from this method \Oro\Bundle\IntegrationBundle\Async\SyncIntegrationProcessor::process to see whats happening on API returing empty result.
    I recently recorded a video how to debug message consumer, this may help

    #29647

    Adam
    Participant

    I have found this PHP computeChangeSet() method in oro crm doc, see below:

    https://oroinc.com/orocrm/doc/2.3/cookbook/how-to-add-entity-event-listeners#configuring-the-listener

    #29648

    Andrey Yatsenko
    Moderator

    You are subscribing to different type of event. computeChangeSet should be used only for doctrine event listeners.

    #29649

    Adam
    Participant

    oh, right! I understand it now. However, still don’t know what could happen?

    #29650

    Adam
    Participant

    @Andrey, I have swapped to computeChangeSet() method and it’s working. It saves all of the values.

    #29651

    Andrey Yatsenko
    Moderator

    Just checked the doctrine code.
    EntityManager::flush() just call UnitOfWork::commit() that call computeChangeSet in case you don’t pass any arguments to ‘flush’
    https://github.com/doctrine/doctrine2/blob/2.5/lib/Doctrine/ORM/UnitOfWork.php#L340

    But it also do a lot of other work, like dispatching events, so calling ‘computeChangeSet’ outside of doctrine event listener is not safe as it will not trigger listeners to this or related entities and broke some other staff like inserting new related entities.

    So it’s recommended to replace computeChangeSet with flush back, but don’t pass arguments to it.

    Just change

    to

    #29654

    Adam
    Participant

    Sorry, I have used this recomputeSingleEntityChangeSet().

    Please, take a look at this tutorial regards to this method:

    http://vvv.tobiassjosten.net/symfony/update-associated-entities-in-doctrine/

    What about this method? However, your solution with use only flush() works as well :)

    I have no idea, how is this even possible, that once it works, in another case it doesn’t work… magic.

    #29655

    Adam
    Participant

    It was triggered but the changes made to the series were not persisted to the database. Since you do not have access to the entity manager in these callbacks, there is furthermore no way to force a persist/flush from here.

Viewing 15 replies - 1 through 15 (of 17 total)

The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.

Back to top