static int _cal_db_event_get_count(int *out_count);
static int _cal_db_event_get_count_with_query(calendar_query_h query, int *out_count);
static int _cal_db_event_update_dirty(calendar_record_h record, int is_dirty_in_time);
-static int __update_record(calendar_record_h record, int is_dirty_in_time);
/*
* static function
static int _cal_db_event_exception_get_ids(int original_id, GList **out_list);
static int _cal_db_event_exception_update(cal_list_s *exception_list_s, int original_id, int calendar_id, int is_dirty_in_time, time_t time_diff, int old_type, int new_type);
static int _cal_db_event_get_deleted_data(int id, int* calendar_book_id, int* created_ver, int* original_event_id, char** recurrence_id);
-static int _cal_db_event_exdate_insert_utime(int event_id, const char* original_exdate, const char* exdate, int **exception_id, int *exception_len, bool *needs_update);
+static void _cal_db_event_exdate_insert_utime(int event_id, const char* original_exdate, const char* exdate, int **exception_id, int *exception_len, bool *needs_update);
static bool _cal_db_event_check_calendar_book_type(calendar_record_h record);
static void __check_list(calendar_list_h l)
case CAL_PROPERTY_EVENT_BYMONTH:
case CAL_PROPERTY_EVENT_BYSETPOS:
case CAL_PROPERTY_EVENT_WKST:
-
is_dirty_in_time = DIRTY_IN_TIME;
break;
}
- if (DIRTY_IN_OTHER != is_dirty_in_time) break;
+ if (DIRTY_IN_OTHER != is_dirty_in_time)
+ break;
}
DBG("%sirty in time", DIRTY_IN_OTHER == is_dirty_in_time ? "Not d" : "D");
return is_dirty_in_time;
sqlite3_finalize(stmt);
}
-static int __update_record(calendar_record_h record, int is_dirty_in_time)
+static int _cal_db_event_update_record(calendar_record_h record)
{
int ret = 0;
char query[CAL_DB_SQL_MAX_LEN] = {0};
/* LCOV_EXCL_STOP */
}
+ int is_dirty_in_time = DIRTY_INIT;
if (event->common.properties_flags) {
if (DIRTY_INIT == is_dirty_in_time)
is_dirty_in_time = __is_dirty_in_time(record);
-
- return _cal_db_event_update_dirty(record, is_dirty_in_time);
+ _cal_db_event_update_dirty(record, is_dirty_in_time);
}
int time_diff = 0;
if (event->exdate) {
if (DIRTY_IN_TIME == is_dirty_in_time)
__update_exdate(event, time_diff);
-
cal_db_util_stmt_bind_text(stmt, index, event->exdate);
}
index++;
if (DIRTY_IN_TIME == is_dirty_in_time) {
cal_db_instance_discard_record(event->index);
cal_db_instance_publish_record(record);
-
} else {
cal_db_instance_update_exdate_del(event->index, event->exdate);
}
if (l) {
int child_id = GPOINTER_TO_INT(l->data);
/* update children original_event_id */
- cal_db_event_update_child_origina_event_id(child_id, event->index);
+ cal_db_event_update_child_original_event_id(child_id, event->index);
char *recurrence_id = NULL;
recurrence_id = cal_db_event_get_recurrence_id_from_exception(child_id);
if (recurrence_id) {
return CALENDAR_ERROR_NONE;
}
-static int _cal_db_event_update_record(calendar_record_h record)
-{
- return __update_record(record, DIRTY_INIT);
-}
-
static int _cal_db_event_add_exdate(int original_event_id, char* recurrence_id)
{
int ret = 0;
return CALENDAR_ERROR_PERMISSION_DENIED;
/* LCOV_EXCL_STOP */
}
- if (event->common.properties_flags != NULL)
- return _cal_db_event_update_dirty(record, -1);
+
+ int is_dirty_in_time = DIRTY_INIT;
+ if (event->common.properties_flags) {
+ if (DIRTY_INIT == is_dirty_in_time)
+ is_dirty_in_time = __is_dirty_in_time(record);
+ _cal_db_event_update_dirty(record, is_dirty_in_time);
+ }
+
+ int time_diff = 0;
+ calendar_time_s ct = {0};
+ if (DIRTY_IN_TIME == is_dirty_in_time) {
+ calendar_record_h old_record = NULL;
+ ret = cal_db_get_record(_calendar_event._uri, event->index, &old_record);
+ if (CALENDAR_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ ERR("calendar_db_get_record() Fail(%d)", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ /* get time diff */
+ char *old_tzid = NULL;
+ calendar_record_get_str_p(old_record, _calendar_event.start_tzid, &old_tzid);
+ calendar_record_get_caltime(old_record, _calendar_event.start_time, &ct);
+ time_diff = __get_time_diff(old_tzid, &ct, event->start_tzid, &event->start);
+ calendar_record_destroy(old_record, true);
+ }
has_alarm = cal_db_alarm_has_alarm(event->alarm_list);
cal_db_timezone_search_with_tzid(event->calendar_id, event->start_tzid, &timezone_id);
cal_db_util_stmt_bind_text(stmt, index, event->categories);
index++;
- if (event->exdate)
+ if (event->exdate) {
+ if (DIRTY_IN_TIME == is_dirty_in_time)
+ __update_exdate(event, time_diff);
cal_db_util_stmt_bind_text(stmt, index, event->exdate);
+ }
index++;
if (event->uid)
cal_db_rrule_update_record(id, rrule);
CAL_FREE(rrule);
- cal_db_instance_discard_record(id);
- cal_db_instance_publish_record(record);
+ if (DIRTY_IN_TIME == is_dirty_in_time) {
+ cal_db_instance_discard_record(id);
+ cal_db_instance_publish_record(record);
+ } else {
+ cal_db_instance_update_exdate_del(event->index, event->exdate);
+ }
+
+ while ((event->uid && *event->uid) && (NULL == event->recurrence_id || '\0' == *event->recurrence_id)) {
+ /* check if exception mod has. recurrence_id */
+ GList *list = NULL;
+ list = cal_db_event_get_list_with_uid(event->uid, event->index);
+ if (NULL == list)
+ break;
+ GList *l = g_list_first(list);
+ if (l) {
+ int child_id = GPOINTER_TO_INT(l->data);
+ /* update children original_event_id */
+ cal_db_event_update_child_original_event_id(child_id, event->index);
+ char *recurrence_id = NULL;
+ recurrence_id = cal_db_event_get_recurrence_id_from_exception(child_id);
+ if (recurrence_id) {
+ /* remove parent instance */
+ cal_db_event_apply_recurrence_id(event->index, event, recurrence_id, child_id);
+ free(recurrence_id);
+ }
+ l = g_list_next(l);
+ }
+ g_list_free(list);
+ break;
+ }
cal_db_alarm_delete_with_id(id);
cal_db_attendee_delete_with_id(id);
}
if (event->exception_list && 0 < event->exception_list->count) {
- ret = cal_db_event_insert_records(event->exception_list, id);
- WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_db_event_insert_records() Fail(%x)", ret);
+ ret = _cal_db_event_exception_update(event->exception_list, event->index,
+ event->calendar_id, is_dirty_in_time, time_diff, ct.type, event->start.type);
+ WARN_IF(CALENDAR_ERROR_NONE != ret, "_cal_db_event_exception_update() Fail(%d)", ret);
}
if (event->extended_list && 0 < event->extended_list->count) {
return ret;
}
-static int _cal_db_event_delete_exception(int *exception_ids, int exception_len)
+static void _cal_db_event_delete_exception(int *exception_ids, int exception_len)
{
int ret = 0;
char query[CAL_DB_SQL_MAX_LEN] = {0};
/* LCOV_EXCL_START */
ERR("cal_db_util_query_exec() Fail(%d)", ret);
SECURE("[%s]", query);
- return ret;
+ break;
/* LCOV_EXCL_STOP */
}
}
- return CALENDAR_ERROR_NONE;
}
-static int _cal_db_event_update_dirty(calendar_record_h record, int is_dirty_in_time)
+static int _cal_db_event_update_dirty(calendar_record_h in_record, int is_dirty_in_time)
{
+ RETV_IF(NULL == in_record, CALENDAR_ERROR_INVALID_PARAMETER);
+
int event_id = 0;
int ret = CALENDAR_ERROR_NONE;
- calendar_record_h original_record = NULL;
- ret = calendar_record_get_int(record, _calendar_event.id, &event_id);
+ ret = calendar_record_get_int(in_record, _calendar_event.id, &event_id);
RETV_IF(CALENDAR_ERROR_NONE != ret, ret);
DBG("id=%d", event_id);
- ret = _cal_db_event_get_record(event_id, &original_record);
+ calendar_record_h db_record = NULL;
+ ret = _cal_db_event_get_record(event_id, &db_record);
RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "_cal_db_event_get_record() Fail(%d)", ret);
- cal_record_s *_record = NULL;
+ cal_event_s *in_event = (cal_event_s *)in_record;
+ cal_event_s *db_event = (cal_event_s *)db_record;
+
+ int i = 0;
const cal_property_info_s* property_info = NULL;
int property_info_count = 0;
- int i = 0;
-
- _record = (cal_record_s *)record;
-
- property_info = cal_view_get_property_info(_record->view_uri, &property_info_count);
+ property_info = cal_view_get_property_info(((cal_record_s *)in_record)->view_uri, &property_info_count);
for (i = 0; i < property_info_count; i++) {
- if (false == cal_record_check_property_flag(record, property_info[i].property_id , CAL_PROPERTY_FLAG_DIRTY))
+ if (false == cal_record_check_property_flag(in_record, property_info[i].property_id , CAL_PROPERTY_FLAG_DIRTY))
continue;
if (property_info[i].property_id == CAL_PROPERTY_EVENT_EXDATE) {
- int calendar_id = 0;
- int account_id = 0;
- calendar_book_sync_event_type_e sync_event_type = CALENDAR_BOOK_SYNC_EVENT_FOR_ME;
-
- char *record_exdate = NULL;
- ret = calendar_record_get_str_p(record, property_info[i]. property_id, &record_exdate);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- ret = calendar_record_get_int(original_record, CAL_PROPERTY_EVENT_BOOK_ID, &calendar_id);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
calendar_record_h record_calendar = NULL;
- ret = cal_db_get_record(_calendar_book._uri, calendar_id, &record_calendar);
- ret |= calendar_record_get_int(record_calendar, _calendar_book.account_id, &account_id);
- ret |= calendar_record_get_int(record_calendar, _calendar_book.sync_event, (int *)&sync_event_type);
- DBG("calendar_id(%d), account_id(%d), sync_event(%d)", calendar_id, account_id, sync_event_type);
- calendar_record_destroy(record_calendar, true);
+ ret = cal_db_get_record(_calendar_book._uri, db_event->calendar_id, &record_calendar);
- char *original_exdate = NULL;
- ret = calendar_record_get_str_p(original_record, property_info[i].property_id, &original_exdate);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
+ cal_book_s *db_book = (cal_book_s*)record_calendar;
+ calendar_book_sync_event_type_e sync_event_type = db_book->sync_event;
+ DBG("calendar_id(%d), account_id(%d), sync_event(%d)",
+ db_event->calendar_id, db_book->account_id, db_book->sync_event);
+ calendar_record_destroy(record_calendar, true);
bool needs_update = false;
if (sync_event_type == CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN) {
- ret = _cal_db_event_exdate_insert_utime(event_id, original_exdate,
- record_exdate, NULL, NULL, &needs_update);
- WARN_IF(CALENDAR_ERROR_NONE != ret, "%s->%s", original_exdate, record_exdate);
+ _cal_db_event_exdate_insert_utime(event_id, db_event->exdate,
+ in_event->exdate, NULL, NULL, &needs_update);
} else {
int *exception_ids = NULL;
int exception_len = 0;
- ret = _cal_db_event_exdate_insert_utime(event_id, original_exdate,
- record_exdate, &exception_ids, &exception_len, &needs_update);
- WARN_IF(CALENDAR_ERROR_NONE != ret, "%s->%s", original_exdate, record_exdate);
- ret = _cal_db_event_delete_exception(exception_ids, exception_len);
- WARN_IF(CALENDAR_ERROR_NONE != ret, "_cal_db_event_delete_record() Fail");
+ _cal_db_event_exdate_insert_utime(event_id, db_event->exdate,
+ in_event->exdate, &exception_ids, &exception_len, &needs_update);
+ _cal_db_event_delete_exception(exception_ids, exception_len);
free(exception_ids);
}
+ DBG("Modified exdate (%s->%s)", db_event->exdate, in_event->exdate);
if (needs_update) {
- ret = cal_record_set_str(original_record, property_info[i].property_id, record_exdate);
+ ret = cal_record_set_str(db_record, property_info[i].property_id, in_event->exdate);
if (CALENDAR_ERROR_NONE != ret)
continue;
}
- } else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id, CAL_PROPERTY_DATA_TYPE_INT) == true) {
- int tmp = 0;
- ret = calendar_record_get_int(record, property_info[i].property_id, &tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- ret = cal_record_set_int(original_record, property_info[i].property_id, tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- } else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id, CAL_PROPERTY_DATA_TYPE_STR) == true) {
- char *tmp = NULL;
- ret = calendar_record_get_str_p(record, property_info[i].property_id, &tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- ret = cal_record_set_str(original_record, property_info[i].property_id, tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- } else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id, CAL_PROPERTY_DATA_TYPE_DOUBLE) == true) {
- double tmp = 0;
- ret = calendar_record_get_double(record, property_info[i].property_id, &tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- ret = cal_record_set_double(original_record, property_info[i].property_id, tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- } else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id, CAL_PROPERTY_DATA_TYPE_LLI) == true) {
- long long int tmp = 0;
- ret = calendar_record_get_lli(record, property_info[i].property_id, &tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- ret = cal_record_set_lli(original_record, property_info[i].property_id, tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- } else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true) {
- calendar_time_s tmp = {0,};
- ret = calendar_record_get_caltime(record, property_info[i].property_id, &tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
- ret = cal_record_set_caltime(original_record, property_info[i].property_id, tmp);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
+ break;
}
}
- /* child replace */
- cal_event_s *tmp = (cal_event_s *)original_record;
- cal_event_s *tmp_src = (cal_event_s *)record;
-
- if (tmp->alarm_list)
- calendar_list_destroy((calendar_list_h)tmp->alarm_list, true);
- cal_list_clone((calendar_list_h)tmp_src->alarm_list, (calendar_list_h *)&tmp->alarm_list);
-
- if (tmp->attendee_list)
- calendar_list_destroy((calendar_list_h)tmp->attendee_list, true);
- cal_list_clone((calendar_list_h)tmp_src->attendee_list, (calendar_list_h *)&tmp->attendee_list);
-
- if (tmp->exception_list)
- calendar_list_destroy((calendar_list_h)tmp->exception_list, true);
- cal_list_clone((calendar_list_h)tmp_src->exception_list, (calendar_list_h *)&tmp->exception_list);
-
- if (tmp->extended_list)
- calendar_list_destroy((calendar_list_h)tmp->extended_list, true);
- cal_list_clone((calendar_list_h)tmp_src->extended_list, (calendar_list_h *)&tmp->extended_list);
-
- CAL_RECORD_RESET_COMMON((cal_record_s*)original_record);
- ret = __update_record(original_record, is_dirty_in_time);
- calendar_record_destroy(original_record, true);
+ calendar_record_destroy(db_record, true);
+ CAL_RECORD_RESET_COMMON((cal_record_s*)in_record);
return ret;
}
return CALENDAR_ERROR_NONE;
}
-static int _cal_db_event_exdate_insert_utime(int event_id, const char* original_exdate,
+static void _cal_db_event_exdate_insert_utime(int event_id, const char* original_exdate,
const char* inserted_exdate, int **exception_ids, int *exception_len, bool *needs_update)
{
int ret = CALENDAR_ERROR_NONE;
if (len_inserted <= 0) {
ERR("len_inserted is 0");
g_strfreev(t_inserted);
- return CALENDAR_ERROR_OUT_OF_MEMORY;
+ return;
}
if (NULL != original_exdate && '\0' != *original_exdate) {
ERR("calloc() Fail");
g_strfreev(t_inserted);
g_strfreev(t_original);
- return CALENDAR_ERROR_OUT_OF_MEMORY;
+ return;
}
int exception_count = 0;
g_strfreev(t_inserted);
g_strfreev(t_original);
- return ret;
}