Fixed some problems with the etag handling, causing an SQL error on

merging contacts, as reported by Johannes Gorschlüter from Stylite
This commit is contained in:
Ralf Becker 2008-05-17 06:44:17 +00:00
parent d884a13521
commit b69b8085e6
3 changed files with 14 additions and 4 deletions

View File

@ -1006,6 +1006,7 @@ class addressbook_bo extends addressbook_so
case 'tid':
case 'owner':
case 'private':
case 'etag';
break; // ignored
case 'cat_id': // cats are all merged together

View File

@ -625,6 +625,7 @@ class addressbook_sql extends so_sql
}
else
{
unset($this->data['etag']);
$new_entry = !$this->data['id'];
if (!($err = parent::save(array('contact_etag=contact_etag+1'))) && $new_entry)
{

View File

@ -422,8 +422,8 @@ class so_sql
* saves the content of data to the db
*
* @param array $keys if given $keys are copied to data before saveing => allows a save as
* @param string|array $extra_where=null extra where clause, eg. to check the etag, returns 'nothing_affected' if not affected rows
* @return int 0 on success and errno != 0 else
* @param string|array $extra_where=null extra where clause, eg. to check an etag, returns true if no affected rows!
* @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
*/
function save($keys=null,$extra_where=null)
{
@ -489,15 +489,23 @@ class so_sql
$data = $keys;
$keys = False;
}
if ($this->autoinc_id)
{
$this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app);
if (($nothing_affected = !$this->db->Errno && !$this->db->affected_rows()) && $extra_where)
{
return true; // extra_where not met, eg. etag wrong
}
}
// always try an insert if we have no autoinc_id, as we dont know if the data exists
if (!$this->autoinc_id || !$this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app) || !$this->db->affected_rows())
if (!$this->autoinc_id || $nothing_affected)
{
$this->db->insert($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app);
}
}
$this->db2data();
return $this->db->Errno ? $this->db->Errno : ($extra_where && !$this->db->affected_rows() ? true : 0);
return $this->db->Errno;
}
/**