コード例 #1
0
 function syncResponse($chunkInfo, $objects)
 {
     global $db;
     if ($this->get('accept_incoming') != 't') {
         debug("node {$remoteId} is not allowed for incoming sync!");
         return NULL;
     }
     $timestamp = $db->getTimestampTz();
     $remoteId = $this->get('node_id');
     // save modified objects
     $db->begin(true);
     // TODO: itt gaz van! ha nem sikerul egy objektumot elmenteni, akkor soha tobbe nem lesz neki elkuldve!!!
     $updatedObjects = sotf_NodeObject::saveModifiedObjects($objects, $remoteId);
     // if db error: don't commit!
     if (is_null($updatedObjects)) {
         return array(array('error' => "store object failed, sync aborted"));
     }
     $db->commit();
     debug("number of updated objects", $updatedObjects);
     $replyInfo = array('received' => count($objects), 'updated' => $updatedObjects);
     if ($chunkInfo['objects_remaining'] == 0) {
         // last chunk,  save node and neighbour stats
         $node = sotf_Node::getLocalNode();
         $this->set('last_sync_in', $timestamp);
         $node->set('last_sync_in', $timestamp);
         // take out from pending nodes, update neighbour list
         if ($this->get('pending_url')) {
             $this->set('pending_url', '');
             $node->set('neighbours', $this->getNeighbourString());
         }
         $this->update();
         $node->update();
         //$replyInfo['node'] = $node->getAll();
     }
     return array($replyInfo);
 }
コード例 #2
0
ファイル: admin.php プロジェクト: BackupTheBerlios/sotf-svn
    if (empty($userid) || !is_numeric($userid)) {
        raiseError("Invalid userid: {$userid}");
    }
    $username = $user->getUsername($userid);
    if (empty($username)) {
        raiseError("Invalid userid: {$userid}");
    }
    $permissions->delPermission('node', $userid);
    $msg = $page->getlocalizedWithParams("deleted_permissions_for", $username);
    $page->addStatusMsg($msg, false);
    $page->redirect("admin.php");
    $page->logRequest();
    exit;
}
// generate output
$localNode = sotf_Node::getLocalNode();
if (!$localNode) {
    // clear old entry
    $localNode = new sotf_Node();
    $localNode->set('name', $config['nodeName']);
    $localNode->find();
    if ($localNode->exists()) {
        $localNode->delete();
    }
    // create local node entry if does not exist
    $localNode = new sotf_Node();
    $localNode->set('node_id', $config['nodeId']);
    $localNode->set('name', $config['nodeName']);
    $localNode->set('url', $config['rootUrl']);
    $localNode->create();
}
コード例 #3
0
 function sync($console = false)
 {
     global $sotfVars;
     // tunable things
     $objectsPerRPCRequest = 100;
     global $page;
     if (!$console && $this->getBool('use_for_outgoing')) {
         debug("node {$this->id} is not used for outgoing sync");
         return;
     }
     debug("SYNCing with ", $this->get("node_id"));
     $rpc = new rpc_Utils();
     if ($config['debug']) {
         $rpc->debug = true;
     }
     $timestamp = $this->db->getTimestampTz();
     $remoteId = $this->get('node_id');
     $url = $this->getUrl();
     // remove trailing '/'
     while (substr($url, -1) == '/') {
         $url = substr($url, 0, -1);
     }
     // collect local data to send
     $localNode = sotf_Node::getLocalNode();
     //debug("localNode", $localNode);
     debug("neighbour", $this);
     $localNodeData = $localNode->getAll();
     // check if url is correct...
     $localNodeData['url'] = $config['rootUrl'];
     // calculate chunking
     $currentStamp = $sotfVars->get('sync_stamp', 0);
     $lastSyncStamp = $this->lastSyncStamp();
     $count = sotf_NodeObject::countModifiedObjects($remoteId, $lastSyncStamp);
     $numChunks = ceil($count / $objectsPerRPCRequest);
     if ($numChunks == 0) {
         $numChunks = 1;
     }
     $thisChunk = 1;
     $chunkInfo = array("old_stamp" => $lastSyncStamp, "current_stamp" => $currentStamp, "num_chunks" => $numChunks, 'this_chunk' => $thisChunk);
     debug("1st chunk info", $chunkInfo);
     // do XML-RPC conversation
     $objectsSent = 0;
     $objectsReceived = 0;
     while ($thisChunk <= $numChunks) {
         if ($thisChunk == $numChunks) {
             // last chunk: no limits
             $objectsPerRPCRequest = 100 * $objectsPerRPCRequest;
         }
         $modifiedObjects = sotf_NodeObject::getModifiedObjects($remoteId, $lastSyncStamp, $objectsSent + 1, $objectsPerRPCRequest);
         $chunkInfo['this_chunk'] = $thisChunk;
         debug("chunk info", $chunkInfo);
         //debug("number of sent objects", count($modifiedObjects));
         $objectsSent = $objectsSent + count($modifiedObjects);
         $objs = array($chunkInfo, $localNodeData, $modifiedObjects);
         $response = $rpc->call($url . '/xmlrpcServer.php', 'sotf.sync', $objs);
         // error handling
         if (is_null($response)) {
             $this->set('errors', $this->get('errors') + 1);
             $this->update();
             return;
         }
         // save received data
         $chunkInfo = $response[0];
         $newObjects = $response[1];
         $objectsReceived = $objectsReceived + count($newObjects);
         debug("number of received objects", count($newObjects));
         if (count($newObjects) > 0) {
             $updatedObjects = sotf_NodeObject::saveModifiedObjects($newObjects);
         }
         $thisChunk++;
     }
     debug("total number of objects sent", $objectsSent);
     debug("total number of objects received", $objectsReceived);
     //$this->log($console, "number of updated objects: " .count($updatedObjects));
     // save last_sync
     $this->set('success', $this->get('success') + 1);
     $this->set('last_sync_out', $timestamp);
     $this->saveSyncStatus($timestamp, $currentStamp);
     // send receipt of successful sync??
 }