Merge pull request #740 from owncloud/revert-669-master
[pub/Android/ownCloud.git] / src / com / owncloud / android / providers / FileContentProvider.java
index 31143b0..a94454c 100644 (file)
@@ -22,12 +22,11 @@ import java.util.ArrayList;
 import java.util.HashMap;
 
 import com.owncloud.android.R;
-import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.db.ProviderMeta;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
-import com.owncloud.android.utils.Log_OC;
-
-
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.lib.resources.shares.ShareType;
 
 import android.content.ContentProvider;
 import android.content.ContentProviderOperation;
@@ -90,13 +89,23 @@ public class FileContentProvider extends ContentProvider {
         mFileProjectionMap.put(ProviderTableMeta.FILE_ETAG, 
                 ProviderTableMeta.FILE_ETAG);
         mFileProjectionMap.put(ProviderTableMeta.FILE_SHARE_BY_LINK,
+                ProviderTableMeta.FILE_SHARE_BY_LINK);
+        mFileProjectionMap.put(ProviderTableMeta.FILE_PUBLIC_LINK,
                 ProviderTableMeta.FILE_PUBLIC_LINK);
+        mFileProjectionMap.put(ProviderTableMeta.FILE_PERMISSIONS,
+                ProviderTableMeta.FILE_PERMISSIONS);
+        mFileProjectionMap.put(ProviderTableMeta.FILE_REMOTE_ID,
+                ProviderTableMeta.FILE_REMOTE_ID);
+        mFileProjectionMap.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL,
+                ProviderTableMeta.FILE_UPDATE_THUMBNAIL);
     }
 
     private static final int SINGLE_FILE = 1;
     private static final int DIRECTORY = 2;
     private static final int ROOT_DIRECTORY = 3;
     private static final int SHARES = 4;
+
+    private static final String TAG = FileContentProvider.class.getSimpleName();
     
     // Projection for ocshares table
     private static HashMap<String, String> mOCSharesProjectionMap;
@@ -129,6 +138,8 @@ public class FileContentProvider extends ContentProvider {
                 ProviderTableMeta.OCSHARES_USER_ID);
         mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED,
                 ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED);
+        mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER,
+                ProviderTableMeta.OCSHARES_ACCOUNT_OWNER);
     }
     
     private UriMatcher mUriMatcher;
@@ -149,18 +160,18 @@ public class FileContentProvider extends ContentProvider {
         return count;
     }
     
-    // TODO: switch(uri)
     private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) {
         int count = 0;
         switch (mUriMatcher.match(uri)) {
         case SINGLE_FILE:
-            /*Cursor c = query(db, uri, null, where, whereArgs, null);
-            String remotePath = "(unexisting)";
+            Cursor c = query(db, uri, null, where, whereArgs, null);
+            String remoteId = "";
             if (c != null && c.moveToFirst()) {
-                remotePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH));
+                remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
+                //ThumbnailsCacheManager.removeFileFromCache(remoteId);
             }
-            Log_OC.d(TAG, "Removing FILE " + remotePath);
-            */
+            Log_OC.d(TAG, "Removing FILE " + remoteId);
+
             count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
                     ProviderTableMeta._ID
                             + "="
@@ -186,16 +197,28 @@ public class FileContentProvider extends ContentProvider {
             Cursor children = query(uri, null, null, null, null);
             if (children != null && children.moveToFirst())  {
                 long childId;
-                boolean isDir; 
+                boolean isDir;
                 //String remotePath; 
                 while (!children.isAfterLast()) {
                     childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
-                    isDir = "DIR".equals(children.getString(children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)));
+                    isDir = "DIR".equals(children.getString(
+                            children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
+                    ));
                     //remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH));
                     if (isDir) {
-                        count += delete(db, ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId), null, null);
+                        count += delete(
+                            db, 
+                            ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId), 
+                            null, 
+                            null
+                        );
                     } else {
-                        count += delete(db, ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId), null, null);
+                        count += delete(
+                            db, 
+                            ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
+                            null, 
+                            null
+                        );
                     }
                     children.moveToNext();
                 }
@@ -220,15 +243,16 @@ public class FileContentProvider extends ContentProvider {
             //Log_OC.d(TAG, "Removing ROOT!");
             count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs);
             break;
+        case SHARES:
+            count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs);
+            break;
         default:
             //Log_OC.e(TAG, "Unknown uri " + uri);
             throw new IllegalArgumentException("Unknown uri: " + uri.toString());
         }
         return count;
     }
-    
 
