| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 3 include_once 'Horde/SyncML/Sync.php'; 4 include_once 'Horde/SyncML/Command/Sync/ContentSyncElement.php'; 5 6 /** 7 * $Horde: framework/SyncML/SyncML/Sync/TwoWaySync.php,v 1.12 2004/07/26 09:24:38 jan Exp $ 8 * 9 * Copyright 2003-2004 Anthony Mills <amills@pyramid6.com> 10 * 11 * See the enclosed file COPYING for license information (LGPL). If you 12 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 13 * 14 * @author Anthony Mills <amills@pyramid6.com> 15 * @author Karsten Fourmont <fourmont@gmx.de> 16 * 17 * @version $Revision: 21683 $ 18 * @since Horde 3.0 19 * @package Horde_SyncML 20 */ 21 class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { 22 23 function endSync($currentCmdID, &$output) 24 { 25 global $registry; 26 27 $state = &$_SESSION['SyncML.state']; 28 29 $syncType = $this->_targetLocURI; 30 $hordeType = str_replace('./','',$syncType); 31 32 $refts = $state->getServerAnchorLast($syncType); 33 $currentCmdID = $this->handleSync($currentCmdID, 34 $hordeType, 35 $syncType, 36 $output, 37 $refts); 38 if ($syncType == 'calendar' && $state->handleTasksInCalendar()) { 39 Horde::logMessage("SyncML: handling tasks in calendar sync", __FILE__, __LINE__, PEAR_LOG_DEBUG); 40 41 $currentCmdID = $this->handleSync($currentCmdID, 'tasks', $syncType, 42 $output, $refts); 43 } 44 45 return $currentCmdID; 46 } 47 48 function handleSync($currentCmdID, $hordeType, $syncType,&$output, $refts) { 49 global $registry; 50 51 // array of Items which got modified, but got never send to the client before 52 $missedAdds = array(); 53 54 $history = $GLOBALS['phpgw']->contenthistory; 55 $state = &$_SESSION['SyncML.state']; 56 $counter = 0; 57 58 $changes = &$state->getChangedItems($hordeType); 59 $deletes = &$state->getDeletedItems($hordeType); 60 $adds = &$state->getAddedItems($hordeType); 61 62 Horde::logMessage("SyncML: ".count($changes).' changed items found for '.$hordeType, __FILE__, __LINE__, PEAR_LOG_DEBUG); 63 Horde::logMessage("SyncML: ".count($deletes).' deleted items found for '.$hordeType, __FILE__, __LINE__, PEAR_LOG_DEBUG); 64 Horde::logMessage("SyncML: ".count($adds). ' added items found for '.$hordeType , __FILE__, __LINE__, PEAR_LOG_DEBUG); 65 66 while($guid = array_shift($changes)) { 67 $guid_ts = $history->getTSforAction($guid, 'modify'); 68 $sync_ts = $state->getChangeTS($syncType, $guid); 69 Horde::logMessage("SyncML: timestamp modify guid_ts: $guid_ts sync_ts: $sync_ts", __FILE__, __LINE__, PEAR_LOG_DEBUG); 70 if ($sync_ts && $sync_ts == $guid_ts) { 71 // Change was done by us upon request of client. 72 // Don't mirror that back to the client. 73 Horde::logMessage("SyncML: change: $guid ignored, came from client", __FILE__, __LINE__, PEAR_LOG_DEBUG); 74 continue; 75 } 76 Horde::logMessage("SyncML: change $guid hs_ts:$guid_ts dt_ts:" . $state->getChangeTS($syncType, $guid), __FILE__, __LINE__, PEAR_LOG_DEBUG); 77 $locid = $state->getLocID($syncType, $guid); 78 if (!$locid) { 79 // somehow we missed to add, lets store the uid, so we add this entry later 80 $missedAdds[] = $guid; 81 Horde::logMessage("SyncML: unable to create change for $guid: locid not found in map", __FILE__, __LINE__, PEAR_LOG_WARNING); 82 continue; 83 } 84 85 // Create a replace request for client. 86 $contentType = $state->getPreferedContentTypeClient($this->_sourceLocURI); 87 if(is_a($contentType, 'PEAR_Error')) { 88 // Client did not sent devinfo 89 $contentType = array('ContentType' => $state->getPreferedContentType($this->_targetLocURI)); 90 } 91 $c = $registry->call($hordeType. '/export', 92 array('guid' => $guid, 'contentType' => $contentType)); 93 if (!is_a($c, 'PEAR_Error')) { 94 // Item in history but not in database. Strange, but can happen. 95 Horde::logMessage("SyncML: change: $guid export content: $c", __FILE__, __LINE__, PEAR_LOG_DEBUG); 96 $cmd = &new Horde_SyncML_Command_Sync_ContentSyncElement(); 97 # LK $cmd->setContent($state->convertServer2Client($c, $contentType)); 98 $cmd->setContent($c); 99 $cmd->setSourceURI($guid); 100 $cmd->setTargetURI($locid); 101 $cmd->setContentType($contentType['ContentType']); 102 if($hordeType == 'sifcalendar' || $hordeType == 'sifcontacts' || $hordeType == 'siftasks') { 103 $cmd->setContentFormat('b64'); 104 } 105 $currentCmdID = $cmd->outputCommand($currentCmdID, $output, 'Replace'); 106 $state->log('Server-Replace'); 107 108 // return if we have to much data 109 if(++$counter >= MAX_ENTRIES && $hordeType != 'sifcalendar' && $hordeType != 'sifcontacts' && $hordeType != 'siftasks') { 110 $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); 111 return $currentCmdID; 112 } 113 } 114 } 115 Horde::logMessage("SyncML: handling sync (changes done) ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG); 116 117 // deletes 118 while($guid = array_shift($deletes)) 119 { 120 $guid_ts = $history->getTSforAction($guid, 'delete'); 121 $sync_ts = $state->getChangeTS($syncType, $guid); 122 Horde::logMessage("SyncML: timestamp delete guid_ts: $guid_ts sync_ts: $sync_ts", __FILE__, __LINE__, PEAR_LOG_DEBUG); 123 if ($sync_ts && $sync_ts == $guid_ts) { 124 // Change was done by us upon request of client. 125 // Don't mirror that back to the client. 126 Horde::logMessage("SyncML: delete $guid ignored, came from client", __FILE__, __LINE__, PEAR_LOG_DEBUG); 127 continue; 128 } 129 $locid = $state->getLocID($syncType, $guid); 130 if (!$locid) { 131 Horde::logMessage("SyncML: unable to create delete for $guid: locid not found in map", __FILE__, __LINE__, PEAR_LOG_WARNING); 132 continue; 133 } 134 135 Horde::logMessage("SyncML: delete: $guid", __FILE__, __LINE__, PEAR_LOG_DEBUG); 136 // Create a Delete request for client. 137 $cmd = &new Horde_SyncML_Command_Sync_ContentSyncElement(); 138 $cmd->setTargetURI($locid); 139 $cmd->setSourceURI($guid); 140 $currentCmdID = $cmd->outputCommand($currentCmdID, $output, 'Delete'); 141 $state->log('Server-Delete'); 142 $state->removeUID($syncType, $locid); 143 144 // return if we have to much data 145 if(++$counter >= MAX_ENTRIES && $hordeType != 'sifcalender' && $hordeType != 'sifcontacts' &&$hordeType != 'siftasks') { 146 $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); 147 return $currentCmdID; 148 } 149 } 150 #Horde::logMessage("SyncML: handling sync ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG); 151 152 // Get adds. 153 if(count($missedAdds) > 0) { 154 Horde::logMessage("SyncML: add missed changes as adds ".count($adds).' / '.$missedAdds[0], __FILE__, __LINE__, PEAR_LOG_DEBUG); 155 $state->setAddedItems($hordeType, array_merge($adds, $missedAdds)); 156 $adds = &$state->getAddedItems($hordeType); 157 Horde::logMessage("SyncML: merged adds counter ".count($adds).' / '.$adds[0], __FILE__, __LINE__, PEAR_LOG_DEBUG); 158 } 159 160 while($guid = array_shift($adds)) { 161 $guid_ts = $history->getTSforAction($guid, 'add'); 162 $sync_ts = $state->getChangeTS($syncType, $guid); 163 Horde::logMessage("SyncML: timestamp add $guid guid_ts: $guid_ts sync_ts: $sync_ts", __FILE__, __LINE__, PEAR_LOG_DEBUG); 164 if ($sync_ts && $sync_ts == $guid_ts) { 165 // Change was done by us upon request of client. 166 // Don't mirror that back to the client. 167 Horde::logMessage("SyncML: add: $guid ignored, came from client", __FILE__, __LINE__, PEAR_LOG_DEBUG); 168 continue; 169 } 170 171 $locid = $state->getLocID($syncType, $guid); 172 173 if ($locid && $refts == 0) { 174 // For slow sync (ts=0): do not add data for which we 175 // have a locid again. This is a heuristic to avoid 176 // duplication of entries. 177 Horde::logMessage("SyncML: skipping add of guid $guid as there already is a locid $locid", __FILE__, __LINE__, PEAR_LOG_DEBUG); 178 continue; 179 } 180 Horde::logMessage("SyncML: add: $guid", __FILE__, __LINE__, PEAR_LOG_DEBUG); 181 182 // Create an Add request for client. 183 $contentType = $state->getPreferedContentTypeClient($this->_sourceLocURI); 184 if(is_a($contentType, 'PEAR_Error')) { 185 // Client did not sent devinfo 186 $contentType = array('ContentType' => $state->getPreferedContentType($this->_targetLocURI)); 187 } 188 189 $cmd = &new Horde_SyncML_Command_Sync_ContentSyncElement(); 190 $c = $registry->call($hordeType . '/export', 191 array( 192 'guid' => $guid , 193 'contentType' => $contentType , 194 ) 195 ); 196 197 if (!is_a($c, 'PEAR_Error')) { 198 // Item in history but not in database. Strange, but can happen. 199 $cmd->setContent($c); 200 if($hordeType == 'sifcalendar' || $hordeType == 'sifcontacts' || $hordeType == 'siftasks') { 201 $cmd->setContentFormat('b64'); 202 } 203 $cmd->setContentType($contentType['ContentType']); 204 $cmd->setSourceURI($guid); 205 $currentCmdID = $cmd->outputCommand($currentCmdID, $output, 'Add'); 206 $state->log('Server-Add'); 207 208 // return if we have to much data 209 if(++$counter >= MAX_ENTRIES && $hordeType != 'sifcalendar' && $hordeType != 'sifcontacts' &&$hordeType != 'siftasks') { 210 $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); 211 return $currentCmdID; 212 } 213 } 214 } 215 Horde::logMessage("SyncML: handling sync ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG); 216 217 $state->clearSync($syncType); 218 219 return $currentCmdID; 220 } 221 222 function loadData() 223 { 224 global $registry; 225 226 $state = &$_SESSION['SyncML.state']; 227 $syncType = $this->_targetLocURI; 228 $hordeType = str_replace('./','',$syncType); 229 $refts = $state->getServerAnchorLast($syncType); 230 231 Horde::logMessage("SyncML: reading changed items from database for $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 232 $state->setChangedItems($hordeType, $registry->call($hordeType. '/listBy', array('action' => 'modify', 'timestamp' => $refts))); 233 234 Horde::logMessage("SyncML: reading deleted items from database for $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 235 $state->setDeletedItems($hordeType, $registry->call($hordeType. '/listBy', array('action' => 'delete', 'timestamp' => $refts))); 236 237 Horde::logMessage("SyncML: reading added items from database for $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG); 238 $state->setAddedItems($hordeType, $registry->call($hordeType. '/listBy', array('action' => 'add', 'timestamp' => $refts))); 239 240 $this->_syncDataLoaded = TRUE; 241 242 return count($state->getChangedItems($hordeType)) + 243 count($state->getDeletedItems($hordeType)) + 244 count($state->getAddedItems($hordeType)); 245 } 246 247 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |