Пример #1
0
 public static function onAuthenticate($requestID, $user, $hook, &$err, $hook_data, $callback_config)
 {
     // Get an API instance
     $API = QuickBooks_API_Singleton::getInstance();
     $Integrator = QuickBooks_Integrator_Singleton::getInstance();
     $module = get_class($Integrator);
     // This is the *very first time the integration was run!*
     //	Orders *will not* be fetched from before this time!
     $type = null;
     $opts = null;
     //$first_datetime = $API->configRead(get_class($this), 'initial', $type, $opts);
     $first_datetime = $API->configRead($module, 'initial', $type, $opts);
     $first = false;
     if (!$first_datetime) {
         $first_datetime = date('Y-m-d H:i:s');
         $API->configWrite($module, 'initial', $first_datetime);
         $first = true;
     }
     // The is the last time the integration was run!
     $type = null;
     $opts = null;
     $last_datetime = $API->configRead($module, 'datetime', $type, $opts);
     if (!$last_datetime) {
         $last_datetime = date('Y-m-d H:i:s');
     }
     /*
     if (!empty($this->_integrator_config['debug_datetime']))
     {
     	$last_datetime = date('Y-m-d H:i:s', strtotime($this->_integrator_config['debug_datetime']));
     	$first_datetime = date('Y-m-d H:i:s', strtotime($this->_integrator_config['debug_datetime']));
     }
     */
     $force = false;
     /*
     $force = false;
     if (isset($_GET['OrderID']))
     {
     	$force = true;
     }
     */
     $this_datetime = date('Y-m-d H:i:s');
     $API->log('Integration handle() has started: [first: ' . $first_datetime . '], [last: ' . $last_datetime . '], [this: ' . $this_datetime . ']', QUICKBOOKS_LOG_VERBOSE);
     /*
     		if (strtotime($this_datetime) - strtotime($last_datetime) > QUICKBOOKS_SERVER_INTEGRATOR_RECUR or 
     $first or 
     $force)
     		{
     $API->log('Last integration timestamp: ' . $last_datetime . ', current timestamp: ' . $this_datetime, QUICKBOOKS_LOG_VERBOSE);
     */
     // Do some integration routines
     QuickBooks_Callbacks_Integrator_Callbacks::_integrate($last_datetime, $first_datetime, $first);
     $API->configWrite($module, 'datetime', $this_datetime);
     /*}
     		else
     		{
     			$API->log('Integration was not due yet (only ' . (strtotime($this_datetime) - strtotime($last_datetime)) . ' seconds since last run)', QUICKBOOKS_LOG_DEVELOP);
     		}
     		*/
 }