1 /* 2 * Copyright (C) 2024-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_MEDIA_PHOTO_SOURCE_PATH_OPERATION_H 17 #define OHOS_MEDIA_PHOTO_SOURCE_PATH_OPERATION_H 18 19 #include <string> 20 #include <vector> 21 #include <sstream> 22 23 #include "medialibrary_rdbstore.h" 24 25 namespace OHOS::Media { 26 class PhotoSourcePathOperation { 27 private: 28 class PhotoAssetInfo { 29 public: 30 int64_t albumId; 31 std::string albumName; 32 std::string lPath; 33 int64_t fileId; 34 std::string displayName; 35 int32_t hidden; 36 int64_t dateTrashed; 37 std::string sourcePath; 38 39 public: ToString()40 std::string ToString() const 41 { 42 std::stringstream ss; 43 ss << "PhotoAssetInfo[" 44 << ", albumId: " << this->albumId << ", albumName: " << this->albumName << ", lPath: " << this->lPath 45 << ", fileId: " << this->fileId << "displayName: " << this->displayName << ", hidden: " << this->hidden 46 << ", dateTrashed: " << this->dateTrashed << ", sourcePath: " << this->sourcePath << "]"; 47 return ss.str(); 48 } 49 }; 50 51 public: 52 void ResetPhotoSourcePath(std::shared_ptr<MediaLibraryRdbStore> mediaRdbStorePtr); 53 54 private: 55 std::vector<PhotoAssetInfo> GetPhotoOfMissingSourcePath( 56 std::shared_ptr<MediaLibraryRdbStore> mediaRdbStorePtr, const int32_t offset = 0, const int32_t limit = 200); 57 58 private: 59 const std::string SQL_PHOTO_SOURCE_PATH_MISSING_QUERY = "\ 60 SELECT \ 61 album_id, \ 62 album_name, \ 63 lpath, \ 64 file_id, \ 65 display_name, \ 66 hidden, \ 67 date_trashed, \ 68 source_path \ 69 FROM Photos \ 70 LEFT JOIN PhotoAlbum \ 71 ON Photos.owner_album_id = PhotoAlbum.album_id \ 72 WHERE PhotoAlbum.album_id IS NOT NULL AND \ 73 COALESCE(PhotoAlbum.lpath, '') <> '' AND \ 74 COALESCE(source_path, '') = '' AND \ 75 (hidden <> 0 || date_trashed <> 0) \ 76 LIMIT ?, ? ;"; 77 const std::string SOURCE_PATH_PREFIX = "/storage/emulated/0"; 78 const std::string SQL_PHOTO_SOURCE_PATH_FIX_UPDATE = "\ 79 UPDATE Photos \ 80 SET source_path = ? \ 81 WHERE COALESCE(source_path, '') = '' AND \ 82 (hidden <> 0 || date_trashed <> 0) AND \ 83 file_id = ? ;"; 84 }; 85 } // namespace OHOS::Media 86 #endif // OHOS_MEDIA_PHOTO_SOURCE_PATH_OPERATION_H