/** Private! Compares a replicated object to the local one and saves it if it's newer than the local. */
 function saveReplica($fromNode)
 {
     global $db, $repository;
     $oldData = $db->getRow("SELECT * FROM sotf_node_objects WHERE id='{$this->id}' ");
     //debug("changed", $changed);
     //debug("lch", $this->lastChange);
     if (count($oldData) > 0) {
         $oldObj = $repository->getObjectNoCache($this->id);
         if (!$oldObj or $this->internalData['change_stamp'] && $this->internalData['change_stamp'] > $oldData['change_stamp']) {
             // this is newer, save it
             debug("arrived newer version of", $this->id);
             if (!$oldObj) {
                 debug("creating, because object did not exist...");
                 $changed = sotf_Object::create();
             } else {
                 $changed = sotf_Object::update();
             }
             if (!$changed) {
                 logger("WARNING: Object creation failed ({$this->id})!!!", $change);
             }
             // save internal data
             $this->internalData['arrived'] = $db->getTimestampTz();
             $internalObj = new sotf_Object('sotf_node_objects', $this->internalData['id'], $this->internalData);
             $internalObj->update();
             // save binary fields
             /*
             		  reset($this->binaryFields);
             		  while(list(,$field)=each($this->binaryFields)) {
              sotf_Object::setBlob($field, $db->unescape_bytea($this->data[$field]));
             		  }
             */
             debug("updated ", $this->id);
             $this->addToRefreshTable($this->id, $fromNode);
             $this->removeFromRefreshTable($this->id, $fromNode);
         } elseif ($this->internalData['change_stamp'] == $oldData['change_stamp']) {
             debug("arrived same version of", $this->id);
             $this->removeFromRefreshTable($this->id, $fromNode);
             $changed = false;
         } else {
             debug("arrived older version of", $this->id);
             $changed = false;
         }
     } else {
         debug("arrived new object", $this->id);
         $db->begin();
         $this->internalData['arrived'] = $db->getTimestampTz();
         $internalObj = new sotf_Object('sotf_node_objects', $this->id, $this->internalData);
         $internalObj->create();
         //$db->silent = true;
         $changed = sotf_Object::create();
         //$db->silent = false;
         if (!$changed) {
             // $internalObj->delete(); //not needed because of transaction
             if (preg_match('/referential integrity violation/', $this->error)) {
                 debug("normal problem", $this->error);
             } else {
                 logError("Could not create object: " . $this->id . " because of " . $this->error);
             }
             $db->rollback();
         } else {
             debug("created ", $this->id);
             $this->addToRefreshTable($this->id, $fromNode);
             $this->removeFromRefreshTable($this->id, $fromNode);
             $db->commit();
         }
     }
     // handle deletions
     if ($changed && $this->tablename == 'sotf_deletions') {
         $delId = $this->get('del_id');
         debug("deleting object", $delId);
         $obj = $repository->getObjectNoCache($delId);
         if ($obj) {
             $obj->delete();
         }
     }
     return $changed;
 }
 /** Private! Compares a replicated object to the local one and saves it if it's newer than the local. */
 function saveReplica()
 {
     global $sotfVars;
     $oldData = $this->db->getRow("SELECT * FROM sotf_node_objects WHERE id='{$this->id}' ");
     //debug("changed", $changed);
     //debug("lch", $this->lastChange);
     if (count($oldData) > 0) {
         if ($this->internalData['change_stamp'] && $this->internalData['change_stamp'] > $oldData['change_stamp']) {
             // this is newer, save it
             sotf_Object::update();
             // save internal data
             $this->internalData['arrived_stamp'] = $sotfVars->get('sync_stamp', 0);
             $this->internalData['arrived'] = $this->db->getTimestampTz();
             $internalObj = new sotf_Object('sotf_node_objects', $this->internalData['id'], $this->internalData);
             $internalObj->update();
             // save binary fields
             /*
             reset($this->binaryFields);
             while(list(,$field)=each($this->binaryFields)) {
             			 sotf_Object::setBlob($field, $this->db->unescape_bytea($this->data[$field]));
             }
             */
             debug("updated ", $this->id);
             return true;
         } elseif ($this->internalData['change_stamp'] && $this->internalData['change_stamp'] == $oldData['change_stamp']) {
             debug("arrived same version of", $this->id);
             return true;
         } else {
             debug("arrived older version of", $this->id);
             return false;
         }
     } else {
         $this->internalData['arrived_stamp'] = $sotfVars->get('sync_stamp', 0);
         $this->internalData['arrived'] = $this->db->getTimestampTz();
         $internalObj = new sotf_Object('sotf_node_objects', $this->id, $this->internalData);
         $internalObj->create();
         $success = sotf_Object::create();
         if (!$success) {
             $internalObj->delete();
         }
         debug("created ", $this->id);
         return $success;
     }
 }
Esempio n. 3
0
        $x->withdraw();
    } else {
        print "<script type=\"text/javascript\" language=\"javascript1.1\">error();</script>";
    }
    print "success";
} elseif ($name == "editorflag") {
    $x = new sotf_Object("sotf_user_progs");
    $x->set('user_id', $user->id);
    $x->set('prog_id', $id);
    $x->find();
    $x->set('flags', $value);
    if ($x->id) {
        if ($value == "none") {
            $x->delete();
        } else {
            $x->update();
        }
    } else {
        $x->create();
    }
    //	else print("<script type=\"text/javascript\" language=\"javascript1.1\">error();</script>");
    print "success";
} elseif ($name == "addplaylist") {
    $playlist = new sotf_UserPlaylist();
    $playlist->add($id);
    print "success";
} else {
    print "<script type=\"text/javascript\" language=\"javascript1.1\">error();</script>";
}
$page->alertWithErrors();
?>
 function update()
 {
     parent::update();
     $this->updateInternalData();
 }