Пример #1
0
 function Synchronise($p_oMaster, $p_oNonMaster, $p_nSystemId = 0)
 {
     $this->m_nError = $this->m_nDBO_OK;
     $p_oMaster->SetSynchronising(true);
     $p_oNonMaster->SetSynchronising(true);
     $sOrder = "COMPLETEDID";
     $this->SetOrder($sOrder);
     $this->Select($p_oMaster);
     $oNonMaster = new CRowtblcompleted();
     $oNonMaster->SetOrder($sOrder);
     $oNonMaster->Select($p_oNonMaster);
     while (!($this->GetEof() && $oNonMaster->GetEof())) {
         $nCompare = 0;
         if ($this->GetEof()) {
             $nCompare = 1;
         } else {
             if ($oNonMaster->GetEof()) {
                 $nCompare = -1;
             } else {
                 if ($this->m_nCompletedId > $oNonMaster->GetCompletedId()) {
                     $nCompare = 1;
                 } else {
                     if ($this->m_nCompletedId < $oNonMaster->GetCompletedId()) {
                         $nCompare = -1;
                     }
                 }
             }
         }
         if ($nCompare == 0) {
             $nUpdate = 0;
             if ($nUpdate != 0) {
                 if ($p_nSystemId == -1) {
                     $nUpdate = 1;
                 } else {
                     if ($oNonMaster->GetCompletedId() <= $p_nSystemId) {
                         $nUpdate = 1;
                     }
                 }
             }
             if ($nUpdate == 1) {
                 if (!$this->Update($p_oNonMaster)) {
                     $this->m_nError = $this->m_nDBO_SYNC_FAILURE;
                     $p_oMaster->SetSynchronising(false);
                     $p_oNonMaster->SetSynchronising(false);
                     return false;
                 }
             } else {
                 if (!$oNonMaster->Update($p_oMaster)) {
                     $this->m_nError = $this->m_nDBO_SYNC_FAILURE;
                     $p_oMaster->SetSynchronising(false);
                     $p_oNonMaster->SetSynchronising(false);
                     return false;
                 }
             }
             $oNonMaster->MoveNext();
             $this->MoveNext();
         } else {
             if ($nCompare > 0) {
                 if ($p_nSystemId == -1) {
                     if (!$oNonMaster->Delete($p_oNonMaster)) {
                         $this->m_nError = $this->m_nDBO_SYNC_FAILURE;
                         $p_oMaster->SetSynchronising(false);
                         $p_oNonMaster->SetSynchronising(false);
                         return false;
                     }
                 } else {
                     if ($oNonMaster->GetCompletedId() <= $p_nSystemId) {
                         if (!$oNonMaster->Delete($p_oNonMaster)) {
                             $this->m_nError = $this->m_nDBO_SYNC_FAILURE;
                             $p_oMaster->SetSynchronising(false);
                             $p_oNonMaster->SetSynchronising(false);
                             return false;
                         }
                     } else {
                         if (!$oNonMaster->Insert($p_oMaster)) {
                             $this->m_nError = $this->m_nDBO_SYNC_FAILURE;
                             $p_oMaster->SetSynchronising(false);
                             $p_oNonMaster->SetSynchronising(false);
                             return false;
                         }
                     }
                 }
                 $oNonMaster->MoveNext();
             } else {
                 if ($p_nSystemId == -1) {
                     if (!$this->Insert($p_oNonMaster)) {
                         $this->m_nError = $this->m_nDBO_SYNC_FAILURE;
                         $p_oMaster->SetSynchronising(false);
                         $p_oNonMaster->SetSynchronising(false);
                         return false;
                     }
                 } else {
                     if ($this->m_nCompletedId <= $p_nSystemId) {
                         if (!$this->Insert($p_oNonMaster)) {
                             $this->m_nError = $this->m_nDBO_SYNC_FAILURE;
                             $p_oMaster->SetSynchronising(false);
                             $p_oNonMaster->SetSynchronising(false);
                             return false;
                         }
                     } else {
                         if (!$this->Delete($p_oMaster)) {
                             $this->m_nError = $this->m_nDBO_SYNC_FAILURE;
                             $p_oMaster->SetSynchronising(false);
                             $p_oNonMaster->SetSynchronising(false);
                             return false;
                         }
                     }
                 }
                 $this->MoveNext();
             }
         }
     }
     $p_oMaster->SetSynchronising(false);
     $p_oNonMaster->SetSynchronising(false);
     return true;
 }
Пример #2
0
 $nSleep = 0;
 do {
     if ($nSleep > 0) {
         sleep(1);
     }
     $oPending->Clear();
     $oPending->SetPendingId($nKey);
     $oPending->Select($oSession);
     $nSleep++;
 } while ($nSleep < $nTimeout && $oPending->GetCompleted() != 1 && $oPending->GetCompleted() != 4);
 $bError = $nSleep == $nTimeout && $oPending->GetCompleted() != 1 && $oPending->GetCompleted() != 4;
 if ($bError) {
     $sMessage = "<error><message>Timeout</message></error>";
 } else {
     $sMessage = "";
     $oCompleted = new CRowtblcompleted();
     $oCompleted->SetPendingId($nKey);
     $oCompleted->SetOrder("CompletedId");
     $oCompleted->Select($oSession);
     $sXML = "";
     while (!$oCompleted->GetEof()) {
         if ($oCompleted->GetSuccess() == 0) {
             $sXML .= $oCompleted->GetOutXML();
             $sMode = $oCompleted->GetMode();
             if ($sMode == "") {
                 $sMode = "default";
             }
             $nIndexEnd = strpos($sXML, "/>");
             $nIndex = strpos($sXML, ">");
             if ($nIndexEnd !== FALSE && $nIndexEnd < $nIndex) {
                 $sXML = substr($sXML, 0, $nIndexEnd) . " mode=\"" . $sMode . "\" " . substr($sXML, $nIndexEnd);