-    // TODO: switch(uri)
     @Override
     public String getType(Uri uri) {
         switch (mUriMatcher.match(uri)) {
@@ -244,7 +268,6 @@ public class FileContentProvider extends ContentProvider {
 
     @Override
     public Uri insert(Uri uri, ContentValues values) {
-        //Log_OC.d(TAG, "Inserting " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
         Uri newUri = null;
         SQLiteDatabase db = mDbHelper.getWritableDatabase();
         db.beginTransaction();
@@ -258,39 +281,105 @@ public class FileContentProvider extends ContentProvider {
         return newUri;
     }
     
-    // TODO: switch(uri)
     private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) {
-        if (mUriMatcher.match(uri) != SINGLE_FILE &&
-                mUriMatcher.match(uri) != ROOT_DIRECTORY) {
-            //Log_OC.e(TAG, "Inserting invalid URI: " + uri);
-            throw new IllegalArgumentException("Unknown uri id: " + uri);
-        }
+        switch (mUriMatcher.match(uri)){
+        case ROOT_DIRECTORY:
+        case SINGLE_FILE:
+            String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
+            String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
+            String[] projection = new String[] {
+                    ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, 
+                    ProviderTableMeta.FILE_ACCOUNT_OWNER 
+            };
+            String where = ProviderTableMeta.FILE_PATH + "=? AND " + 
+                    ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
+            String[] whereArgs = new String[] {remotePath, accountName};
+            Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
+            // ugly patch; serious refactorization is needed to reduce work in 
+            // FileDataStorageManager and bring it to FileContentProvider
+            if (doubleCheck == null || !doubleCheck.moveToFirst()) {     
+                long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
+                if (rowId > 0) {
+                    Uri insertedFileUri = 
+                            ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
+                    return insertedFileUri;
+                } else {
+                    throw new SQLException("ERROR " + uri);
+                }
+            } else {
+                // file is already inserted; race condition, let's avoid a duplicated entry
+                Uri insertedFileUri = ContentUris.withAppendedId(
+                        ProviderTableMeta.CONTENT_URI_FILE, 
+                        doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID))
+                );
+                doubleCheck.close();
 
-        String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
-        String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
-        String[] projection = new String[] {ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, ProviderTableMeta.FILE_ACCOUNT_OWNER };
-        String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
-        String[] whereArgs = new String[] {remotePath, accountName};
-        Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
-        if (doubleCheck == null || !doubleCheck.moveToFirst()) {    // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider 
-            long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
-            if (rowId > 0) {
-                Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
-                //Log_OC.d(TAG, "Inserted " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
                 return insertedFileUri;
+            }
+            
+        case SHARES:
+            String path = values.getAsString(ProviderTableMeta.OCSHARES_PATH);
+            String accountNameShare= values.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER);
+            String[] projectionShare = new String[] {
+                    ProviderTableMeta._ID, ProviderTableMeta.OCSHARES_PATH, 
+                    ProviderTableMeta.OCSHARES_ACCOUNT_OWNER 
+            };
+            String whereShare = ProviderTableMeta.OCSHARES_PATH + "=? AND " + 
+                    ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
+            String[] whereArgsShare = new String[] {path, accountNameShare};
+            Uri insertedShareUri = null;
+            Cursor doubleCheckShare = 
+                    query(db, uri, projectionShare, whereShare, whereArgsShare, null);
+            // ugly patch; serious refactorization is needed to reduce work in 
+            // FileDataStorageManager and bring it to FileContentProvider
+            if (doubleCheckShare == null || !doubleCheckShare.moveToFirst()) {     
+                long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
+                if (rowId >0) {
+                    insertedShareUri = 
+                            ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId);
+                } else {
+                    throw new SQLException("ERROR " + uri);
+
+                }
             } else {
-                //Log_OC.d(TAG, "Error while inserting " + values.getAsString(ProviderTableMeta.FILE_PATH)  + " at provider " + this);
-                throw new SQLException("ERROR " + uri);
+                // file is already inserted; race condition, let's avoid a duplicated entry
+                insertedShareUri = ContentUris.withAppendedId(
+                        ProviderTableMeta.CONTENT_URI_SHARE, 
+                        doubleCheckShare.getLong(
+                                doubleCheckShare.getColumnIndex(ProviderTableMeta._ID)
+                        )
+                );
+                doubleCheckShare.close();
             }
-        } else {
-            // file is already inserted; race condition, let's avoid a duplicated entry
-            Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID)));
-            doubleCheck.close();
-            return insertedFileUri;
+            updateFilesTableAccordingToShareInsertion(db, uri, values);
+            return insertedShareUri;
+            
+
+        default:
+            throw new IllegalArgumentException("Unknown uri id: " + uri);
         }
+        
     }
-
     
