[sync] SyncML working, part 4/3

Karsten Fourmont fourmont at gmx.de
Fri Jul 2 14:54:02 PDT 2004


Hi,

 > I'm in the process of getting this into CVS now
Thanks.
 > For the future,
 > *please* take a read through horde/docs/CODING_STANDARDS.

Sorry for causing unnecessary work.
I did read CODING_STANDARDS by now and configured my editor accordingly.
Whether my mind is configured accordingly too has to be seen. But I do 
try :-)

Here's the first patch. Partly due to Ian's feedback.

Description:
-updated package.xml
-DataTree object is no longer stored in session
-removed outdated uncommented code

Hope I got the CODING_STANDARDS right :-)
I must admit I'm notoriously bad at these things...

With these patches applied, any default CVS head installation should to 
be able to sync at least with a P800/900.

Bye
  Karsten
-------------- next part --------------
Index: package.xml
===================================================================
RCS file: /repository/framework/SyncML/package.xml,v
retrieving revision 1.5
diff -u -r1.5 package.xml
--- package.xml	26 May 2004 17:32:49 -0000	1.5
+++ package.xml	2 Jul 2004 21:40:44 -0000
@@ -38,6 +38,7 @@
           <file name="Alert.php"/>
           <file name="Final.php"/>
           <file name="Get.php"/>
+          <file name="Map.php"/>
           <file name="Put.php"/>
           <file name="Replace.php"/>
           <file name="Results.php"/>
@@ -66,6 +67,9 @@
 
       <dir role="doc" name="docs">
         <file name="TODO"/>
+        <file name="README.syncml_primer.txt"/>
+        <file name="README.program_flow.txt"/>
+        <file name="INSTALL.p900.txt"/>
       </dir>
     </filelist>
 
Index: SyncML/State.php
===================================================================
RCS file: /repository/framework/SyncML/SyncML/State.php,v
retrieving revision 1.10
diff -u -r1.10 State.php
--- SyncML/State.php	2 Jul 2004 19:24:44 -0000	1.10
+++ SyncML/State.php	2 Jul 2004 21:40:45 -0000
@@ -165,8 +165,6 @@
 
     var $_syncs = array();
 
-    var $_datatree;
-
     var $_clientAnchorNext = array(); // written to db after successful sync
 
     var $_serverAnchorLast = array();
@@ -188,12 +186,29 @@
         }
 
         $this->isAuthorized = false;
+    }
 
-        $driver = $GLOBALS['conf']['datatree']['driver'];
-        $params = Horde::getDriverConfig('datatree', $driver);
-        $params = array_merge($params, array( 'group' => 'syncml' ));
+    /**
+     * Returns the DataTree used as persistence layer for SyncML.
+     * The datatree var should not be a class member of State as State
+     * is stored as a session var. Resource handles (=db connections)
+     * cannot be stored in sessions.
+     *
+     * @return object DataTree  The concrete DataTree reference
+     */
+    function getDataTree() 
+    {
+        static $syncml_datatree=false;
+
+        if (!$syncml_datatree) {
+            $driver = $GLOBALS['conf']['datatree']['driver'];
+            $params = Horde::getDriverConfig('datatree', $driver);
+            $params = array_merge($params, array( 'group' => 'syncml' ));
 
-        $this->_datatree = &DataTree::singleton($driver, $params);
+            $syncml_datatree = &DataTree::singleton($driver, $params);
+        }
+        
+        return $syncml_datatree;
     }
 
     function getLocName()
