[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/horde/Horde/SyncML/Sync/ -> SlowSync.php (source)

   1  <?php
   2  
   3  include_once 'Horde/SyncML/Sync/TwoWaySync.php';
   4  
   5  /**
   6   * Slow sync may just work; I think most of the work is going to be
   7   * done by the API.
   8   *
   9   * $Horde: framework/SyncML/SyncML/Sync/SlowSync.php,v 1.7 2004/05/26 17:32:50 chuck Exp $
  10   *
  11   * Copyright 2003-2004 Anthony Mills <amills@pyramid6.com>
  12   *
  13   * See the enclosed file COPYING for license information (LGPL). If you
  14   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  15   *
  16   * @author  Anthony Mills <amills@pyramid6.com>
  17   * @version $Revision: 21683 $
  18   * @since   Horde 3.0
  19   * @package Horde_SyncML
  20   */
  21  class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
  22  
  23      function handleSync($currentCmdID, $hordeType, $syncType,&$output, $refts)
  24      {
  25          global $registry;
  26          
  27          $history = $GLOBALS['phpgw']->contenthistory;
  28          $state = &$_SESSION['SyncML.state'];
  29          
  30          $adds = &$state->getAddedItems($hordeType);
  31          
  32      #if($adds === FALSE)
  33      #{
  34      #    Horde::logMessage("SyncML: reading added items from database", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  35      #    $state->setAddedItems($hordeType, $registry->call($hordeType. '/list', array()));
  36      #    $adds = &$state->getAddedItems($hordeType);
  37          #}
  38  
  39      Horde::logMessage("SyncML: ".count($adds).   ' added items found for '.$hordeType  , __FILE__, __LINE__, PEAR_LOG_DEBUG);
  40          $serverAnchorNext = $state->getServerAnchorNext($syncType);
  41      $counter = 0;    
  42  
  43      while($guid = array_shift($adds))
  44      {
  45          #$guid_ts = max($history->getTSforAction($guid, 'add'),$history->getTSforAction($guid, 'modify'));
  46          $sync_ts = $state->getChangeTS($syncType, $guid);
  47          #Horde::logMessage("SyncML: slowsync timestamp add: $guid sync_ts: $sync_ts anchorNext: ". $serverAnchorNext.' / '.time(), __FILE__, __LINE__, PEAR_LOG_DEBUG);
  48          // $sync_ts                       it got synced from client to server someone
  49          // $sync_ts >= $serverAnchorNext  it got synced from client to server in this sync package already
  50          if ($sync_ts && $sync_ts >= $serverAnchorNext) {
  51              // Change was done by us upon request of client.
  52              // Don't mirror that back to the client.
  53              //Horde::logMessage("SyncML: slowsync add: $guid ignored, came from client", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  54              continue;
  55          }
  56  
  57          #$locid = $state->getLocID($syncType, $guid);
  58  
  59          // Create an Add request for client.
  60  # LK            $contentType = $state->getPreferedContentTypeClient($syncType);
  61  
  62          $contentType = $state->getPreferedContentTypeClient($this->_sourceLocURI);
  63          if(is_a($contentType, 'PEAR_Error')) {
  64              // Client did not sent devinfo
  65              $contentType = array('ContentType' => $state->getPreferedContentType($this->_targetLocURI));
  66          }
  67  
  68          $cmd = &new Horde_SyncML_Command_Sync_ContentSyncElement();
  69          $c = $registry->call($hordeType . '/export', array('guid' => $guid, 'contentType' => $contentType));
  70          #Horde::logMessage("SyncML: slowsync add to server $c", __FILE__, __LINE__, PEAR_LOG_DEBUG);
  71          if (!is_a($c, 'PEAR_Error')) {
  72              // Item in history but not in database. Strange, but
  73              // can happen.
  74              #LK        $cmd->setContent($state->convertServer2Client($c, $contentType));
  75              $cmd->setContent($c);
  76              if($hordeType == 'sifcalendar' || $hordeType == 'sifcontacts' || $hordeType == 'siftasks') {
  77                  $cmd->setContentFormat('b64');
  78              }
  79              $cmd->setContentType($contentType['ContentType']);
  80              $cmd->setSourceURI($guid);
  81              $currentCmdID = $cmd->outputCommand($currentCmdID, $output, 'Add');
  82              $state->log('Server-Add');
  83              
  84              // return if we have to much data
  85              #Horde::logMessage("SyncML: ".' checking hordetype '.$hordeType  , __FILE__, __LINE__, PEAR_LOG_DEBUG);
  86              if(++$counter >= MAX_ENTRIES && $hordeType != 'sifcalendar' && $hordeType != 'sifcontacts' && $hordeType != 'siftasks') {
  87                  $state->setSyncStatus(SERVER_SYNC_DATA_PENDING);
  88                  return $currentCmdID;
  89              }
  90          }
  91      }
  92      #Horde::logMessage("SyncML: handling sync ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG);
  93      
  94             $state->clearSync($syncType);
  95  
  96          return $currentCmdID;
  97      }
  98      
  99      /**
 100      * Here's where the actual processing of a client-sent Sync
 101      * Command takes place. Entries are added or replaced
 102      * from the server database by using Horde API (Registry) calls.
 103      */
 104  	function runSyncCommand(&$command) {
 105          #Horde::logMessage('SyncML: content type is ' . $command->getContentType() .' moreData '. $command->_moreData, __FILE__, __LINE__, PEAR_LOG_DEBUG);
 106          global $registry;
 107          
 108          $history = $GLOBALS['egw']->contenthistory;
 109          
 110          $state = &$_SESSION['SyncML.state'];
 111          
 112          if(isset($state->_moreData['luid'])) {
 113              if(($command->_luid == $state->_moreData['luid'])) {
 114                                  Horde::logMessage('SyncML: got next moreData chunk '.$command->getContent(), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 115                  $lastChunks = implode('',$state->_moreData['chunks']);
 116                  $command->_content = $lastChunks.$command->_content;
 117                  $stringlen1 =  strlen($lastChunks);
 118                  $stringlen2 =  strlen($command->_content);
 119                  
 120                  if(!$command->_moreData && strlen($command->_content) != $state->_moreData['contentSize']) {
 121                      $command->_status = RESPONSE_SIZE_MISMATCH;
 122                      $state->_moreData = array();
 123                      
 124                      return;
 125                  } elseif(!$command->_moreData && strlen($command->_content) == $state->_moreData['contentSize']) {
 126                      $state->_moreData = array();
 127                      Horde::logMessage('SyncML: chunk ended successful type is ' . $command->getContentType() .' content is '. $command->getContent(), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 128                  }
 129              } else {
 130                  // alert 223 needed too
 131                  #$command->_status = ALERT_NO_END_OF_DATA;
 132                  
 133                  $state->_moreData = array();
 134                  
 135                  return;
 136              }
 137          }
 138          
 139          // don't add/replace the data currently, they are not yet complete
 140          if($command->_moreData == TRUE) {
 141              $state->_moreData['chunks'][]    = $command->_content;
 142              $state->_moreData['luid']    = $command->_luid;
 143              
 144              // gets only set with the first chunk of data
 145              if(isset($command->_contentSize))
 146                  $state->_moreData['contentSize'] = $command->_contentSize;
 147                  
 148              $command->_status = RESPONSE_CHUNKED_ITEM_ACCEPTED_AND_BUFFERED;
 149                          Horde::logMessage('SyncML: added moreData chunk '.$command->getContent(), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 150              
 151              return;
 152          }
 153          
 154          $hordeType = $type = $this->_targetLocURI;
 155          // remove the './' from the beginning
 156          $hordeType = str_replace('./','',$hordeType);
 157          
 158          $syncElementItems = $command->getSyncElementItems();
 159          
 160          foreach($syncElementItems as $syncItem) {
 161              if(!$contentType = $syncItem->getContentType()) {
 162                  $contentType = $state->getPreferedContentType($type);
 163              }
 164              
 165              if ($this->_targetLocURI == 'calendar' && strpos($syncItem->getContent(), 'BEGIN:VTODO') !== false) {
 166                  $hordeType = 'tasks';
 167              }
 168          
 169              $guid = false;
 170          #    if (is_a($command, 'Horde_SyncML_Command_Sync_Add')) {
 171          #        $guid = $registry->call($hordeType . '/import',
 172          #            array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType));
 173          #        if (!is_a($guid, 'PEAR_Error')) {
 174          #            $ts = $history->getTSforAction($guid, 'add');
 175          #            $state->setUID($type, $syncItem->getLocURI(), $guid, $ts);
 176          #            $state->log("Client-Add");
 177          #            #Horde::logMessage('SyncML: added client entry as ' . $guid, __FILE__, __LINE__, PEAR_LOG_DEBUG);
 178          #        } else {
 179          #            $state->log("Client-AddFailure");
 180          #            Horde::logMessage('SyncML: Error in adding client entry:' . $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR);
 181          #        }
 182          #    } elseif (is_a($command, 'Horde_SyncML_Command_Sync_Replace')) {
 183                  #$guid = $state->getGlobalUID($type, $syncItem->getLocURI());
 184                  $guid = $registry->call($hordeType . '/search',
 185                      array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType));
 186                  Horde::logMessage('SyncML: found guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_DEBUG);
 187                  $ok = false;
 188                  if ($guid) {
 189                      #Horde::logMessage('SyncML: locuri'. $syncItem->getLocURI() . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_ERR);
 190                      // Entry exists: replace current one.
 191                      $ok = $registry->call($hordeType . '/replace',
 192                          array($guid, $state->convertClient2Server($syncItem->getContent(), $contentType), $contentType));
 193                      if (!is_a($ok, 'PEAR_Error')) {
 194                          $ts = $history->getTSforAction($guid, 'modify');
 195                          $state->setUID($type, $syncItem->getLocURI(), $guid, $ts);
 196                          #Horde::logMessage('SyncML: replaced entry due to client request guid: '. $guid  .' LocURI: '. $syncItem->getLocURI() .' ts: '. $ts, __FILE__, __LINE__, PEAR_LOG_DEBUG);
 197                          $state->log("Client-Replace");
 198                          $ok = true;
 199                      } else {
 200                          // Entry may have been deleted; try adding it.
 201                          $ok = false;
 202                      }
 203                  }
 204              
 205                  if (!$ok) {
 206                      // Entry does not exist in map or database: add a new
 207                      // one.
 208                      Horde::logMessage('SyncML: try to add contentype ' . $contentType .' to '. $hordeType, __FILE__, __LINE__, PEAR_LOG_DEBUG);
 209                      $guid = $registry->call($hordeType . '/import',
 210                          array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType));
 211                      if (!is_a($guid, 'PEAR_Error')) {
 212                          $ts = $history->getTSforAction($guid, 'add');
 213                          $state->setUID($type, $syncItem->getLocURI(), $guid, $ts);
 214                          $state->log("Client-AddReplace");
 215                          Horde::logMessage('SyncML: r/ added client entry as ' . $guid, __FILE__, __LINE__, PEAR_LOG_DEBUG);
 216                      } else {
 217                          Horde::logMessage('SyncML: Error in replacing/add client entry:' . $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR);
 218                          $state->log("Client-AddFailure");
 219                      }
 220                  }
 221          #    }
 222          }
 223  
 224          return true;
 225      }
 226      
 227  
 228      function loadData()
 229      {
 230          global $registry;
 231  
 232      $state = &$_SESSION['SyncML.state'];
 233          $syncType = $this->_targetLocURI;
 234          $hordeType = str_replace('./','',$syncType);
 235  
 236      Horde::logMessage("SyncML: reading added items from database for $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG);
 237      $state->setAddedItems($hordeType, $registry->call($hordeType. '/list', array()));
 238      $adds = &$state->getAddedItems($hordeType);
 239      $this->_syncDataLoaded = TRUE;
 240  
 241      return count($state->getAddedItems($hordeType));
 242      }
 243  
 244  }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7