Also report all new, updated, and deleted metadatas from updateItemMetadatas in NextcloudFilesDatabaseManager

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-08 17:57:43 +01:00
parent a10b563eb7
commit e7e850094b
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -189,24 +189,28 @@ class NextcloudFilesDatabaseManager : NSObject {
return (returningNewMetadatas, returningUpdatedMetadatas) return (returningNewMetadatas, returningUpdatedMetadatas)
} }
func updateItemMetadatas(account: String, serverUrl: String, updatedMetadatas: [NextcloudItemMetadataTable]) { func updateItemMetadatas(account: String, serverUrl: String, updatedMetadatas: [NextcloudItemMetadataTable]) -> (newMetadatas: [NextcloudItemMetadataTable]?, updatedMetadatas: [NextcloudItemMetadataTable]?, deletedMetadatas: [NextcloudItemMetadataTable]?) {
let database = ncDatabase() let database = ncDatabase()
do { do {
try database.write { try database.write {
let existingMetadatas = ncDatabase().objects(NextcloudItemMetadataTable.self).filter("account == %@ AND serverUrl == %@ AND status == %@", account, serverUrl, NextcloudItemMetadataTable.Status.normal.rawValue) let existingMetadatas = ncDatabase().objects(NextcloudItemMetadataTable.self).filter("account == %@ AND serverUrl == %@ AND status == %@", account, serverUrl, NextcloudItemMetadataTable.Status.normal.rawValue)
processItemMetadatasToDelete(databaseToWriteTo: database, let deletedMetadatas = processItemMetadatasToDelete(databaseToWriteTo: database,
existingMetadatas: existingMetadatas, existingMetadatas: existingMetadatas,
updatedMetadatas: updatedMetadatas) updatedMetadatas: updatedMetadatas)
processItemMetadatasToUpdate(databaseToWriteTo: database, let metadatasFromUpdate = processItemMetadatasToUpdate(databaseToWriteTo: database,
existingMetadatas: existingMetadatas, existingMetadatas: existingMetadatas,
updatedMetadatas: updatedMetadatas) updatedMetadatas: updatedMetadatas)
return (metadatasFromUpdate.newMetadatas, metadatasFromUpdate.updatedMetadatas, deletedMetadatas)
} }
} catch let error { } catch let error {
NSLog("Could not update any metadatas, received error: %@", error.localizedDescription) NSLog("Could not update any metadatas, received error: %@", error.localizedDescription)
} }
return (nil, nil, nil)
} }
func setStatusForItemMetadata(_ metadata: NextcloudItemMetadataTable, status: NextcloudItemMetadataTable.Status) -> NextcloudItemMetadataTable? { func setStatusForItemMetadata(_ metadata: NextcloudItemMetadataTable, status: NextcloudItemMetadataTable.Status) -> NextcloudItemMetadataTable? {