Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c20e147b authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

update DB for upgrade on package update

parent 376fd299
Loading
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -6,10 +6,10 @@


#### Actu:
This branch has merged OS_integration branch the 04/09/2018.
Licence has been added check "LICENCE" file for details.
Fix account's deletion
Fix disabled sync in account's settings: I update DB, so it might cause issue after update. One solution in this case is to remove your account and add it again.

Check the wiki for more information
Check the [wiki](https://gitlab.e.foundation/e/apps/eDrive/wikis/home) for more information

#### TODO:
This is the current pending goal List:
@@ -17,6 +17,6 @@ This is the current pending goal List:
+ Handle lack of space localy
+ Issue # 0 : apps crash if request are too long and fails because of that
+ Add Unit test
+ Restat after few minutes the initializationService while it fails or the user doesn't disable sync.
+ ScheduleInitialization while it hasn't run completely or user hasn't disable both sync type.

+18 −8
Original line number Diff line number Diff line
@@ -29,13 +29,13 @@ import io.eelo.drive.models.SyncedFileState;

public final class DbHelper extends SQLiteOpenHelper {
    final private static String TAG = DbHelper.class.getSimpleName(); //Tag for log
    private static final int DATABASE_VERSION = 19;
    private static final int DATABASE_VERSION = 19; //20/09/2018
    public static final String DATABASE_NAME = "eelo_drive.db";

    /**
     * Constructor of the helper
     */
    DbHelper(Context context){
    public DbHelper(Context context){
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

@@ -51,17 +51,28 @@ public final class DbHelper extends SQLiteOpenHelper {

    /**
     * Function to upgrade a DB.
     * Delete old Tables
     * @param db SQLiteDatabase object
     * @param oldVersion Version number of the db to delete
     * @param newVersion Version number of the db to create
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SyncedFolderContract.SQL_DELETE_TABLE_SYNCEDFOLDER);
        db.execSQL(SyncedFileStateContract.SQL_DELETE_TABLE_SYNCEDFILESTATE);
        this.onCreate(db);
        Log.i(TAG, "onUpgrade(db, "+oldVersion+", "+newVersion+")");
        if(oldVersion < 19){
            try {
                db.execSQL(SyncedFolderContract.UPDATE_TABLE_TO_VERSION_19);
                db.execSQL(SyncedFileStateContract.UPDATE_TABLE_TO_VERSION_19);

                db.execSQL(SyncedFileStateContract.UPDATE_MEDIA_DATA_TO_VERSION_19);
                db.execSQL(SyncedFileStateContract.UPDATE_SETTINGS_DATA_TO_VERSION_19);
                db.execSQL(SyncedFolderContract.UPDATE_MEDIA_DATA_TO_VERSION_19);
                db.execSQL(SyncedFolderContract.UPDATE_SETTINGS_DATA_TO_VERSION_19);
            }catch(Exception e){
                Log.e(TAG, toString());
            }
        }
    }


    private static SyncedFileStateDAO openSyncedFileStateDAO(Context context, boolean writeMod){
        SyncedFileStateDAO dao = new SyncedFileStateDAO(context);
@@ -198,8 +209,7 @@ public final class DbHelper extends SQLiteOpenHelper {
        }
        else {
            mSyncedFolder = dao.getSyncedFolderList(SyncedFolderContract.ENABLED+" = 1 AND "
                            +SyncedFolderContract.IS_MEDIA_TYPE+" = ?", new String[] {(isMediaType)? "1":"0"}
                    );
                +SyncedFolderContract.IS_MEDIA_TYPE+" = ?", new String[] {(isMediaType)? "1":"0"} );
            dao.close();
            return mSyncedFolder;
        }
+16 −0
Original line number Diff line number Diff line
@@ -44,4 +44,20 @@ class SyncedFileStateContract implements BaseColumns{

    static final String SQL_DELETE_TABLE_SYNCEDFILESTATE = " DROP TABLE IF EXISTS "
           + TABLE_NAME;

    static final String UPDATE_TABLE_TO_VERSION_19 = "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+IS_MEDIA_TYPE+" BOOLEAN;";

    static final String UPDATE_MEDIA_DATA_TO_VERSION_19 = "UPDATE "+TABLE_NAME+
            " SET "+IS_MEDIA_TYPE+" = 1 WHERE "+
            REMOTE_PATH+" LIKE \"/Photos/%\" OR "+
            REMOTE_PATH+" LIKE \"/Movies/%\" OR "+
            REMOTE_PATH+" LIKE \"/Pictures/%\" OR "+
            REMOTE_PATH+" LIKE \"/Music/%\" OR "+
            REMOTE_PATH+" LIKE \"/Ringtones/%\" OR "+
            REMOTE_PATH+" LIKE \"/Documents/%\" OR "+
            REMOTE_PATH+" LIKE \"/Podcasts/%\";";

    static final String UPDATE_SETTINGS_DATA_TO_VERSION_19 = "UPDATE "+TABLE_NAME+
            " SET "+IS_MEDIA_TYPE+" = 0 WHERE "+REMOTE_PATH+" LIKE \"/Devices/%\";";

}
+15 −0
Original line number Diff line number Diff line
@@ -44,4 +44,19 @@ final class SyncedFolderContract implements BaseColumns{

    static final String SQL_DELETE_TABLE_SYNCEDFOLDER = " DROP TABLE IF EXISTS "
            + TABLE_NAME;

    static final String UPDATE_TABLE_TO_VERSION_19 = "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+IS_MEDIA_TYPE+" BOOLEAN;";

    static final String UPDATE_MEDIA_DATA_TO_VERSION_19 = "UPDATE "+TABLE_NAME+
            " SET "+IS_MEDIA_TYPE+" = 1 WHERE "+
            REMOTE_PATH+" LIKE \"/Photos/%\" OR "+
            REMOTE_PATH+" LIKE \"/Movies/%\" OR "+
            REMOTE_PATH+" LIKE \"/Pictures/%\" OR "+
            REMOTE_PATH+" LIKE \"/Music/%\" OR "+
            REMOTE_PATH+" LIKE \"/Ringtones/%\" OR "+
            REMOTE_PATH+" LIKE \"/Documents/%\" OR "+
            REMOTE_PATH+" LIKE \"/Podcasts/%\";";

    static final String UPDATE_SETTINGS_DATA_TO_VERSION_19 = "UPDATE "+TABLE_NAME+
            " SET "+IS_MEDIA_TYPE+" = 0 WHERE "+REMOTE_PATH+" LIKE \"/Devices/%\";";
}
+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

import io.eelo.drive.database.DbHelper;
import io.eelo.drive.services.InitializerService;
import io.eelo.drive.utils.AppConstants;
import io.eelo.drive.utils.CommonUtils;
@@ -33,6 +34,10 @@ public class PackageEventReceiver extends BroadcastReceiver {
            pref.edit().putBoolean(AppConstants.INITIALIZERSERVICE_HAS_RUN, false).apply();
            context.startService(new Intent(context, InitializerService.class));

            DbHelper dbHelper = new DbHelper(context);
            dbHelper.getWritableDatabase().close(); //Force upgrade of db.


            /*if (!pref.getBoolean(AppConstants.INITIALIZERSERVICE_HAS_RUN, false)) {
                context.startService(new Intent(context, InitializerService.class));
            } else if(CommonUtils.getAccount( pref.getString(AccountManager.KEY_ACCOUNT_NAME,""),