From cb65460b5ffc59e63f37e6cc669ca3f42a2ebb04 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 22 Nov 2021 17:53:37 +0100 Subject: [PATCH] * InfoLog: fix not working overwrite check (optimistic locking) plus incrementing etag --- infolog/inc/class.infolog_bo.inc.php | 9 +++++++-- infolog/inc/class.infolog_so.inc.php | 14 +++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/infolog/inc/class.infolog_bo.inc.php b/infolog/inc/class.infolog_bo.inc.php index 8b575bc79a..e55a60e758 100644 --- a/infolog/inc/class.infolog_bo.inc.php +++ b/infolog/inc/class.infolog_bo.inc.php @@ -961,6 +961,10 @@ class infolog_bo $check_modified = $values['info_datemodified'] && !$xmlrpc ? $to_write['info_datemodified'] : false; $values['info_datemodified'] = $this->user_time_now; $to_write['info_datemodified'] = $this->now; + if ($check_modified && isset($values['info_etag'])) + { + ++$values['info_etag']; + } } 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(!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); } @@ -1006,12 +1010,13 @@ class infolog_bo $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); if(!$values['info_link_id'] || $values['info_link_id'] != $to_write['info_link_id']) { // 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); $values['info_link_id'] = $to_write['info_link_id']; $values['info_contact'] = $to_write['info_contact']; diff --git a/infolog/inc/class.infolog_so.inc.php b/infolog/inc/class.infolog_so.inc.php index 95e0e96861..c1bd5bcd03 100644 --- a/infolog/inc/class.infolog_so.inc.php +++ b/infolog/inc/class.infolog_so.inc.php @@ -584,7 +584,19 @@ class infolog_so if (($this->data['info_id'] = $info_id) && !$force_insert) { $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__)) { //error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning false");