phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] sync/inc/class.bo_sync.inc.php, 1.59


From: nomail
Subject: [Phpgroupware-cvs] sync/inc/class.bo_sync.inc.php, 1.59
Date: Fri, 26 Nov 2004 13:34:57 +0100

Update of /sync/inc
Modified Files:
        Branch: 
          class.bo_sync.inc.php

date: 2004/11/26 12:34:57;  author: fipsfuchs;  state: Exp;  lines: +82 -31

Log Message:
new version from internal CVS moved to original project
=====================================================================
Index: sync/inc/class.bo_sync.inc.php
diff -u sync/inc/class.bo_sync.inc.php:1.58 sync/inc/class.bo_sync.inc.php:1.59
--- sync/inc/class.bo_sync.inc.php:1.58 Tue Sep  7 09:45:30 2004
+++ sync/inc/class.bo_sync.inc.php      Fri Nov 26 12:34:57 2004
@@ -112,6 +112,7 @@
           $ret = $this->so->AddDevice($phpgw_accountid, $URI, $username, 
$password);
                } else {
           // no user, no device -> return error
+          if ($this->debug) error_log('AuthenticateSyncDevice: authentication 
fails.');
           $ret = -1;
         }
       }
@@ -129,8 +130,7 @@
        // restore session data again
        $GLOBALS['phpgw']->session->appsession('session_data','sync', 
$session_data);
   
-       if ($this->debug)
-         error_log("AuthenticateSyncDevice: got new session: " . $sess);     
+       if ($this->debug) error_log("AuthenticateSyncDevice: got new session: " 
. $sess);     
       }
       
       return array(
@@ -184,7 +184,8 @@
       */
 
       $result = $this->so->GetDeviceInfo($deviceid);
-      if (! is_array($result)) return array();
+      // cawgod:
+      if (! is_array($result)) $result = array();
       $result["id"] = $deviceid;
       return $result;
     }
@@ -238,6 +239,8 @@
                return array(-1, $LUID, null);
              }
                 
+                               // cawgod:
+                               $this->callSetCurrentDeviceID($this->ipc, 
$deviceid);
        $data = $this->ipc->getData($GUID, $mimetype, $mimeversion);
 
        if ($data == false) 
@@ -250,8 +253,7 @@
         }
       }
       
-      if ($this->debug)
-        error_log("Data dump: $data");
+      $this->debugLog("Data dump: $data", 1);
         
       $result = array(1, $LUID, base64_encode($data));
       return $result;      
