Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ function preferences_list($p)
$timeslots = $this->rc->config->get('calendar_timeslots', $this->defaults['calendar_timeslots']);

$select = new html_select(['name' => '_timeslots', 'id' => $field_id]);
$select->add($choices);
foreach ($choices as $choice) {
$select->add($choice, $choice);
}

$p['blocks']['view']['options']['timeslots'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('timeslots'))),
Expand Down
4 changes: 2 additions & 2 deletions drivers/caldav/SQL/sqlite.initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CREATE TABLE IF NOT EXISTS `caldav_calendars` (
`showalarms` tinyINTEGER NOT NULL DEFAULT '1',
`caldav_tag` TEXT DEFAULT NULL,
`caldav_url` TEXT NOT NULL,
`caldav_last_change` timestamp NOT NULL ,
`caldav_last_change` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`is_ical` tinyINTEGER NOT NULL DEFAULT '0',
`ical_user` TEXT DEFAULT NULL,
`ical_pass` TEXT DEFAULT NULL,
Expand Down Expand Up @@ -78,7 +78,7 @@ CREATE TABLE IF NOT EXISTS `caldav_events` (
`notifyat` datetime DEFAULT NULL,
`caldav_url` TEXT NOT NULL,
`caldav_tag` TEXT DEFAULT NULL,
`caldav_last_change` timestamp NOT NULL ,
`caldav_last_change` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`calendar_id`)
REFERENCES `caldav_calendars`(`calendar_id`) ON DELETE CASCADE ON UPDATE CASCADE
);
Expand Down
38 changes: 24 additions & 14 deletions drivers/caldav/caldav_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ protected function _read_calendars()

if (!empty($this->rc->user->ID)) {
$calendar_ids = array();
$result = $this->rc->db->query('SELECT
$result = $this->rc->db->query('SELECT
cal.calendar_id AS `id`,
cal.source_id AS `source_id`,
cal.name AS `name`,
cal.color AS `color`,
cal.source_id AS `source_id`,
cal.name AS `name`,
cal.color AS `color`,
cal.showalarms AS `showalarms`,
cal.caldav_tag AS `caldav_tag`,
cal.caldav_tag AS `caldav_tag`,
cal.caldav_url AS `caldav_url`,
s.caldav_user AS `caldav_user`,
s.caldav_pass AS `caldav_pass`,
Expand Down Expand Up @@ -298,7 +298,7 @@ private function _add_calendars($calendars, $source) {
{
// Skip already existent calendars
$result = $this->rc->db->query("SELECT * FROM ".$this->db_calendars." WHERE user_id=? and caldav_url LIKE ?", $this->rc->user->ID, $calendar['href']);
if($this->rc->db->affected_rows($result)) continue;
if($this->rc->db->num_rows($result) > 0) continue;

$cal = array(
'caldav_url' => $calendar['href'],
Expand Down Expand Up @@ -333,35 +333,35 @@ private function _add_calendars($calendars, $source) {
public function create_source($source)
{
$source['caldav_url'] = self::_encode_url($source['caldav_url']);

// Re-discover all existing calendars systematically
try {
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;
Expand Down Expand Up @@ -2263,7 +2263,7 @@ private function _perform_updates($updates)
}

// no local event -> create event
else
else if(isset($update["remote_event"]))
{
$event = array_merge($update["remote_event"], array(
"caldav_url" => $update["url"],
Expand Down Expand Up @@ -2302,6 +2302,16 @@ private function _perform_updates($updates)
*/
private function _is_synced($cal_id)
{
if ($this->rc->db->db_provider == 'sqlite') {
// this is a minimal
$query = $this->rc->db->query(
"UPDATE ".$this->db_calendars." ".
"SET caldav_last_change = CURRENT_TIMESTAMP WHERE calendar_id = ?",
$cal_id);

return false;
}

// Atomic sql: Check for exceeded sync period and update last_change.
$query = $this->rc->db->query(
"UPDATE ".$this->db_calendars." ".
Expand Down