@@ -46,8 +46,10 @@ import android.os.CancellationSignal
46
46
import android.os.ParcelFileDescriptor
47
47
import android.provider.BaseColumns
48
48
import android.text.TextUtils
49
+ import android.util.Log
49
50
import androidx.sqlite.db.SupportSQLiteDatabase
50
51
import androidx.sqlite.db.SupportSQLiteQueryBuilder
52
+ import androidx.work.WorkManager
51
53
import com.owncloud.android.MainApp
52
54
import com.owncloud.android.R
53
55
import com.owncloud.android.data.Executors
@@ -56,14 +58,12 @@ import com.owncloud.android.data.ProviderMeta
56
58
import com.owncloud.android.data.capabilities.datasources.implementation.OCLocalCapabilitiesDataSource
57
59
import com.owncloud.android.data.capabilities.datasources.implementation.OCLocalCapabilitiesDataSource.Companion.toModel
58
60
import com.owncloud.android.data.capabilities.db.OCCapabilityEntity
59
- import com.owncloud.android.data.files.db.FileDao
60
61
import com.owncloud.android.data.files.db.OCFileEntity
61
62
import com.owncloud.android.data.folderbackup.datasources.FolderBackupLocalDataSource
62
63
import com.owncloud.android.data.migrations.CameraUploadsMigrationToRoom
63
64
import com.owncloud.android.data.preferences.datasources.SharedPreferencesProvider
64
65
import com.owncloud.android.data.sharing.shares.db.OCShareEntity
65
66
import com.owncloud.android.data.transfers.db.OCTransferEntity
66
- import com.owncloud.android.data.transfers.db.TransferDao
67
67
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
68
68
import com.owncloud.android.domain.camerauploads.model.UploadBehavior
69
69
import com.owncloud.android.domain.files.model.LIST_MIME_DIR
@@ -284,6 +284,8 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
284
284
285
285
override fun onCreate (): Boolean {
286
286
dbHelper = DataBaseHelper (context)
287
+ // This sentence is for opening the database, which is necessary to perform the migration correctly to DB version 38
288
+ dbHelper.writableDatabase
287
289
288
290
val authority = context?.resources?.getString(R .string.authority)
289
291
uriMatcher = UriMatcher (UriMatcher .NO_MATCH )
@@ -541,7 +543,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
541
543
}
542
544
543
545
override fun onUpgrade (db : SQLiteDatabase , oldVersion : Int , newVersion : Int ) {
544
- Timber .i(" SQL : Entering in onUpgrade" )
546
+ Log .i(" SQLiteOpenHelper " , " SQL : Entering in onUpgrade" )
545
547
var upgraded = false
546
548
547
549
if (oldVersion == 1 && newVersion >= 2 ) {
@@ -1050,8 +1052,8 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
1050
1052
}
1051
1053
}
1052
1054
1053
- if (oldVersion < 37 && newVersion >= 37 ) {
1054
- Timber .i(" SQL : Entering in #37 to migrate files and uploads from SQLite to Room" )
1055
+ if (oldVersion < 38 && newVersion >= 38 ) {
1056
+ Timber .i(" SQL : Entering in #38 to migrate files and uploads from SQLite to Room" )
1055
1057
db.beginTransaction()
1056
1058
1057
1059
try {
@@ -1073,7 +1075,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
1073
1075
} while (cursorFiles.moveToNext())
1074
1076
1075
1077
// Insert file list to the new files table in new database
1076
- val ocFileDao: FileDao by inject ()
1078
+ val ocFileDao = OwncloudDatabase .getDatabase(context !! ).fileDao ()
1077
1079
executors.diskIO().execute {
1078
1080
for (file in files) {
1079
1081
ocFileDao.mergeRemoteAndLocalFile(file)
@@ -1103,7 +1105,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
1103
1105
} while (cursorUploads.moveToNext())
1104
1106
1105
1107
// Insert uploads list to the new transfers table in new database
1106
- val ocTransferDao: TransferDao by inject ()
1108
+ val ocTransferDao = OwncloudDatabase .getDatabase(context !! ).transferDao ()
1107
1109
executors.diskIO().execute {
1108
1110
for (upload in uploads) {
1109
1111
ocTransferDao.insert(upload)
@@ -1112,7 +1114,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
1112
1114
upload.createdBy != UploadEnqueuedBy .ENQUEUED_AS_CAMERA_UPLOAD_VIDEO .ordinal
1113
1115
) {
1114
1116
val localFile = File (upload.localPath)
1115
- val uploadFileFromSystemUseCase: UploadFileFromSystemUseCase by inject( )
1117
+ val uploadFileFromSystemUseCase = UploadFileFromSystemUseCase ( WorkManager .getInstance(context !! ) )
1116
1118
uploadFileFromSystemUseCase.execute(
1117
1119
UploadFileFromSystemUseCase .Params (
1118
1120
accountName = upload.accountName,
@@ -1134,6 +1136,15 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
1134
1136
// Drop old capabilities table from old database
1135
1137
db.execSQL(" DROP TABLE IF EXISTS " + ProviderTableMeta .CAPABILITIES_TABLE_NAME + " ;" )
1136
1138
1139
+ // Drop old camera uploads sync table from old database
1140
+ db.execSQL(" DROP TABLE IF EXISTS " + ProviderTableMeta .CAMERA_UPLOADS_SYNC_TABLE_NAME + " ;" )
1141
+
1142
+ // Drop old user avatars table from old database
1143
+ db.execSQL(" DROP TABLE IF EXISTS " + ProviderTableMeta .USER_AVATARS__TABLE_NAME + " ;" )
1144
+
1145
+ // Drop old user quotas table from old database
1146
+ db.execSQL(" DROP TABLE IF EXISTS " + ProviderTableMeta .USER_QUOTAS_TABLE_NAME + " ;" )
1147
+
1137
1148
db.setTransactionSuccessful()
1138
1149
upgraded = true
1139
1150
} finally {
0 commit comments