* InfoLog: fix not working overwrite check (optimistic locking) plus incrementing etag

This commit is contained in:
Ralf Becker 2021-11-22 17:53:37 +01:00
parent 57eb310364
commit 2056400695
2 changed files with 20 additions and 3 deletions

View File

@ -961,6 +961,10 @@ class infolog_bo
$check_modified = $values['info_datemodified'] && !$xmlrpc ? $to_write['info_datemodified'] : false; $check_modified = $values['info_datemodified'] && !$xmlrpc ? $to_write['info_datemodified'] : false;
$values['info_datemodified'] = $this->user_time_now; $values['info_datemodified'] = $this->user_time_now;
$to_write['info_datemodified'] = $this->now; $to_write['info_datemodified'] = $this->now;
if ($check_modified && isset($values['info_etag']))
{
++$values['info_etag'];
}
} }
if ($touch_modified || !$values['info_modifier']) if ($touch_modified || !$values['info_modifier'])
{ {
@ -979,7 +983,7 @@ class infolog_bo
if (($info_id = $this->so->write($to_write, $check_modified, $purge_cfs, !isset($old)))) if (($info_id = $this->so->write($to_write, $check_modified, $purge_cfs, !isset($old))))
{ {
if(!isset($values['info_type']) || $status_only || empty($values['caldav_url'])) if(!isset($values['info_type']) || $status_only || empty($values['caldav_name']))
{ {
$values = $this->read($info_id, true, 'server', $ignore_acl); $values = $this->read($info_id, true, 'server', $ignore_acl);
} }
@ -1006,12 +1010,13 @@ class infolog_bo
$values['link_to']['to_id'] = $info_id; $values['link_to']['to_id'] = $info_id;
} }
} }
if($values['info_id'] && $info_id) if ($values['info_id'] && $info_id)
{ {
$this->write_check_links($to_write); $this->write_check_links($to_write);
if(!$values['info_link_id'] || $values['info_link_id'] != $to_write['info_link_id']) if(!$values['info_link_id'] || $values['info_link_id'] != $to_write['info_link_id'])
{ {
// Just got a link ID, need to save it // Just got a link ID, need to save it
unset($to_write['info_etag']); // we must not increment it again
$this->so->write($to_write); $this->so->write($to_write);
$values['info_link_id'] = $to_write['info_link_id']; $values['info_link_id'] = $to_write['info_link_id'];
$values['info_contact'] = $to_write['info_contact']; $values['info_contact'] = $to_write['info_contact'];

View File

@ -584,7 +584,19 @@ class infolog_so
if (($this->data['info_id'] = $info_id) && !$force_insert) if (($this->data['info_id'] = $info_id) && !$force_insert)
{ {
$where = array('info_id' => $info_id); $where = array('info_id' => $info_id);
if ($check_modified) $where['info_datemodified'] = $check_modified; if ($check_modified)
{
$where['info_datemodified'] = $check_modified;
// also check etag, if we got it
if (isset($values['info_etag']))
{
$where['info_etag'] = $values['info_etag'];
}
unset($to_write['info_etag']);
// and increment it
$to_write[] = 'info_etag=info_etag+1';
}
if (!$this->db->update($this->info_table,$to_write,$where,__LINE__,__FILE__)) if (!$this->db->update($this->info_table,$to_write,$where,__LINE__,__FILE__))
{ {
//error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning false"); //error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning false");