+    private void updateFilesTableAccordingToShareInsertion(
+            SQLiteDatabase db, Uri uri, ContentValues shareValues
+            ) {
+        ContentValues fileValues = new ContentValues();
+        fileValues.put(
+                ProviderTableMeta.FILE_SHARE_BY_LINK, 
+                ShareType.PUBLIC_LINK.getValue() == 
+                    shareValues.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE)? 1 : 0
+        );
+        String whereShare = ProviderTableMeta.FILE_PATH + "=? AND " + 
+                ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
+        String[] whereArgsShare = new String[] {
+                shareValues.getAsString(ProviderTableMeta.OCSHARES_PATH), 
+                shareValues.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)
+        };
+        db.update(ProviderTableMeta.FILE_TABLE_NAME, fileValues, whereShare, whereArgsShare);
+    }
+    
+
     @Override
     public boolean onCreate() {
         mDbHelper = new DataBaseHelper(getContext());
@@ -310,7 +399,14 @@ public class FileContentProvider extends ContentProvider {
 
     
     @Override
-    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+    public Cursor query(
+            Uri uri, 
+            String[] projection, 
+            String selection, 
+            String[] selectionArgs, 
+            String sortOrder
+        ) {
+        
         Cursor result = null;
         SQLiteDatabase db = mDbHelper.getReadableDatabase();
         db.beginTransaction();
@@ -323,7 +419,15 @@ public class FileContentProvider extends ContentProvider {
         return result;
     }
     
-    private Cursor query(SQLiteDatabase db, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+    private Cursor query(
+            SQLiteDatabase db, 
+            Uri uri, 
+            String[] projection, 
+            String selection, 
+            String[] selectionArgs, 
+            String sortOrder
+        ) {
+        
         SQLiteQueryBuilder sqlQuery = new SQLiteQueryBuilder();
 
         sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME);
@@ -343,7 +447,13 @@ public class FileContentProvider extends ContentProvider {
                         + uri.getPathSegments().get(1));
             }
             break;
-        case SHARES: //TODO
+        case SHARES: 
+            sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME);
+            sqlQuery.setProjectionMap(mOCSharesProjectionMap);
+            if (uri.getPathSegments().size() > 1) {
+                sqlQuery.appendWhere(ProviderTableMeta._ID + "="
+                        + uri.getPathSegments().get(1));
+            }
             break;
         default:
             throw new IllegalArgumentException("Unknown uri id: " + uri);
@@ -351,7 +461,12 @@ public class FileContentProvider extends ContentProvider {
 
         String order;
         if (TextUtils.isEmpty(sortOrder)) {
-            order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
+            if (mUriMatcher.match(uri) == SHARES) {
+                order = ProviderTableMeta.OCSHARES_DEFAULT_SORT_ORDER;
+            } else {
+
+                order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
+            }
         } else {
             order = sortOrder;
         }
@@ -363,11 +478,9 @@ public class FileContentProvider extends ContentProvider {
         return c;
     }
 
-    // TODO: switch(uri)
     @Override
     public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
         
-        //Log_OC.d(TAG, "Updating " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
         int count = 0;
         SQLiteDatabase db = mDbHelper.getWritableDatabase();
         db.beginTransaction();
@@ -382,17 +495,29 @@ public class FileContentProvider extends ContentProvider {
     }
     
     
-    // TODO: switch(uri)
-    private int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+
+    private int update(
+            SQLiteDatabase db, 
+            Uri uri, 
+            ContentValues values, 
+            String selection, 
+            String[] selectionArgs
+        ) {
         switch (mUriMatcher.match(uri)) {
             case DIRECTORY:
-                return updateFolderSize(db, selectionArgs[0]);
+                return  0; //updateFolderSize(db, selectionArgs[0]);
+            case SHARES:
+                return db.update(
+                        ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs
+                );
             default:
-                return db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs);
+                return db.update(
+                        ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs
+                );
         }
     }    
 
-    
+ /*   
     private int updateFolderSize(SQLiteDatabase db, String folderId) {
         int count = 0;
         String [] whereArgs = new String[] { folderId };
@@ -443,11 +568,13 @@ public class FileContentProvider extends ContentProvider {
         }
         return count;
     }
-
+*/
     
     @Override
-    public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
-        Log_OC.d("FileContentProvider", "applying batch in provider " + this + " (temporary: " + isTemporary() + ")" );
+    public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations) 
+            throws OperationApplicationException {
+        Log_OC.d("FileContentProvider", "applying batch in provider " + this + 
+                " (temporary: " + isTemporary() + ")" );
         ContentProviderResult[] results = new ContentProviderResult[operations.size()];
         int i=0;
         
@@ -495,8 +622,29 @@ public class FileContentProvider extends ContentProvider {
                     + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, "
                     + ProviderTableMeta.FILE_ETAG + " TEXT, " 
                     + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER, "
-                    + ProviderTableMeta.FILE_PUBLIC_LINK  + " TEXT );"
+                    + ProviderTableMeta.FILE_PUBLIC_LINK  + " TEXT, "
+                    + ProviderTableMeta.FILE_PERMISSIONS  + " TEXT null,"
+                    + ProviderTableMeta.FILE_REMOTE_ID  + " TEXT null,"
+                    + ProviderTableMeta.FILE_UPDATE_THUMBNAIL  + " INTEGER);" //boolean
                     );
+            
+            // Create table ocshares
+            db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
+                    + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
+                    + ProviderTableMeta.OCSHARES_FILE_SOURCE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_ITEM_SOURCE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_SHARE_TYPE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_SHARE_WITH + " TEXT, "
+                    + ProviderTableMeta.OCSHARES_PATH + " TEXT, "
+                    + ProviderTableMeta.OCSHARES_PERMISSIONS+ " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_SHARED_DATE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_TOKEN + " TEXT, "
+                    + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, "
+                    + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, "  // boolean
+                    + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," 
+                    + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" );
         }
 
         @Override
@@ -515,12 +663,13 @@ public class FileContentProvider extends ContentProvider {
                 db.beginTransaction();
                 try {
                     db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
-                               " ADD COLUMN " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA  + " INTEGER " +
-                               " DEFAULT 0");
+                               " ADD COLUMN " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA  + 
+                               " INTEGER " + " DEFAULT 0");
                     
                     // assume there are not local changes pending to upload
                     db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME + 
-                            " SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = " + System.currentTimeMillis() + 
+                            " SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = " 
+                            + System.currentTimeMillis() + 
                             " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
                  
                     upgraded = true;
@@ -534,11 +683,12 @@ public class FileContentProvider extends ContentProvider {
                 db.beginTransaction();
                 try {
                     db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
-                           " ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA  + " INTEGER " +
-                           " DEFAULT 0");
+                           " ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA +
+                           " INTEGER " + " DEFAULT 0");
                 
                     db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME + 
-                           " SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " + ProviderTableMeta.FILE_MODIFIED + 
+                           " SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " +
+                            ProviderTableMeta.FILE_MODIFIED +
                            " WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
                 
                     upgraded = true;
@@ -548,7 +698,8 @@ public class FileContentProvider extends ContentProvider {
                 }
             }
             if (!upgraded)
