【问题标题】:Consolibyte Quickbooks PHP web connector cannot sync all vendorsConsolibyte Quickbooks PHP Web 连接器无法同步所有供应商
【发布时间】:2017-02-03 15:08:06
【问题描述】:

我希望将所有 Quickbooks 供应商同步到我的 Web 应用程序,但是我遇到了一个问题,我只能得到 10 个结果(不是我需要的 5500 个)它将请求发送到 QWC,得到 10 个请求,然后再次运行自上次运行(几秒钟前)以来更新的请求,而不是继续同步剩余的供应商。我确定我错过了一些重要的东西。我知道它一次同步 10 个,但它不应该继续一次获取 10 个,直到没有更多可获取?

我的代码主要基于这个例子:https://github.com/consolibyte/quickbooks-php/blob/master/docs/web_connector/example_web_connector_import.php

这里有一些代码sn-ps:

Quickbooks 处理控制器 - index 方法处理 QB 请求。供应商函数单独存储并在下面列出。

<?php


define('QB_QUICKBOOKS_CONFIG_LAST', 'last');
define('QB_QUICKBOOKS_CONFIG_CURR', 'curr');
define('QB_QUICKBOOKS_MAX_RETURNED', 10);
define('QB_QUICKBOOKS_MAILTO', '...');

class QuickbooksController extends Controller {

    public function index() {
        QuickBooks_WebConnector_Queue_Singleton::initialize($this->dsn);
        $queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
        $queue->enqueue(QUICKBOOKS_IMPORT_VENDOR, 1, QB_PRIORITY_VENDOR);
        $server = new QuickBooks_WebConnector_Server($this->dsn, $this->map, $this->errmap, $this->hooks, $this->log_level, $this->soapserver, QUICKBOOKS_WSDL, $this->soap_options, $this->handler_options, $this->driver_options, $this->callback_options);
        $response = $server->handle(true, true);
    }


    public function __construct() {
        $this->loadHelper('accounting.quickbooks.vendors');
        date_default_timezone_set('America/New_York');
        $this->user = 'internal';
        $this->pass = 'BrownBadgerPizza';

        $this->map = [
            QUICKBOOKS_IMPORT_VENDOR => array( 'vendorImportRequest', 'vendorImportResponse' ),
        ];
        $this->errmap = [
            500 => '_quickbooks_handle_500',
        ];
        $this->hooks = array(
            QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => '_quickbooks_hook_loginsuccess',
        );
        $this->log_level = QUICKBOOKS_LOG_DEBUG;
        $this->soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;
        $this->handler_options = [
            'deny_concurrent_logins' => false,
            'deny_reallyfast_logins' => false,
        ];
        $this->driver_options = [];
        $this->callback_options = [];
        $this->dsn = '...',
        define('QB_QUICKBOOKS_DSN', $this->dsn);
    }

    public function support() {
        header("HTTP/1.1 200 OK");
    }
}

function _quickbooks_hook_loginsuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config) {
    $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
    $date = '1983-01-02 12:01:01';
    if (!_quickbooks_get_last_run($user, QUICKBOOKS_IMPORT_VENDOR))
    {
        _quickbooks_set_last_run($user, QUICKBOOKS_IMPORT_VENDOR, $date);
    }
    $Queue->enqueue(QUICKBOOKS_IMPORT_VENDOR, 1, QB_PRIORITY_VENDOR);
}

function _quickbooks_get_last_run($user, $action) {
    $type = null;
    $opts = null;
    return QuickBooks_Utilities::configRead(QB_QUICKBOOKS_DSN, $user, md5(__FILE__), QB_QUICKBOOKS_CONFIG_LAST . '-' . $action, $type, $opts);
}


function _quickbooks_set_last_run($user, $action, $force = null) {
    $value = date('Y-m-d') . 'T' . date('H:i:s');
    if ($force) {
        $value = date('Y-m-d', strtotime($force)) . 'T' . date('H:i:s', strtotime($force));
    }
    return QuickBooks_Utilities::configWrite(QB_QUICKBOOKS_DSN, $user, md5(__FILE__), QB_QUICKBOOKS_CONFIG_LAST . '-' . $action, $value);
}

function _quickbooks_get_current_run($user, $action)
{
    $type = null;
    $opts = null;
    return QuickBooks_Utilities::configRead(QB_QUICKBOOKS_DSN, $user, md5(__FILE__), QB_QUICKBOOKS_CONFIG_CURR . '-' . $action, $type, $opts);
}

