small fix for the etag & uid handling of new entries

This commit is contained in:
Ralf Becker 2008-04-26 08:46:44 +00:00
parent 163b795d45
commit 69d7ee916d
3 changed files with 11 additions and 3 deletions

View File

@ -529,6 +529,7 @@ class bocontacts extends socontacts
if(!($this->error = parent::save($to_write)) && is_object($GLOBALS['egw']->contenthistory)) if(!($this->error = parent::save($to_write)) && is_object($GLOBALS['egw']->contenthistory))
{ {
$contact['id'] = $to_write['id']; $contact['id'] = $to_write['id'];
$contact['uid'] = $to_write['uid'];
$contact['etag'] = $to_write['etag']; $contact['etag'] = $to_write['etag'];
$GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $contact['id'],$isUpdate ? 'modify' : 'add', time()); $GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $contact['id'],$isUpdate ? 'modify' : 'add', time());

View File

@ -464,6 +464,7 @@ class socontacts
if (!($error_nr = $this->somain->save())) if (!($error_nr = $this->somain->save()))
{ {
$contact['id'] = $this->somain->data['id']; $contact['id'] = $this->somain->data['id'];
$contact['uid'] = $this->somain->data['uid'];
$contact['etag'] = $this->somain->data['etag']; $contact['etag'] = $this->somain->data['etag'];
if ($this->contact_repository == 'sql-ldap') if ($this->contact_repository == 'sql-ldap')

View File

@ -610,7 +610,7 @@ class socontacts_sql extends so_sql
{ {
if (is_array($keys) && count($keys)) $this->data_merge($keys); if (is_array($keys) && count($keys)) $this->data_merge($keys);
if (isset($this->data['etag'])) if (isset($this->data['etag'])) // do we have an etag in the data to write
{ {
$etag = $this->data['etag']; $etag = $this->data['etag'];
unset($this->data['etag']); unset($this->data['etag']);
@ -625,11 +625,17 @@ class socontacts_sql extends so_sql
} }
else else
{ {
$err = parent::save(); $new_entry = !$this->data['id'];
if (!($err = parent::save(array('contact_etag=contact_etag+1'))) && $new_entry)
{
$this->data['etag'] = 0;
}
} }
if (!$err && !$this->data['uid']) if (!$err && !$this->data['uid'])
{ {
$this->update(array('uid' => common::generate_uid('addressbook',$this->data['id']))); parent::update(array('uid' => common::generate_uid('addressbook',$this->data['id'])));
$this->data['etag']++;
//echo "<p>set uid={$this->data['uid']}, etag={$this->data['etag']}</p>";
} }
return $err; return $err;
} }