Only skip update if the set of available calendars did not changed.

This is necessary to automatically update sources for which the calendars have been added or deleted by another client than roundcube. It is typically the case when managing sharing access in nextcloud while still being able to view them in roundcube.
This commit is contained in:
Alexis DUBURCQ 2022-12-28 01:14:59 +01:00 committed by GitHub
parent f0a90df1d3
commit 61eb3a4a16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -333,19 +333,36 @@ class caldav_driver extends calendar_driver
public function create_source($source)
{
$source['caldav_url'] = self::_encode_url($source['caldav_url']);
// Skip already exiting sources
$result = $this->rc->db->query("SELECT user_id, caldav_url, caldav_user FROM " . $this->db_sources . " WHERE user_id=? AND caldav_url=? AND caldav_user=?", $this->rc->user->ID, $source['caldav_url'], $source['caldav_user']);
if($this->rc->db->affected_rows($result)) return true;
try {
// Re-discover all existing calendars systematically
try {
$calendars = $this->_autodiscover_calendars($source);
}
}
catch(Exception $e) {
self::debug_log($e);
$this->rc->output->show_message($this->cal->gettext('source_notadded_error'), 'error');
return false;
}
// Remove local data associated with deprecated calendars
$caldav_urls = array_column($calendars, 'href');
$query = $this->rc->db->query(
"DELETE FROM " . $this->db_calendars . " WHERE user_id=? AND caldav_url NOT IN ('" . implode("','", $caldav_urls) . "')",
$this->rc->user->ID);
$this->rc->db->affected_rows($query);
// Skip update if the set of available calendars matches
$result = $this->rc->db->query(
"SELECT calendar_id FROM " . $this->db_calendars . " WHERE user_id=? AND caldav_url LIKE ?",
$this->rc->user->ID, $source['caldav_url'] . '%');
$count_cur = $this->rc->db->num_rows($result);
$count_avail = count($calendars);
if ($count_cur == $count_avail)
{
self::debug_log("Skip source update.");
return true;
}
if(count($calendars)) {
$pass = isset($source['caldav_pass']) ? $this->_encrypt_pass($source['caldav_pass']) : null;
$db_source_result = $this->rc->db->query(