@@ -274,10 +276,8 @@
     */
   
     function setSyncItem($deviceid, $source, $LUID, $mimetype, $Itemdata) {
-      // set the responsible IPC class of the responsible module
       
-      $this->GetIpcforSource($source);
-      if (!isset($this->ipc) or ($this->ipc == false)) 
+      if(!$this->setIpcforSource($source))      // set the responsible IPC 
class of the responsible module
       {
         error_log("Sync Module: Error: There is no source called '$source'. 
Can not synchronize");
         return false;
@@ -294,21 +294,30 @@
         error_log("error getting mimetype and version while setting data to 
source $source, using $mimetype");
       }
       
+      $this->callSetCurrentDeviceID($this->ipc, $deviceid);
       // get the mapped GUID
       $GUID = $this->so->getGUIDExt($deviceid, $source, $LUID);
-      if ($GUID == -1)
+      if ($GUID == -1) // what is -1
       {
         // no GUID found -> then we have to replace not add
         $result = $this->ipc->addData($Itemdata, $mimetype, $mimeversion, 
$session_data['syncstart_timestamp']);
-
         if ($this->debug)
           error_log("setSyncItem: new item with result: $result and timestamp: 
".$session_data['syncstart_timestamp']);
         
-        if (! is_bool($result))
+        if (!is_bool($result))
         {
           // set new GUID
           $result = $this->so->addMappingExt($deviceid, $source, $LUID, 
$result);
           $result == -1 ? $result = false : $result = true;
+          // cawgod:
+          if ($result)
+          {
+               $res = $this->so->getResolveEntry($deviceid, $source, $LUID);
+               if ($res)
+               {
+                       $this->callResolveMapping($res, $GUID);
+               }
+          }
           return $result; 
         }
       }
@@ -320,6 +329,7 @@
         if ($this->debug)
           error_log("setSyncItem: replacing item $GUID, timestamp: 
".$session_data['syncstart_timestamp']);;
       }
+      
       if (is_bool($result))
       {
         // db returns false if couldn't set 
@@ -388,17 +398,34 @@
     *         returns boolean false if $source has no mapping or no IPC class
     */
   
-    function GetIpcforSource($source)
-    {
-      $sourcemodule = $this->so->GetSourceModule($source);
-      if ($sourcemodule != -1)
+               function GetIpcforSource($source)
+               {
+                       $sourcemodule = $this->so->GetSourceModule($source);
+                       if ($sourcemodule != -1)
+                       {
+                               $this->ipc =& 
$this->ipcManager->getIPC($sourcemodule);
+                       }
+      
+      if($this->ipc)
       {
-        $this->ipc =& $this->ipcManager->getIPC($sourcemodule);
-        return $sourcemodule;
+       return $sourcemodule;
       } else
         return false;
     }
     
+               function setIpcforSource($source)
+               {
+                       $sourcemodule = $this->so->GetSourceModule($source);
+                       if ($sourcemodule != -1)
+                       {
+                               if($this->ipc =& 
$this->ipcManager->getIPC($sourcemodule))
+                               {
+                                       return true;
+                               }
+                       }
+                       return false;
+               }
+               
    /**
     * get an array of LUIDs 
     *
@@ -416,9 +443,7 @@
       // cache channelid for our $deviceid and $source
       $channelid = $this->so->GetChannelIDfromSourceAndDeviceID($deviceid, 
$source);
       
-      $this->GetIpcforSource($source);
-      
-      if (!isset($this->ipc) or ($this->ipc == false)) 
+      if (!$this->setIpcforSource($source)) 
       {
         error_log("Sync Module: Error: There is no source called '$source'. 
Can not synchronize");
         return -1;
@@ -426,10 +451,10 @@
 
       $session_data = 
$GLOBALS['phpgw']->session->appsession('session_data','sync');
       $idlistname = "idlistcache_" . $deviceid . "_" . $source;
-        
+
       if ((is_array($session_data[$idlistname])) and ($type == 1))
       {
-        error_log("GetIDList: use cached IdList: 
".serialize($session_data[$idlistname]));
+        $this->debugLog("GetIDList: use cached IdList: 
".serialize($session_data[$idlistname]), 1);
         return $session_data[$idlistname];         
       }
            
@@ -448,24 +473,20 @@
             $LUID = $this->so->generateandsettempLUID($channelid, $id);
           }
         }
-        
+
         // if $type is 2 than add only items without LUID
         // and if $type is 3 add only items with LUID
         if (($type == 1) or (($LUID[0] == '_') xor ($type != 2))) 
           $retList[$id] = $LUID;
       }
-      
+
       if ($type == 1) 
       {
         $session_data = 
$GLOBALS['phpgw']->session->appsession('session_data','sync');
         $session_data[$idlistname] = $retList;
-        error_log("GetIdList: set cache to session");
+        $this->debugLog("GetIdList: set cache to session", 1);
         $GLOBALS['phpgw']->session->appsession('session_data','sync', 
$session_data);
       }
-         
-      if ($this->debug)
-        error_log("getIDList return value: ".serialize($retList));
-
       return $retList;
     }
     
@@ -770,5 +791,35 @@
    }
      
  
-  }
+       function callSetCurrentDeviceID($ipc, $deviceid) {
+               if ($ipc->isRefSyncable) {
+                       $ipc->setCurrentDeviceID($deviceid);
+               }
+       }
+
+       function callResolveMapping($res, $guid) {
+               $ipc = $this->GetIpcForSource($res["reqsourceuri"]);
+               if ($ipc) {
+                       if ($ipc->isRefSyncable) {
+                               $success = $ipc->resolveMapping(
+                                       $res["deviceid"], $res["reqsourceuri"], 
$res["id"],
+                                       $res["fkluid"], $guid, 
$res["fksourceuri"], $res["tag"]
+                               );
+                               if ($success) {
+                                       
$this->so->deleteResolveEntry($res["resolveid"]);
+                               }
+                       }
+               }
+       }
+       
+       function debugLog($string, $level = 0)
+               {
+                       if($level <= $this->debugLevel)
+                       {
+                               error_log($string);
+                       }       
+               }
+       
+
+}
 ?> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]