function _quickbooks_set_current_run($user, $action, $force = null)
{
    $value = date('Y-m-d') . 'T' . date('H:i:s');

    if ($force)
    {
        $value = date('Y-m-d', strtotime($force)) . 'T' . date('H:i:s', strtotime($force));
    }

    return QuickBooks_Utilities::configWrite(QB_QUICKBOOKS_DSN, $user, md5(__FILE__), QB_QUICKBOOKS_CONFIG_CURR . '-' . $action, $value);
}

function _quickbooks_handle_500($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg) {
    return true;
}

供应商请求:

function vendorImportRequest($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale) {
    $attr_iteratorID = '';
    $attr_iterator = ' iterator="Start" ';
    if (empty($extra['iteratorID'])) {
        $last = _quickbooks_get_last_run($user, $action);
        _quickbooks_set_last_run($user, $action);
        _quickbooks_set_current_run($user, $action, $last);
    } else {
        $attr_iteratorID = ' iteratorID="' . $extra['iteratorID'] . '" ';
        $attr_iterator = ' iterator="Continue" ';
        $last = _quickbooks_get_current_run($user, $action);
    }
    $xml = '<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="' . $version . '"?>
        <QBXML>
            <QBXMLMsgsRq onError="stopOnError">
                <VendorQueryRq ' . $attr_iterator . ' ' . $attr_iteratorID . ' requestID="' . $requestID . '">
                    <MaxReturned>' . QB_QUICKBOOKS_MAX_RETURNED . '</MaxReturned>
                    <FromModifiedDate>' . $last . '</FromModifiedDate>
                    <OwnerID>0</OwnerID>
                </VendorQueryRq>
            </QBXMLMsgsRq>
        </QBXML>';
    return $xml;
}

供应商回应:

