Changeset View
Changeset View
Standalone View
Standalone View
plugins/libkolab/lib/kolab_storage_cache.php
Show All 19 Lines | |||||
* | * | ||||
* You should have received a copy of the GNU Affero General Public License | * You should have received a copy of the GNU Affero General Public License | ||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
class kolab_storage_cache | class kolab_storage_cache | ||||
{ | { | ||||
const DB_DATE_FORMAT = 'Y-m-d H:i:s'; | const DB_DATE_FORMAT = 'Y-m-d H:i:s'; | ||||
const MAX_RECORDS = 500; | |||||
public $sync_complete = false; | public $sync_complete = false; | ||||
protected $db; | protected $db; | ||||
protected $imap; | protected $imap; | ||||
protected $folder; | protected $folder; | ||||
protected $uid2msg; | protected $uid2msg; | ||||
protected $objects; | protected $objects; | ||||
▲ Show 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | public function save($msguid, $object, $olduid = null) | ||||
$this->check_error(); | $this->check_error(); | ||||
} | } | ||||
/** | /** | ||||
* Move an existing cache entry to a new resource | * Move an existing cache entry to a new resource | ||||
* | * | ||||
* @param string Entry's IMAP message UID | * @param string Entry's IMAP message UID | ||||
* @param string Entry's Object UID | * @param string Entry's Object UID | ||||
* @param object kolab_storage_folder Target storage folder instance | * @param kolab_storage_folder Target storage folder instance | ||||
* @param string Target entry's IMAP message UID | |||||
*/ | */ | ||||
public function move($msguid, $uid, $target) | public function move($msguid, $uid, $target, $new_msguid = null) | ||||
{ | { | ||||
if ($this->ready) { | if ($this->ready && $target) { | ||||
// clear cached uid mapping and force new lookup | // clear cached uid mapping and force new lookup | ||||
unset($target->cache->uid2msg[$uid]); | unset($target->cache->uid2msg[$uid]); | ||||
// resolve new message UID in target folder | // resolve new message UID in target folder | ||||
if ($new_msguid = $target->cache->uid2msguid($uid)) { | if (!$new_msguid) { | ||||
$new_msguid = $target->cache->uid2msguid($uid); | |||||
} | |||||
if ($new_msguid) { | |||||
$this->_read_folder_data(); | $this->_read_folder_data(); | ||||
$this->db->query( | $this->db->query( | ||||
"UPDATE `{$this->cache_table}` SET `folder_id` = ?, `msguid` = ? ". | "UPDATE `{$this->cache_table}` SET `folder_id` = ?, `msguid` = ? ". | ||||
"WHERE `folder_id` = ? AND `msguid` = ?", | "WHERE `folder_id` = ? AND `msguid` = ?", | ||||
$target->cache->get_folder_id(), | $target->cache->get_folder_id(), | ||||
$new_msguid, | $new_msguid, | ||||
$this->folder_id, | $this->folder_id, | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | class kolab_storage_cache | ||||
{ | { | ||||
$result = $uids ? array() : new kolab_storage_dataset($this); | $result = $uids ? array() : new kolab_storage_dataset($this); | ||||
// read from local cache DB (assume it to be synchronized) | // read from local cache DB (assume it to be synchronized) | ||||
if ($this->ready) { | if ($this->ready) { | ||||
$this->_read_folder_data(); | $this->_read_folder_data(); | ||||
// fetch full object data on one query if a small result set is expected | // fetch full object data on one query if a small result set is expected | ||||
$fetchall = !$uids && ($this->limit ? $this->limit[0] : ($count = $this->count($query))) < 500; | $fetchall = !$uids && ($this->limit ? $this->limit[0] : ($count = $this->count($query))) < self::MAX_RECORDS; | ||||
// skip SELECT if we know it will return nothing | // skip SELECT if we know it will return nothing | ||||
if ($count === 0) { | if ($count === 0) { | ||||
return $result; | return $result; | ||||
} | } | ||||
$sql_query = "SELECT " . ($fetchall ? '*' : "`msguid` AS `_msguid`, `uid`") | $sql_query = "SELECT " . ($fetchall ? '*' : "`msguid` AS `_msguid`, `uid`") | ||||
. " FROM `{$this->cache_table}` WHERE `folder_id` = ?" | . " FROM `{$this->cache_table}` WHERE `folder_id` = ?" | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | class kolab_storage_cache | ||||
} | } | ||||
/** | /** | ||||
* Define ORDER BY clause for cache queries | * Define ORDER BY clause for cache queries | ||||
*/ | */ | ||||
public function set_order_by($sortcols) | public function set_order_by($sortcols) | ||||
{ | { | ||||
if (!empty($sortcols)) { | if (!empty($sortcols)) { | ||||
$this->order_by = '`' . join('`, `', (array)$sortcols) . '`'; | $sortcols = array_map(function($v) { | ||||
list($column, $order) = explode(' ', $v, 2); | |||||
return "`$column`" . ($order ? " $order" : ''); | |||||
}, (array) $sortcols); | |||||
$this->order_by = join(', ', $sortcols); | |||||
} | } | ||||
else { | else { | ||||
$this->order_by = null; | $this->order_by = null; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Define LIMIT clause for cache queries | * Define LIMIT clause for cache queries | ||||
▲ Show 20 Lines • Show All 495 Lines • Show Last 20 Lines |