Example #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 = "PENDINGID";
     $this->SetOrder($sOrder);
     $this->Select($p_oMaster);
     $oNonMaster = new CRowtblpending();
     $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_nPendingId > $oNonMaster->GetPendingId()) {
                     $nCompare = 1;
                 } else {
                     if ($this->m_nPendingId < $oNonMaster->GetPendingId()) {
                         $nCompare = -1;
                     }
                 }
             }
         }
         if ($nCompare == 0) {
             $nUpdate = 0;
             if ($nUpdate != 0) {
                 if ($p_nSystemId == -1) {
                     $nUpdate = 1;
                 } else {
                     if ($oNonMaster->GetPendingId() <= $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->GetPendingId() <= $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_nPendingId <= $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;
 }