function vendorImportResponse($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents) {
    if (!empty($idents['iteratorRemainingCount'])) {
        $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
        $Queue->enqueue(QUICKBOOKS_IMPORT_VENDOR, null, QB_PRIORITY_VENDOR, array( 'iteratorID' => $idents['iteratorID'] ));
    }
... do things with XML

非常感谢您的帮助。

编辑:

第一次尝试同步所有供应商后的 quickbooks_queue 表结果

qb_action    ident extra qbxml priority qb_status enqueue_datetime      dequeue_datetime      msg
VendorImport             1     4        e         2017-02-03 13:15:34   2017-02-03 13:15:341: A query request did not find a matching object in QuickBooks
VendorImport             1     4        q         2017-02-03 13:15:38   NULL

quickbooks_log 表

Handler is starting up...: Array
(
   [qb_company_file] => 
   [qbwc_min_version] => 
   [qbwc_wait_before_next_update] => 
   [qbwc_min_run_every_n_seconds] => 
   [qbwc_version_warning_message] => 
   [qbwc_version_error_message] => 
   [qbwc_interactive_url] => 
   [autoadd_missing_requestid] => 1
   [check_valid_requestid] => 1
   [server_version] => PHP QuickBooks SOAP Server v3.0 at /route.php/quickbooks
   [authenticate] => 
   [authenticate_dsn] => 
   [map_application_identifiers] => 1
   [allow_remote_addr] => Array
       (
       )

   [deny_remote_addr] => Array
       (
       )

   [convert_unix_newlines] => 1
   [deny_concurrent_logins] => 
   [deny_concurrent_timeout] => 60
   [deny_reallyfast_logins] => 
   [deny_reallyfast_timeout] => 600
   [masking] => 1
)
sendRequestXML()
Dequeued: ( VendorImport, 1 )
Outgoing XML request: <?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<VendorQueryRq  iterator="Start"   requestID="318">
<MaxReturned>10</MaxReturned>
<FromModifiedDate></FromModifiedDate>
<OwnerID>0</OwnerID>
</VendorQueryRq>
</QBXMLMsgsRq>
</QBXML>
Handler is starting up...: Array
(
   [qb_company_file] => 
   [qbwc_min_version] => 
   [qbwc_wait_before_next_update] => 
   [qbwc_min_run_every_n_seconds] => 
   [qbwc_version_warning_message] => 
   [qbwc_version_error_message] => 
   [qbwc_interactive_url] => 
   [autoadd_missing_requestid] => 1
   [check_valid_requestid] => 1
   [server_version] => PHP QuickBooks SOAP Server v3.0 at /route.php/quickbooks
   [authenticate] => 
   [authenticate_dsn] => 
   [map_application_identifiers] => 1
   [allow_remote_addr] => Array
       (
       )

   [deny_remote_addr] => Array
       (
       )

   [convert_unix_newlines] => 1
   [deny_concurrent_logins] => 
   [deny_concurrent_timeout] => 60
   [deny_reallyfast_logins] => 
   [deny_reallyfast_timeout] => 600
   [masking] => 1
)
receiveResponseXML()
Incoming XML response:
10 vendors of data ...
25% complete...
Handler is starting up...: Array
(
   [qb_company_file] => 
   [qbwc_min_version] => 
   [qbwc_wait_before_next_update] => 
   [qbwc_min_run_every_n_seconds] => 
   [qbwc_version_warning_message] => 
   [qbwc_version_error_message] => 
   [qbwc_interactive_url] => 
   [autoadd_missing_requestid] => 1
   [check_valid_requestid] => 1
   [server_version] => PHP QuickBooks SOAP Server v3.0 at /route.php/quickbooks
   [authenticate] => 
   [authenticate_dsn] => 
   [map_application_identifiers] => 1
   [allow_remote_addr] => Array
       (
       )

   [deny_remote_addr] => Array
       (
       )

   [convert_unix_newlines] => 1
   [deny_concurrent_logins] => 
   [deny_concurrent_timeout] => 60
   [deny_reallyfast_logins] => 
   [deny_reallyfast_timeout] => 600
   [masking] => 1
)
sendRequestXML()
Dequeued: ( VendorImport, 1 )
Outgoing XML request: <?xml version="1.0" encoding="utf-8"?>
<?qbxml version="13.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<VendorQueryRq  iterator="Start"   requestID="1">
<MaxReturned>10</MaxReturned>
<FromModifiedDate>2017-02-03T13:15:32</FromModifiedDate>
<OwnerID>0</OwnerID>
</VendorQueryRq>
</QBXMLMsgsRq>
</QBXML>
Handler is starting up...: Array
(
   [qb_company_file] => 
   [qbwc_min_version] => 
   [qbwc_wait_before_next_update] => 
   [qbwc_min_run_every_n_seconds] => 
   [qbwc_version_warning_message] => 
   [qbwc_version_error_message] => 
   [qbwc_interactive_url] => 
   [autoadd_missing_requestid] => 1
   [check_valid_requestid] => 1
   [server_version] => PHP QuickBooks SOAP Server v3.0 at /route.php/quickbooks
   [authenticate] => 
   [authenticate_dsn] => 
   [map_application_identifiers] => 1
   [allow_remote_addr] => Array
       (
       )

   [deny_remote_addr] => Array
       (
       )

   [convert_unix_newlines] => 1
   [deny_concurrent_logins] => 
   [deny_concurrent_timeout] => 60
   [deny_reallyfast_logins] => 
   [deny_reallyfast_timeout] => 600
   [masking] => 1
)
receiveResponseXML()
Incoming XML response: <?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<VendorQueryRs requestID="1" statusCode="1" statusSeverity="Info" statusMessage="A query request did not find a matching object in QuickBooks" iteratorRemainingCount="0" iteratorID="{a7b4ed15-9612-4fe8-aa3c-31ee60b7b491}" />
</QBXMLMsgsRs>
</QBXML>
Attempting to handle error: 1, A query request did not find a matching object in QuickBooks
Handled error: 1: A query request did not find a matching object in QuickBooks (handler returned: )
Transaction error at -1% complete...
Handler is starting up...: Array
(
   [qb_company_file] => 
   [qbwc_min_version] => 
   [qbwc_wait_before_next_update] => 
   [qbwc_min_run_every_n_seconds] => 
   [qbwc_version_warning_message] => 
   [qbwc_version_error_message] => 
   [qbwc_interactive_url] => 
   [autoadd_missing_requestid] => 1
   [check_valid_requestid] => 1
   [server_version] => PHP QuickBooks SOAP Server v3.0 at /route.php/quickbooks
   [authenticate] => 
   [authenticate_dsn] => 
   [map_application_identifiers] => 1
   [allow_remote_addr] => Array
       (
       )

   [deny_remote_addr] => Array
       (
       )

   [convert_unix_newlines] => 1
   [deny_concurrent_logins] => 
   [deny_concurrent_timeout] => 60
   [deny_reallyfast_logins] => 
   [deny_reallyfast_timeout] => 600
   [masking] => 1
)
getLastError()
Handler is starting up...: Array
(
   [qb_company_file] => 
   [qbwc_min_version] => 
   [qbwc_wait_before_next_update] => 
   [qbwc_min_run_every_n_seconds] => 
   [qbwc_version_warning_message] => 
   [qbwc_version_error_message] => 
   [qbwc_interactive_url] => 
   [autoadd_missing_requestid] => 1
   [check_valid_requestid] => 1
   [server_version] => PHP QuickBooks SOAP Server v3.0 at /route.php/quickbooks
   [authenticate] => 
   [authenticate_dsn] => 
   [map_application_identifiers] => 1
   [allow_remote_addr] => Array
       (
       )

   [deny_remote_addr] => Array
       (
       )

   [convert_unix_newlines] => 1
   [deny_concurrent_logins] => 
   [deny_concurrent_timeout] => 60
   [deny_reallyfast_logins] => 
   [deny_reallyfast_timeout] => 600
   [masking] => 1
)
closeConnection()

编辑 #2 在查看了日志和队列之后,我看到的是,即使我传递了iteratorID,当我得到一个具有额外结果的 XML 响应时,由于某种原因,库没有通过 @ 传递该 ID排队请求上的 987654328@ 参数。

数据库中的队列表在extra 列中有这个:a:1:{s:10:"iteratorID";s:38:"{3a096324-6e5e-4fcb-a6ac-9a2600372029}";}。但是请求函数中额外的参数是空白的。

【问题讨论】:

  • 发布日志。查看 quickbooks_queue 表,看看事情是否按照您期望的顺序处理。
  • 我添加了 quickbooks_queue 和 quickbooks_log 结果。看起来队列可能有问题,但我不确定我看到了什么。
  • 响应将包含剩余的项目数和迭代器 ID。您是否发送迭代器 id 以获取更多数据?
  • @WilliamLorfing,我遗漏的响应确实包含一个迭代器 ID,并显示为 iteratorRemainingCount="5513"。我在 VendorRequest xml 中传递它,请参见上面的代码。我添加了一些额外的日志来查看我在 $extra 变量中得到了什么。
  • @KeithPalmerJr。实际上,进入我的处理函数的 $extra 变量在第二次运行时看起来是空的。这意味着它没有获得迭代器 ID。这部分代码与文档匹配,队列在extra 列中显示:a:1:{s:10:"iteratorID";s:38:"{3a096324-6e5e-4fcb-a6ac-9a2600372029}";}

标签: php quickbooks intuit-partner-platform qbwc


【解决方案1】:

什么是 QB_QUICKBOOKS_MAX_RETURNED 值?

第一次通过后,您是否会获取返回的迭代器值并对其进行处理?

【讨论】:

  • QB_QUICKBOOKS_MAX_RETURNED 值设置为 10。我相信我正在使用迭代器 ID 进行处理。这是供应商响应处理程序队列:$Queue-&gt;enqueue(QUICKBOOKS_IMPORT_VENDOR, null, QB_PRIORITY_VENDOR, array( 'iteratorID' =&gt; $idents['iteratorID'] ));
【解决方案2】:

这可能是您的问题:

<FromModifiedDate></FromModifiedDate>

里面没有日期。

您并没有真正为我们发布足够的代码来帮助您。

【讨论】:

    【解决方案3】:

    解决方案

    我发现在我的 QBWC 处理程序函数中,我正在排队供应商导入请求。这是对登录成功队列的补充。在我删除它之后,它工作得很好。

    这是使它工作的更新:

    来自

    public function index() {
        QuickBooks_WebConnector_Queue_Singleton::initialize($this->dsn);
        $queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
        $queue->enqueue(QUICKBOOKS_IMPORT_VENDOR, 1, QB_PRIORITY_VENDOR);
        $server = new QuickBooks_WebConnector_Server($this->dsn, $this->map, $this->errmap, $this->hooks, $this->log_level, $this->soapserver, QUICKBOOKS_WSDL, $this->soap_options, $this->handler_options, $this->driver_options, $this->callback_options);
        $response = $server->handle(true, true);
    }
    

    收件人

    public function index() {
        QuickBooks_WebConnector_Queue_Singleton::initialize($this->dsn);
        $queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
        $server = new QuickBooks_WebConnector_Server($this->dsn, $this->map, $this->errmap, $this->hooks, $this->log_level, $this->soapserver, QUICKBOOKS_WSDL, $this->soap_options, $this->handler_options, $this->driver_options, $this->callback_options);
        $response = $server->handle(true, true);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 2018-03-28
      • 1970-01-01
      相关资源
      最近更新 更多