@@ -323,12 +338,13 @@
      */
     function getLocID($type, $guid)
     {
-        $id = $this->_datatree->getId($this->_locName . $this->_sourceURI . $type . $guid);
+        $dt = $this->getDataTree();
+        $id = $dt->getId($this->_locName . $this->_sourceURI . $type . $guid);
         if (is_a($id, 'PEAR_Error')) {
             return false;
         }
 
-        $gid = $this->_datatree->getObjectById($id);
+        $gid = $dt->getObjectById($id);
         if (is_a($gid, 'PEAR_Error')) {
             return false;
         }
@@ -347,26 +363,28 @@
      */
     function setUID($type, $locid, $guid, $ts=0)
     {
+        $dt = $this->getDataTree();
+
         // Set $locid.
         $gid = &new DataTreeObject($this->_locName . $this->_sourceURI . $type . $guid);
         $gid->set('type', $type);
         $gid->set('locid', $locid);
         $gid->set('ts', $ts);
 
-        $r = $this->_datatree->add($gid);
+        $r = $dt->add($gid);
         if (is_a($r, 'PEAR_Error')) {
             // Object already exists: update instead.
-            $r = $this->_datatree->updateData($gid);
+            $r = $dt->updateData($gid);
         }
         $this->dieOnError($r, __FILE__, __LINE__);
 
         // Set $globaluid
         $lid = &new DataTreeObject($this->_locName . $this->_sourceURI . $type . $locid);
         $lid->set('globaluid', $guid);
-        $r = $this->_datatree->add($lid);
+        $r = $dt->add($lid);
         if (is_a($r, 'PEAR_Error')) {
             // object already exists: update instead.
-            $r = $this->_datatree->updateData($lid);
+            $r = $dt->updateData($lid);
         }
         $this->dieOnError($r, __FILE__, __LINE__);
     }
@@ -386,11 +404,13 @@
         $this->dieOnError($this->_locName, __FILE__, __LINE__);
         $this->dieOnError($this->_sourceURI, __FILE__, __LINE__);
 
-        $id = $this->_datatree->getId($this->_locName . $this->_sourceURI . $type . $locid);
+        $dt = $this->getDataTree();
+
+        $id = $dt->getId($this->_locName . $this->_sourceURI . $type . $locid);
         if (is_a($id, 'PEAR_Error')) {
             return false;
         }
-        $lid = $this->_datatree->getObjectById($id);
+        $lid = $dt->getObjectById($id);
         if (is_a($lid, 'PEAR_Error')) {
             return false;
         }
@@ -405,12 +425,14 @@
      */
     function getChangeTS($type, $guid)
     {
-        $id = $this->_datatree->getId($this->_locName . $this->_sourceURI . $type . $guid);
+        $dt = $this->getDataTree();
+
+        $id = $dt->getId($this->_locName . $this->_sourceURI . $type . $guid);
         if (is_a($id, 'PEAR_Error')) {
             return false;
         }
 
-        $gid = $this->_datatree->getObjectById($id);
+        $gid = $dt->getObjectById($id);
         if (is_a($gid, 'PEAR_Error')) {
             return false;
         }
@@ -425,16 +447,18 @@
      */
     function removeUID($type, $locid)
     {
-        $id = $this->_datatree->getId($this->_locName . $this->_sourceURI . $type . $locid);
+        $dt = $this->getDataTree();
+
+        $id = $dt->getId($this->_locName . $this->_sourceURI . $type . $locid);
         if (is_a($id, 'PEAR_Error')) {
             Horde::logMessage("SyncML: state->removeUID(type=$type,locid=$locid) : nothing to remove", __FILE__, __LINE__,  PEAR_LOG_DEBUG);
             return false;
         }
-        $lid = $this->_datatree->getObjectById($id);
+        $lid = $dt->getObjectById($id);
         $guid = $lid->get('globaluid');
         Horde::logMessage("SyncML:  state->removeUID(type=$type,locid=$locid) : removing guid:$guid and lid:$lid", __FILE__, __LINE__,  PEAR_LOG_DEBUG);
-        $this->_datatree->remove($guid);
-        $this->_datatree->remove($lid);
+        $dt->remove($guid);
+        $dt->remove($lid);
 
         return $guid;
     }
@@ -455,47 +479,6 @@
         }
     }
 
