mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +03:00
Add migration procedures
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
378c46f0ec
commit
582f29b041
3 changed files with 72 additions and 15 deletions
|
@ -26,7 +26,7 @@ import java.io.Serializable;
|
|||
/**
|
||||
* Synced folder entity containing all information per synced folder.
|
||||
*/
|
||||
public class SyncedFolder implements Serializable {
|
||||
public class SyncedFolder implements Serializable, Cloneable {
|
||||
public static final long UNPERSISTED_ID = Long.MIN_VALUE;
|
||||
private static final long serialVersionUID = -793476118299906429L;
|
||||
private long id = UNPERSISTED_ID;
|
||||
|
@ -94,6 +94,15 @@ public class SyncedFolder implements Serializable {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch( CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
/**
|
||||
* Nextcloud Android client application
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* Copyright (C) 2016 Andy Scherzinger
|
||||
* Copyright (C) 2016 Nextcloud.
|
||||
* Copyright (C) 2016 Andy Scherzinger
|
||||
* Copyright (C) 2016 Nextcloud.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.datamodel;
|
||||
|
||||
|
@ -270,6 +270,17 @@ public class SyncedFolderProvider extends Observable {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete any records of synchronized folders that are withing the given list of ids.
|
||||
*/
|
||||
public int deleteSyncedFoldersInList(ArrayList<Long> ids) {
|
||||
return mContentResolver.delete(
|
||||
ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
|
||||
ProviderMeta.ProviderTableMeta._ID + " IN (?)",
|
||||
new String[]{String.valueOf(ids)}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* update given synced folder.
|
||||
*
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.accounts.AccountManager;
|
|||
import android.content.ContentProvider;
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentProviderResult;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
|
@ -42,7 +43,11 @@ import android.text.TextUtils;
|
|||
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.MediaFolder;
|
||||
import com.owncloud.android.datamodel.MediaProvider;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.SyncedFolder;
|
||||
import com.owncloud.android.datamodel.SyncedFolderProvider;
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||
import com.owncloud.android.db.ProviderMeta;
|
||||
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
|
||||
|
@ -54,6 +59,7 @@ import com.owncloud.android.utils.MimeType;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
@ -982,11 +988,42 @@ public class FileContentProvider extends ContentProvider {
|
|||
Log_OC.i(SQL, "Entering in the #20 ADD in onUpgrade");
|
||||
db.beginTransaction();
|
||||
try {
|
||||
// add type column default being IMAGE(0)
|
||||
// add type column default being LEGACY (3)
|
||||
db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
|
||||
ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_TYPE +
|
||||
" INTEGER " + " DEFAULT 3");
|
||||
|
||||
ContentResolver contentResolver = getContext().getContentResolver();
|
||||
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
|
||||
|
||||
final List<MediaFolder> imageMediaFolders = MediaProvider.getImageFolders(contentResolver, 0);
|
||||
final List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 0);
|
||||
|
||||
ArrayList<Long> idsToDelete = new ArrayList<>();
|
||||
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
|
||||
idsToDelete.add(syncedFolder.getId());
|
||||
for (int i = 0; i < imageMediaFolders.size(); i++) {
|
||||
if (imageMediaFolders.get(i).absolutePath.equals(syncedFolder.getLocalPath())) {
|
||||
SyncedFolder imageSyncedFolder = (SyncedFolder) syncedFolder.clone();
|
||||
imageSyncedFolder.setType(MediaFolder.IMAGE);
|
||||
syncedFolderProvider.storeFolderSync(imageSyncedFolder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < videoMediaFolders.size(); j++) {
|
||||
if (videoMediaFolders.get(j).absolutePath.equals(syncedFolder.getLocalPath())) {
|
||||
SyncedFolder videoSyncedFolder = (SyncedFolder) syncedFolder.clone();
|
||||
videoSyncedFolder.setType(MediaFolder.VIDEO);
|
||||
syncedFolderProvider.storeFolderSync(videoSyncedFolder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
syncedFolderProvider.deleteSyncedFoldersInList(idsToDelete);
|
||||
|
||||
upgraded = true;
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
|
|
Loading…
Reference in a new issue