Clean up DB upgrade

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-05-05 13:50:18 +02:00 committed by AndyScherzinger
parent 582f29b041
commit de962ad8b6
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
2 changed files with 9 additions and 4 deletions

View file

@ -30,7 +30,6 @@ public class MediaFolder {
public static final Integer CUSTOM = 0;
public static final Integer IMAGE = 1;
public static final Integer VIDEO = 2;
public static final Integer LEGACY = 3;
/** name of the folder. */
public String folderName;

View file

@ -988,11 +988,16 @@ public class FileContentProvider extends ContentProvider {
Log_OC.i(SQL, "Entering in the #20 ADD in onUpgrade");
db.beginTransaction();
try {
// add type column default being LEGACY (3)
// add type column default being CUSTOM (0)
db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_TYPE +
" INTEGER " + " DEFAULT 3");
" INTEGER " + " DEFAULT 0");
// create arbitrary data table
createArbitraryData(db);
// magic to split out existing synced folders in two when needed
// otherwise, we migrate them to their proper type (image or video)
ContentResolver contentResolver = getContext().getContentResolver();
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
@ -1001,7 +1006,8 @@ public class FileContentProvider extends ContentProvider {
final List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 0);
ArrayList<Long> idsToDelete = new ArrayList<>();
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
for (SyncedFolder syncedFolder : syncedFolders) {
idsToDelete.add(syncedFolder.getId());
for (int i = 0; i < imageMediaFolders.size(); i++) {
if (imageMediaFolders.get(i).absolutePath.equals(syncedFolder.getLocalPath())) {