-    /*
-    function getLastSyncDate($type)
-    {
-        $id = $this->_datatree->getId($this->_locName . $this->_sourceURI . $type . 'lastSyncDate');
-        if (is_a($id, 'PEAR_Error')) {
-          return false;
-        }
-        $obj = $this->_datatree->getObjectById($id);
-        if (is_a($obj, 'PEAR_Error')) {
-          return false;
-        }
-        $r = $obj->get('date');
-
-        return $r;
-    }
-
-    function setLastSyncDate($type, $date)
-    {
-        $lsd = &new DataTreeObject($this->_locName . $this->_sourceURI . $type . 'lastSyncDate');
-        $lsd->set('date', $date);
-        $this->_datatree->add($lsd);
-    }
-
-    function getClientLastSyncAnchor($type)
-    {
-        $id = $this->_datatree->getId($this->_locName . $this->_sourceURI . $type . 'lastSyncAnchor');
-        if (is_a($id, 'PEAR_Error')) {
-          return false;
-        }
-        $obj = $this->_datatree->getObjectById($id);
-        return $obj->get('anchor');
-    }
-
-    function setLastSyncAnchor($type, $date)
-    {
-        $lsd = &new DataTreeObject($this->_locName . $this->_sourceURI . $type . 'lastSyncAnchor');
-        $lsd->set('anchor', $date);
-        $this->_datatree->add($lsd);
-    }
-    */
-
     function setClientAnchorNext($type, $a)
     {
         $this->_clientAnchorNext[$type] = $a;
@@ -536,12 +519,14 @@
      */
     function &getSyncSummary($type)
     {
-        $id = $this->_datatree->getId($this->_locName . $this->_sourceURI . $type . 'syncSummary');
+        $dt = $this->getDataTree();
+
+        $id = $dt->getId($this->_locName . $this->_sourceURI . $type . 'syncSummary');
         if (is_a($id, 'PEAR_Error')) {
             return false;
         }
 
-        return $this->_datatree->getObjectById($id);
+        return $dt->getObjectById($id);
     }
 
     /**
@@ -551,10 +536,13 @@
      */
     function writeSyncSummary()
     {
+
         if (!isset($this->_serverAnchorNext) || !is_array($this->_serverAnchorNext)) {
             return;
         }
 
+        $dt = $this->getDataTree();
+
         foreach (array_keys($this->_serverAnchorNext) as $type) {
             $s = $this->_locName . $this->_sourceURI . $type . 'syncSummary';
 
@@ -562,10 +550,10 @@
             $info = &new DataTreeObject($s);
             $info->set('ClientAnchor', $this->_clientAnchorNext);
             $info->set('ServerAnchor', $this->_serverAnchorNext);
-            $r = $this->_datatree->add($info);
+            $r = $dt->add($info);
             if (is_a($r, 'PEAR_Error')) {
                 // Object already exists: update instead.
-                $this->_datatree->updateData($info);
+                $dt->updateData($info);
             }
         }
     }
Index: SyncML/Command/Sync.php
===================================================================
RCS file: /repository/framework/SyncML/SyncML/Command/Sync.php,v
retrieving revision 1.15
diff -u -r1.15 Sync.php
--- SyncML/Command/Sync.php	2 Jul 2004 19:24:44 -0000	1.15
+++ SyncML/Command/Sync.php	2 Jul 2004 21:40:46 -0000
@@ -3,6 +3,8 @@
 include_once 'Horde/SyncML/State.php';
 include_once 'Horde/SyncML/Command.php';
 include_once 'Horde/SyncML/Command/Sync/SyncElement.php';
+include_once 'Horde/SyncML/Sync/TwoWaySync.php';
+include_once 'Horde/SyncML/Sync/SlowSync.php';
 
 /**
  * $Horde: framework/SyncML/SyncML/Command/Sync.php,v 1.15 2004/07/02 19:24:44 chuck Exp $


More information about the sync mailing list