Changeset View
Changeset View
Standalone View
Standalone View
plugins/libkolab/lib/kolab_storage_cache.php
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | class kolab_storage_cache | ||||
protected $max_sync_lock_time = 600; | protected $max_sync_lock_time = 600; | ||||
protected $extra_cols = array(); | protected $extra_cols = array(); | ||||
protected $data_props = array(); | protected $data_props = array(); | ||||
protected $order_by = null; | protected $order_by = null; | ||||
protected $limit = null; | protected $limit = null; | ||||
protected $error = 0; | protected $error = 0; | ||||
protected $server_timezone; | protected $server_timezone; | ||||
protected $sync_start; | protected $sync_start; | ||||
protected $cache_bypassed = 0; | |||||
/** | /** | ||||
* Factory constructor | * Factory constructor | ||||
*/ | */ | ||||
public static function factory(kolab_storage_folder $storage_folder) | public static function factory(kolab_storage_folder $storage_folder) | ||||
{ | { | ||||
$subclass = 'kolab_storage_cache_' . $storage_folder->type; | $subclass = 'kolab_storage_cache_' . $storage_folder->type; | ||||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Lines | protected function synchronize_update() | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
// VANISHED found? | // VANISHED found? | ||||
$mbox_data = $this->imap->folder_data($this->folder->name); | $mbox_data = $this->imap->folder_data($this->folder->name); | ||||
// Removed vanished messages from the database | // Removed vanished messages from the database | ||||
$vanished = (array) rcube_imap_generic::uncompressMessageSet($mbox_data['VANISHED']); | $vanished = (array) rcube_imap_generic::uncompressMessageSet($mbox_data['VANISHED'] ?? null); | ||||
// Remove redundant entries from IMAP and DB | // Remove redundant entries from IMAP and DB | ||||
$vanished = array_merge($removed, array_intersect($vanished, $existing)); | $vanished = array_merge($removed, array_intersect($vanished, $existing)); | ||||
$this->synchronize_delete($removed, $vanished); | $this->synchronize_delete($removed, $vanished); | ||||
return $result; | return $result; | ||||
} | } | ||||
Show All 15 Lines | protected function synchronize_fetch($new_index, &$old_index, &$del_index) | ||||
// fetch new objects from imap | // fetch new objects from imap | ||||
foreach (array_diff($new_index, $old_index) as $msguid) { | foreach (array_diff($new_index, $old_index) as $msguid) { | ||||
// Note: We'll store only objects matching the folder type | // Note: We'll store only objects matching the folder type | ||||
// anything else will be silently ignored | // anything else will be silently ignored | ||||
if ($object = $this->folder->read_object($msguid)) { | if ($object = $this->folder->read_object($msguid)) { | ||||
// Deduplication: remove older objects with the same UID | // Deduplication: remove older objects with the same UID | ||||
// Here we do not resolve conflicts, we just make sure | // Here we do not resolve conflicts, we just make sure | ||||
// the most recent version of the object will be used | // the most recent version of the object will be used | ||||
if ($old_msguid = $old_index[$object['uid']]) { | if ($old_msguid = ($old_index[$object['uid']] ?? null)) { | ||||
if ($old_msguid < $msguid) { | if ($old_msguid < $msguid) { | ||||
$del_index[] = $old_msguid; | $del_index[] = $old_msguid; | ||||
} | } | ||||
else { | else { | ||||
$del_index[] = $msguid; | $del_index[] = $msguid; | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 649 Lines • ▼ Show 20 Lines | protected function _serialize($object) | ||||
return $sql_data; | return $sql_data; | ||||
} | } | ||||
/** | /** | ||||
* Helper method to turn stored cache data into a valid storage object | * Helper method to turn stored cache data into a valid storage object | ||||
*/ | */ | ||||
protected function _unserialize($sql_arr) | protected function _unserialize($sql_arr) | ||||
{ | { | ||||
if ($sql_arr['fast-mode'] && !empty($sql_arr['data']) && ($object = json_decode($sql_arr['data'], true))) { | if (($sql_arr['fast-mode'] ?? false) && !empty($sql_arr['data']) && ($object = json_decode($sql_arr['data'], true))) { | ||||
$object['uid'] = $sql_arr['uid']; | $object['uid'] = $sql_arr['uid']; | ||||
foreach ($this->data_props as $prop) { | foreach ($this->data_props as $prop) { | ||||
if (isset($object[$prop]) && is_array($object[$prop]) && $object[$prop]['cl'] == 'DateTime') { | if (isset($object[$prop]) && is_array($object[$prop]) && isset($object[$prop]['cl']) && $object[$prop]['cl'] == 'DateTime') { | ||||
$object[$prop] = new DateTime($object[$prop]['dt'], new DateTimeZone($object[$prop]['tz'])); | $object[$prop] = new DateTime($object[$prop]['dt'], new DateTimeZone($object[$prop]['tz'])); | ||||
} | } | ||||
else if (!isset($object[$prop]) && isset($sql_arr[$prop])) { | else if (!isset($object[$prop]) && isset($sql_arr[$prop])) { | ||||
$object[$prop] = $sql_arr[$prop]; | $object[$prop] = $sql_arr[$prop]; | ||||
} | } | ||||
} | } | ||||
if ($sql_arr['created'] && empty($object['created'])) { | if ($sql_arr['created'] && empty($object['created'])) { | ||||
$object['created'] = new DateTime($sql_arr['created']); | $object['created'] = new DateTime($sql_arr['created']); | ||||
} | } | ||||
if ($sql_arr['changed'] && empty($object['changed'])) { | if ($sql_arr['changed'] && empty($object['changed'])) { | ||||
$object['changed'] = new DateTime($sql_arr['changed']); | $object['changed'] = new DateTime($sql_arr['changed']); | ||||
} | } | ||||
$object['_type'] = $sql_arr['type'] ?: $this->folder->type; | $object['_type'] = $sql_arr['type'] ?? $this->folder->type; | ||||
$object['_msguid'] = $sql_arr['msguid']; | $object['_msguid'] = $sql_arr['msguid']; | ||||
$object['_mailbox'] = $this->folder->name; | $object['_mailbox'] = $this->folder->name; | ||||
} | } | ||||
// Fetch object xml | // Fetch object xml | ||||
else { | else { | ||||
// FIXME: Because old cache solution allowed storing objects that | // FIXME: Because old cache solution allowed storing objects that | ||||
// do not match folder type we may end up with invalid objects. | // do not match folder type we may end up with invalid objects. | ||||
// 2nd argument of read_object() here makes sure they are still | // 2nd argument of read_object() here makes sure they are still | ||||
▲ Show 20 Lines • Show All 356 Lines • Show Last 20 Lines |