-                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
+                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + 
+                        ", newVersion == " + newVersion);
         
             if (oldVersion < 5 && newVersion >= 5) {
                 Log_OC.i("SQL", "Entering in the #4 ADD in onUpgrade");
@@ -565,8 +716,9 @@ public class FileContentProvider extends ContentProvider {
                 }
             }
             if (!upgraded)
-                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
-            
+                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + 
+                        ", newVersion == " + newVersion);
+
             if (oldVersion < 6 && newVersion >= 6) {
                 Log_OC.i("SQL", "Entering in the #5 ADD in onUpgrade");
                 db.beginTransaction();
@@ -578,7 +730,7 @@ public class FileContentProvider extends ContentProvider {
                     db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
                             " ADD COLUMN " + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT " +
                             " DEFAULT NULL");
-                    
+
                     // Create table ocshares
                     db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
                             + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
@@ -594,8 +746,30 @@ public class FileContentProvider extends ContentProvider {
                             + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, "
                             + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, "  // boolean
                             + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, "
-                            + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER );"
-                            );
+                            + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," 
+                            + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" );
+
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
+            }
+            if (!upgraded)
+                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + 
+                        ", newVersion == " + newVersion);
+
+            if (oldVersion < 7 && newVersion >= 7) {
+                Log_OC.i("SQL", "Entering in the #7 ADD in onUpgrade");
+                db.beginTransaction();
+                try {
+                    db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
+                            " ADD COLUMN " + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
+                            " DEFAULT NULL");
+
+                    db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
+                            " ADD COLUMN " + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " +
+                            " DEFAULT NULL");
                     
                     upgraded = true;
                     db.setTransactionSuccessful();
@@ -604,7 +778,26 @@ public class FileContentProvider extends ContentProvider {
                 }
             }
             if (!upgraded)
-                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
+                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + 
+                        ", newVersion == " + newVersion);
+
+            if (oldVersion < 8 && newVersion >= 8) {
+                Log_OC.i("SQL", "Entering in the #8 ADD in onUpgrade");
+                db.beginTransaction();
+                try {
+                    db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
+                            " ADD COLUMN " + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER " +
+                            " DEFAULT 0");
+
+                    upgraded = true;
+                    db.setTransactionSuccessful();
+                } finally {
+                    db.endTransaction();
+                }
+            }
+            if (!upgraded)
+                Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + 
+                        ", newVersion == " + newVersion);
         }
     }