[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /** 3 * $Horde: framework/SyncML/SyncML/Sync.php,v 1.7 2004/09/14 04:27:05 chuck Exp $ 4 * 5 * Copyright 2003-2004 Anthony Mills <amills@pyramid6.com> 6 * 7 * See the enclosed file COPYING for license information (LGPL). If you 8 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 9 * 10 * @author Anthony Mills <amills@pyramid6.com> 11 * @version $Revision: 21249 $ 12 * @since Horde 3.0 13 * @package Horde_SyncML 14 */ 15 class Horde_SyncML_Sync { 16 17 /** 18 * Target, either contacts, notes, events, 19 */ 20 var $_targetLocURI; 21 22 var $_sourceLocURI; 23 24 /** 25 * Return if all commands success. 26 */ 27 var $globalSuccess; 28 29 /** 30 * This is the content type to use to export data. 31 */ 32 var $preferedContentType; 33 34 /** 35 * Do have the sync data loaded from the database already? 36 */ 37 var $syncDataLoaded; 38 39 function &factory($alert) 40 { 41 Horde::logMessage('SyncML: new sync for alerttype ' . $alert, __FILE__, __LINE__, PEAR_LOG_DEBUG); 42 switch ($alert) { 43 case ALERT_TWO_WAY: 44 include_once 'Horde/SyncML/Sync/TwoWaySync.php'; 45 return $sync = &new Horde_SyncML_Sync_TwoWaySync(); 46 47 case ALERT_SLOW_SYNC: 48 include_once 'Horde/SyncML/Sync/SlowSync.php'; 49 return $sync = &new Horde_SyncML_Sync_SlowSync(); 50 51 case ALERT_ONE_WAY_FROM_CLIENT: 52 include_once 'Horde/SyncML/Sync/OneWayFromClientSync.php'; 53 return $sync = &new Horde_SyncML_Sync_OneWayFromClientSync(); 54 55 case ALERT_REFRESH_FROM_CLIENT: 56 include_once 'Horde/SyncML/Sync/RefreshFromClientSync.php'; 57 return $sync = &new Horde_SyncML_Sync_RefreshFromClientSync(); 58 59 case ALERT_ONE_WAY_FROM_SERVER: 60 include_once 'Horde/SyncML/Sync/OneWayFromServerSync.php'; 61 return $sync = &new Horde_SyncML_Sync_OneWayFromServerSync(); 62 63 case ALERT_REFRESH_FROM_SERVER: 64 include_once 'Horde/SyncML/Sync/RefreshFromServerSync.php'; 65 return $sync = &new Horde_SyncML_Sync_RefreshFromServerSync(); 66 } 67 68 require_once 'PEAR.php'; 69 return PEAR::raiseError('Alert ' . $alert . ' not found.'); 70 } 71 72 function nextSyncCommand($currentCmdID, &$syncCommand, &$output) 73 { 74 $result = $this->runSyncCommand($syncCommand); 75 return $syncCommand->output($currentCmdID, $output); 76 } 77 78 function startSync($currentCmdID, &$output) 79 { 80 return $currentCmdID; 81 } 82 83 function endSync($currentCmdID, &$output) 84 { 85 return $currentCmdID; 86 } 87 88 /** 89 * Here's where the actual processing of a client-sent Sync 90 * Command takes place. Entries are added, deleted or replaced 91 * from the server database by using Horde API (Registry) calls. 92 */ 93 function runSyncCommand(&$command) { 94 #Horde::logMessage('SyncML: content type is ' . $command->getContentType() .' moreData '. $command->_moreData, __FILE__, __LINE__, PEAR_LOG_DEBUG); 95 global $registry; 96 97 $history = $GLOBALS['egw']->contenthistory; 98 99 $state = &$_SESSION['SyncML.state']; 100 101 if(isset($state->_moreData['luid'])) { 102 if(($command->_luid == $state->_moreData['luid'])) { 103 Horde::logMessage('SyncML: got next moreData chunk '.$command->getContent(), __FILE__, __LINE__, PEAR_LOG_DEBUG); 104 $lastChunks = implode('',$state->_moreData['chunks']); 105 $command->_content = $lastChunks.$command->_content; 106 $stringlen1 = strlen($lastChunks); 107 $stringlen2 = strlen($command->_content); 108 109 if(!$command->_moreData && strlen($command->_content) != $state->_moreData['contentSize']) { 110 $command->_status = RESPONSE_SIZE_MISMATCH; 111 $state->_moreData = array(); 112 113 return; 114 } elseif(!$command->_moreData && strlen($command->_content) == $state->_moreData['contentSize']) { 115 $state->_moreData = array(); 116 Horde::logMessage('SyncML: chunk ended successful type is ' . $command->getContentType() .' content is '. $command->getContent(), __FILE__, __LINE__, PEAR_LOG_DEBUG); 117 } 118 } else { 119 // alert 223 needed too 120 #$command->_status = ALERT_NO_END_OF_DATA; 121 122 $state->_moreData = array(); 123 124 return; 125 } 126 } 127 128 // don't add/replace the data currently, they are not yet complete 129 if($command->_moreData == TRUE) { 130 $state->_moreData['chunks'][] = $command->_content; 131 $state->_moreData['luid'] = $command->_luid; 132 133 // gets only set with the first chunk of data 134 if(isset($command->_contentSize)) 135 $state->_moreData['contentSize'] = $command->_contentSize; 136 137 $command->_status = RESPONSE_CHUNKED_ITEM_ACCEPTED_AND_BUFFERED; 138 Horde::logMessage('SyncML: added moreData chunk '.$command->getContent(), __FILE__, __LINE__, PEAR_LOG_DEBUG); 139 140 return; 141 } 142 143 $hordeType = $type = $this->_targetLocURI; 144 // remove the './' from the beginning 145 $hordeType = str_replace('./','',$hordeType); 146 if(!$contentType = $command->getContentType()) { 147 $contentType = $state->getPreferedContentType($type); 148 } 149 150 if ($this->_targetLocURI == 'calendar' && strpos($command->getContent(), 'BEGIN:VTODO') !== false) { 151 $hordeType = 'tasks'; 152 } 153 154 $syncElementItems = $command->getSyncElementItems(); 155 156 foreach($syncElementItems as $syncItem) { 157 158 $guid = false; 159 160 if (is_a($command, 'Horde_SyncML_Command_Sync_Add')) { 161 $guid = $registry->call($hordeType . '/import', 162 array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType)); 163 164 if (!is_a($guid, 'PEAR_Error')) { 165 $ts = $history->getTSforAction($guid, 'add'); 166 $state->setUID($type, $syncItem->getLocURI(), $guid, $ts); 167 $state->log("Client-Add"); 168 Horde::logMessage('SyncML: added client entry as ' . $guid, __FILE__, __LINE__, PEAR_LOG_DEBUG); 169 } else { 170 $state->log("Client-AddFailure"); 171 Horde::logMessage('SyncML: Error in adding client entry:' . $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR); 172 } 173 } elseif (is_a($command, 'Horde_SyncML_Command_Sync_Delete')) { 174 // We can't remove the mapping entry as we need to keep 175 // the timestamp information. 176 $guid = $state->removeUID($type, $syncItem->getLocURI()); 177 #$guid = $state->getGlobalUID($type, $syncItem->getLocURI()); 178 Horde::logMessage('SyncML: about to delete entry ' . $type .' / '. $guid . ' due to client request '.$syncItem->getLocURI(), __FILE__, __LINE__, PEAR_LOG_DEBUG); 179 180 if (!is_a($guid, 'PEAR_Error') && $guid != false) { 181 $registry->call($hordeType . '/delete', array($guid)); 182 #$ts = $history->getTSforAction($guid, 'delete'); 183 #$state->setUID($type, $syncItem->getLocURI(), $guid, $ts); 184 $state->log("Client-Delete"); 185 Horde::logMessage('SyncML: deleted entry ' . $guid . ' due to client request', __FILE__, __LINE__, PEAR_LOG_DEBUG); 186 } else { 187 $state->log("Client-DeleteFailure"); 188 Horde::logMessage('SyncML: Failure deleting client entry, maybe gone already on server. msg:'. $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR); 189 } 190 } elseif (is_a($command, 'Horde_SyncML_Command_Sync_Replace')) { 191 $guid = $state->getGlobalUID($type, $syncItem->getLocURI()); 192 $ok = false; 193 if ($guid) { 194 Horde::logMessage('SyncML: locuri'. $syncItem->getLocURI() . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_ERR); 195 // Entry exists: replace current one. 196 $ok = $registry->call($hordeType . '/replace', 197 array($guid, $state->convertClient2Server($syncItem->getContent(), $contentType), $contentType)); 198 if (!is_a($ok, 'PEAR_Error')) { 199 $ts = $history->getTSforAction($guid, 'modify'); 200 $state->setUID($type, $syncItem->getLocURI(), $guid, $ts); 201 Horde::logMessage('SyncML: replaced entry due to client request guid: ' .$guid. ' ts: ' .$ts, __FILE__, __LINE__, PEAR_LOG_DEBUG); 202 $state->log("Client-Replace"); 203 $ok = true; 204 } else { 205 // Entry may have been deleted; try adding it. 206 $ok = false; 207 } 208 } 209 210 if (!$ok) { 211 // Entry does not exist in map or database: add a new one. 212 Horde::logMessage('SyncML: try to add contentype ' . $contentType, __FILE__, __LINE__, PEAR_LOG_DEBUG); 213 $guid = $registry->call($hordeType . '/import', 214 array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType)); 215 if (!is_a($guid, 'PEAR_Error')) { 216 $ts = $history->getTSforAction($guid, 'add'); 217 $state->setUID($type, $syncItem->getLocURI(), $guid, $ts); 218 $state->log("Client-AddReplace"); 219 Horde::logMessage('SyncML: r/ added client entry as ' . $guid, __FILE__, __LINE__, PEAR_LOG_DEBUG); 220 } else { 221 Horde::logMessage('SyncML: Error in replacing/add client entry:' . $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR); 222 $state->log("Client-AddFailure"); 223 } 224 } 225 } 226 } 227 228 return $guid; 229 } 230 }
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 |