From: minje.ahn Date: Fri, 24 Feb 2023 04:11:33 +0000 (+0900) Subject: Restore media_info_delete_from_db to product API X-Git-Tag: accepted/tizen/unified/20230306.081555^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fapi%2Fmedia-content.git;a=commitdiff_plain;h=05e80c08c239aebb3032abc9b015c6337dd5d55f Restore media_info_delete_from_db to product API A long-deprecated public API was recently removed, but since the product module prv-service is still required, it has been restored and moved into the product header. Change-Id: If26b36dca847063612fd66dfc2f2ac639f652909 Signed-off-by: minje.ahn --- diff --git a/include_product/media_content_product.h b/include_product/media_content_product.h index 47a30fe..c3f0b2b 100755 --- a/include_product/media_content_product.h +++ b/include_product/media_content_product.h @@ -32,6 +32,8 @@ int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan /********** media_info **********/ +int media_info_delete_from_db(const char *media_id); + /** * @brief Gets the extract_flag of media info. * @since_tizen 2.3 diff --git a/src/media_info.c b/src/media_info.c index 06634d0..f9084ab 100644 --- a/src/media_info.c +++ b/src/media_info.c @@ -454,6 +454,62 @@ int media_info_get_media_info_by_path_from_db(const char* path, media_info_h* me return ret; } + +static int __media_info_get_media_path_by_id_from_db(const char *media_id, char **path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char *select_query = NULL; + + content_retip_if_fail(STRING_VALID(media_id)); + + select_query = sqlite3_mprintf(SELECT_MEDIA_PATH_BY_ID, media_id); + + ret = _content_get_result(select_query, &stmt); + SQLITE3_SAFE_FREE(select_query); + content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + if (sqlite3_step(stmt) == SQLITE_ROW) { + *path = g_strdup((const char *)sqlite3_column_text(stmt, 0)); + } else { + content_error("There's no media with this ID : %s", media_id); + *path = NULL; + ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} + +int media_info_delete_from_db(const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *path = NULL; + char *storage_id = NULL; + + content_retip_if_fail(STRING_VALID(media_id)); + + ret = __media_info_get_media_path_by_id_from_db(media_id, &path); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + content_error("__media_info_get_media_path_by_id_from_db failed : %d", ret); + g_free(path); + return ret; + } + + ret = _media_db_get_storage_id_by_media_id(media_id, &storage_id); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + content_error("_media_db_get_storage_id_by_media_id failed : %d", ret); + g_free(path); + return ret; + } + + ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, path, _content_get_uid()); + g_free(path); + g_free(storage_id); + + return _content_error_capi(ret); +} #endif int media_info_destroy(media_info_h media)