Merge pull request #34 from duburcqa/patch-1
Only skip update if the set of available calendars did not changed Closes #13
This commit is contained in:
commit
43c30995b0
1 changed files with 24 additions and 7 deletions
|
@ -333,19 +333,36 @@ class caldav_driver extends calendar_driver
|
||||||
public function create_source($source)
|
public function create_source($source)
|
||||||
{
|
{
|
||||||
$source['caldav_url'] = self::_encode_url($source['caldav_url']);
|
$source['caldav_url'] = self::_encode_url($source['caldav_url']);
|
||||||
|
|
||||||
// Skip already exiting sources
|
// Re-discover all existing calendars systematically
|
||||||
$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']);
|
try {
|
||||||
if($this->rc->db->affected_rows($result)) return true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$calendars = $this->_autodiscover_calendars($source);
|
$calendars = $this->_autodiscover_calendars($source);
|
||||||
}
|
}
|
||||||
catch(Exception $e) {
|
catch(Exception $e) {
|
||||||
self::debug_log($e);
|
self::debug_log($e);
|
||||||
$this->rc->output->show_message($this->cal->gettext('source_notadded_error'), 'error');
|
$this->rc->output->show_message($this->cal->gettext('source_notadded_error'), 'error');
|
||||||
return false;
|
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)) {
|
if(count($calendars)) {
|
||||||
$pass = isset($source['caldav_pass']) ? $this->_encrypt_pass($source['caldav_pass']) : null;
|
$pass = isset($source['caldav_pass']) ? $this->_encrypt_pass($source['caldav_pass']) : null;
|
||||||
$db_source_result = $this->rc->db->query(
|
$db_source_result = $this->rc->db->query(
|
||||||
|
|
Loading…
Reference in a new issue