Merge branch 'master' of ssh://git.kolab.org/git/roundcubemail-plugins-kolab

This commit is contained in:
Thomas Bruederli 2013-11-20 12:36:40 +01:00
commit 7299978854
2 changed files with 44 additions and 34 deletions

View file

@ -274,41 +274,48 @@ class kolab_storage_cache
/** /**
* Insert a cache entry * Insert (or update) a cache entry
* *
* @param string Related IMAP message UID * @param int Related IMAP message UID
* @param mixed Hash array with object properties to save or false to delete the cache entry * @param mixed Hash array with object properties to save or false to delete the cache entry
* @param int Optional old message UID (for update)
*/ */
public function insert($msguid, $object) public function save($msguid, $object, $olduid)
{ {
// write to cache // write to cache
if ($this->ready) { if ($this->ready) {
$this->_read_folder_data(); $this->_read_folder_data();
$sql_data = $this->_serialize($object); $sql_data = $this->_serialize($object);
$sql_data['folder_id'] = $this->folder_id;
$sql_data['msguid'] = $msguid;
$sql_data['uid'] = $object['uid'];
$extra_cols = $this->extra_cols ? ', ' . join(', ', $this->extra_cols) : ''; $args = array();
$extra_fields = $this->extra_cols ? str_repeat(', ?', count($this->extra_cols)) : ''; $cols = array('folder_id', 'msguid', 'uid', 'changed', 'data', 'xml', 'tags', 'words');
$cols = array_merge($cols, $this->extra_cols);
$args = array( foreach ($cols as $idx => $col) {
"INSERT INTO $this->cache_table ". $cols[$idx] = $this->db->quote_identifier($col);
" (folder_id, msguid, uid, created, changed, data, xml, tags, words $extra_cols)". $args[] = $sql_data[$col];
" VALUES (?, ?, ?, " . $this->db->now() . ", ?, ?, ?, ?, ? $extra_fields)",
$this->folder_id,
$msguid,
$object['uid'],
$sql_data['changed'],
$sql_data['data'],
$sql_data['xml'],
$sql_data['tags'],
$sql_data['words'],
);
foreach ($this->extra_cols as $col) {
$args[] = $sql_data[$col];
} }
$result = call_user_func_array(array($this->db, 'query'), $args); if ($olduid) {
foreach ($cols as $idx => $col) {
$cols[$idx] = "$col = ?";
}
$query = "UPDATE $this->cache_table SET " . implode(', ', $cols)
. " WHERE folder_id = ? AND msguid = ?";
$args[] = $this->folder_id;
$args[] = $olduid;
}
else {
$query = "INSERT INTO $this->cache_table (created, " . implode(', ', $cols)
. ") VALUES (" . $this->db->now() . str_repeat(', ?', count($cols)) . ")";
}
$result = $this->db->query($query, $args);
if (!$this->db->affected_rows($result)) { if (!$this->db->affected_rows($result)) {
rcube::raise_error(array( rcube::raise_error(array(

View file

@ -753,24 +753,27 @@ class kolab_storage_folder
$result = $this->imap->save_message($this->name, $raw_msg, null, false, null, null, $binary); $result = $this->imap->save_message($this->name, $raw_msg, null, false, null, null, $binary);
// delete old message
if ($result && !empty($object['_msguid']) && !empty($object['_mailbox'])) {
$this->cache->bypass(true);
$this->imap->delete_message($object['_msguid'], $object['_mailbox']);
$this->cache->bypass(false);
$this->cache->set($object['_msguid'], false, $object['_mailbox']);
}
// update cache with new UID // update cache with new UID
if ($result) { if ($result) {
$old_uid = $object['_msguid'];
$object['_msguid'] = $result; $object['_msguid'] = $result;
$object['_mailbox'] = $this->name; $object['_mailbox'] = $this->name;
$this->cache->insert($result, $object);
// remove temp file if ($old_uid) {
if ($body_file) { // delete old message
@unlink($body_file); $this->cache->bypass(true);
$this->imap->delete_message($old_uid, $object['_mailbox']);
$this->cache->bypass(false);
} }
// insert/update message in cache
$this->cache->save($result, $object, $old_uid);
}
// remove temp file
if ($body_file) {
@unlink($body_file);
} }
} }