Search code examples
phpexportintegrationsugarcrmsugarbean

SugarCRM 6.5.26 CE - contacts export using SugarBean [php]


I've got SugarCrm plugin which is exporting data to external service. I'm using logic hooks for updated/deleted/new Contacts, but I've got problem with synchronizing already existing data. I have to extract all the data from the SugarCRM and there are two SugarBean methods I've tried to use: get_full_list() and get_list(). First one gives me the full Contact list, but I need to send it in batches 1000 Contacts in one Json max, the second method returns only first page of the Contacts (depends on config settings 10 - 1000max entries).

I'm using this method ATM:

    // prepare contacts data from SugarBean
    $bean = BeanFactory::getBean($module);
    $contactResults = $bean->get_full_list();

Then foreach on $contactResults and save the data I want to the required format and send it as a Json via postrequest. I've tried to find the solution to split it into batches, but Im stuck :( Neither get_full_list or get_list seems to work for me.

Any suggestions? Maybe someone solved this issue already? Thanks in advance!


Solution

  • It sounds to me like your problem is creating batches? If not please be more specific about what isn't working.

    • For splitting an array into batches, you may want to have a look at https://php.net/manual/en/function.array-chunk.php
    • Also get_list supports retrieving later pages. It is defined like this: function get_list($order_by = "", $where = "", $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0, $singleSelect=false, $select_fields = array()). That means for the second page you could specify $row_offset = 1000, for the third page make it 2000, etc. So basically run a loop that calls get_list with $limit = 1000 and increases an initial $row_offset of 0 by 1000 after each iteration, until less than 1000 records or null is returned by the function.

    Here are some general hints if you run into problems with processing those beans:

    • If the problem you're having is incomplete data, try loading each bean manually by using its ID. Some Sugar functions don't load all (special) fields by default.
    • If things seem to just fail for no reason, make sure to check your PHP log for errors. Maybe loading as many beans at once could possibly cause problems with your PHP's max_execution_time or memory_limit.