From: Jeesun Kim Date: Fri, 18 Aug 2017 00:45:26 +0000 (+0900) Subject: Fix replace to update instance when time is modified X-Git-Tag: accepted/tizen/4.0/unified/20170829.020337^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=10d91993d6f64bd8be4a9e3ef87c8bee64d35c8c;p=platform%2Fcore%2Fpim%2Fcalendar-service.git Fix replace to update instance when time is modified Change-Id: I93b9477be5ae9d476bb839d9eaa0671d068bf6c2 --- diff --git a/server/db/cal_db_plugin_event.c b/server/db/cal_db_plugin_event.c index 3fe6608..4630561 100644 --- a/server/db/cal_db_plugin_event.c +++ b/server/db/cal_db_plugin_event.c @@ -50,7 +50,6 @@ static int _cal_db_event_get_records_with_query(calendar_query_h query, int offs 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 @@ -62,7 +61,7 @@ int cal_db_event_exception_get_records(int original_id, cal_list_s *list); 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) @@ -251,11 +250,11 @@ static int __is_dirty_in_time(calendar_record_h record) 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; @@ -497,7 +496,7 @@ static void _cal_db_exception_delete_with_id(int original_event_id) 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}; @@ -530,11 +529,11 @@ static int __update_record(calendar_record_h record, int is_dirty_in_time) /* 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; @@ -683,7 +682,6 @@ static int __update_record(calendar_record_h record, int is_dirty_in_time) 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++; @@ -772,7 +770,6 @@ static int __update_record(calendar_record_h record, int is_dirty_in_time) 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); } @@ -787,7 +784,7 @@ static int __update_record(calendar_record_h record, int is_dirty_in_time) 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) { @@ -832,11 +829,6 @@ static int __update_record(calendar_record_h record, int is_dirty_in_time) 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; @@ -1476,8 +1468,33 @@ static int _cal_db_event_replace_record(calendar_record_h record, int id) 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); @@ -1599,8 +1616,11 @@ static int _cal_db_event_replace_record(calendar_record_h record, int 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) @@ -1684,8 +1704,36 @@ static int _cal_db_event_replace_record(calendar_record_h record, int id) 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); @@ -1703,8 +1751,9 @@ static int _cal_db_event_replace_record(calendar_record_h record, int 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) { @@ -2213,7 +2262,7 @@ static bool _cal_db_event_check_calendar_book_type(calendar_record_h record) 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}; @@ -2226,151 +2275,75 @@ static int _cal_db_event_delete_exception(int *exception_ids, int exception_len) /* 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; } @@ -2628,7 +2601,7 @@ static int _cal_db_event_get_deleted_data(int id, int* book_id, int* created_ver 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; @@ -2644,7 +2617,7 @@ static int _cal_db_event_exdate_insert_utime(int event_id, const char* original_ 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) { @@ -2657,7 +2630,7 @@ static int _cal_db_event_exdate_insert_utime(int event_id, const char* original_ ERR("calloc() Fail"); g_strfreev(t_inserted); g_strfreev(t_original); - return CALENDAR_ERROR_OUT_OF_MEMORY; + return; } int exception_count = 0; @@ -2728,5 +2701,4 @@ static int _cal_db_event_exdate_insert_utime(int event_id, const char* original_ g_strfreev(t_inserted); g_strfreev(t_original); - return ret; } diff --git a/server/db/cal_db_plugin_event_helper.c b/server/db/cal_db_plugin_event_helper.c index 2c30330..b40f141 100644 --- a/server/db/cal_db_plugin_event_helper.c +++ b/server/db/cal_db_plugin_event_helper.c @@ -189,7 +189,7 @@ GList* cal_db_event_get_list_with_uid(char *uid, int parent_id) return l; } -void cal_db_event_update_child_origina_event_id(int child_id, int parent_id) +void cal_db_event_update_child_original_event_id(int child_id, int parent_id) { CAL_FN_CALL(); @@ -344,14 +344,14 @@ static void __get_next_instance_caltime(int parent_id, calendar_time_s *caltime, /* LCOV_EXCL_STOP */ } - while (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt)) { + if (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt)) { dtstart->type = CALENDAR_TIME_UTIME; dtstart->time.utime = sqlite3_column_int64(stmt, 0); dtend->type = CALENDAR_TIME_UTIME; dtend->time.utime = sqlite3_column_int64(stmt, 0); - break; } break; + case CALENDAR_TIME_LOCALTIME: snprintf(query, sizeof(query), "SELECT dtstart_datetime, dtend_datetime FROM %s " "WHERE event_id=%d AND dtstart_datetime>'%04d-%02d-%02dT%02d:%02d:%02d' " @@ -409,12 +409,12 @@ static void __get_last_instance_caltime(int parent_id, int type, calendar_time_s return; /* LCOV_EXCL_STOP */ } - while (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt)) { + if (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt)) { dtstart->type = CALENDAR_TIME_UTIME; dtstart->time.utime = sqlite3_column_int64(stmt, 0); - break; } break; + case CALENDAR_TIME_LOCALTIME: snprintf(query, sizeof(query), "SELECT dtstart_datetime FROM %s WHERE event_id=%d " "ORDER BY dtstart_datetime DESC LIMIT 1", @@ -927,7 +927,7 @@ int cal_db_event_insert_record(calendar_record_h record, int original_event_id, 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_id); + cal_db_event_update_child_original_event_id(child_id, event_id); char *recurrence_id = NULL; recurrence_id = cal_db_event_get_recurrence_id_from_exception(child_id); if (NULL == recurrence_id || '\0' == *recurrence_id) { diff --git a/server/db/cal_db_plugin_event_helper.h b/server/db/cal_db_plugin_event_helper.h index 99130bc..384b932 100644 --- a/server/db/cal_db_plugin_event_helper.h +++ b/server/db/cal_db_plugin_event_helper.h @@ -25,7 +25,7 @@ int cal_db_event_check_value_validation(cal_event_s *event); int cal_db_event_insert_record(calendar_record_h record, int original_event_id, int *id); int cal_db_event_insert_records(cal_list_s *list_s, int original_event_id); GList *cal_db_event_get_list_with_uid(char *uid, int parent_id); -void cal_db_event_update_child_origina_event_id(int child_id, int parent_id); +void cal_db_event_update_child_original_event_id(int child_id, int parent_id); char *cal_db_event_get_recurrence_id_from_exception(int child_id); void cal_db_event_apply_recurrence_id(int parent_id, cal_event_s *event, char *recurrence_id, int child_id);