Commit 6c599376 authored by Alan McNatty's avatar Alan McNatty
Browse files

Fixed a sync bug - the notifications needed a count not trim to see if any...

Fixed a sync bug - the notifications needed a count not trim to see if any existed. That bug must have been around for a bit.

Also added a couple ot Util methods to perform account stuff getAccount and deleteAccount. We now also delete the old account if any authentication details have changed. Also the sync process has some new logging and the order (if not noticed from last commit) has reverted back to sync then upload - I found a bug with the token changing midway through a bunch of uploads (may need to check how frequently the pref value is checked if a sync happens mid upload).
parent d0a21526
...@@ -77,12 +77,13 @@ try { ...@@ -77,12 +77,13 @@ try {
} }
catch (ParameterException $e) { } catch (ParameterException $e) { }
$activity_arr = get_records_sql_array('select n.id, n.subject, n.message $activity_arr = get_records_sql_array("select n.id, n.subject, n.message
from {notification_internal_activity} n, {activity_type} a from {notification_internal_activity} n, {activity_type} a
where n.type=a.id and n.read=0 and ' where n.type=a.id and n.read=0
. db_format_tsfield('n.ctime', '') . ' >= ? and n.usr= ? ', and FLOOR(EXTRACT(EPOCH FROM ctime AT TIME ZONE 'UTC')) >= ?
and n.usr= ? ",
array($lastsync + 0, $USER->id)); array($lastsync + 0, $USER->id));
if ( trim($activity_arr) != '' ) if ( count($activity_arr) > 0 )
$json['activity'] = $activity_arr; $json['activity'] = $activity_arr;
// OK - let's add tags // OK - let's add tags
......
...@@ -279,6 +279,7 @@ public class Utils { ...@@ -279,6 +279,7 @@ public class Utils {
// Save last sync time // Save last sync time
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
// We save current time in seconds since 1970 in UTC!!
mPrefs.edit() mPrefs.edit()
.putLong("lastsync", System.currentTimeMillis()/1000) .putLong("lastsync", System.currentTimeMillis()/1000)
.commit() .commit()
...@@ -344,6 +345,9 @@ public class Utils { ...@@ -344,6 +345,9 @@ public class Utils {
} }
public static void setPeriodicSync(Account account, Context context) { public static void setPeriodicSync(Account account, Context context) {
if ( account == null )
return;
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
Long periodic_sync = Long.valueOf(mPrefs.getString(context.getResources().getString(R.string.pref_sync_periodic_key), "0")); Long periodic_sync = Long.valueOf(mPrefs.getString(context.getResources().getString(R.string.pref_sync_periodic_key), "0"));
...@@ -384,6 +388,16 @@ public class Utils { ...@@ -384,6 +388,16 @@ public class Utils {
return account; return account;
} }
public static void deleteAccount(Context context) {
AccountManager mAccountManager = AccountManager.get(context);
Account[] mAccounts = mAccountManager.getAccountsByType(GlobalResources.ACCOUNT_TYPE);
for ( int i = 0; i < mAccounts.length; i++ ) {
mAccountManager.removeAccount(mAccounts[i], null, null);
}
}
public static String[][] getJournals(String nullitem, Context context) { public static String[][] getJournals(String nullitem, Context context) {
return getValues("blog", nullitem, context); return getValues("blog", nullitem, context);
} }
...@@ -466,4 +480,5 @@ public class Utils { ...@@ -466,4 +480,5 @@ public class Utils {
return bm; return bm;
} }
} }
...@@ -69,7 +69,7 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{ ...@@ -69,7 +69,7 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
""); "");
Long lastsync = mPrefs.getLong("lastsync", 0); Long lastsync = mPrefs.getLong("lastsync", 0);
if ( VERBOSE ) Log.v(TAG, "Synchronizing Mahara account '" + username + "', " + "'" + token + "' and lastsync '" + lastsync + "'"); if ( VERBOSE ) Log.v(TAG, "Synchronizing Mahara account '" + username + "', " + "'" + token + "' for details as of lastsync '" + lastsync + "'");
// Get latest details from sync // Get latest details from sync
JSONObject result = RestClient.AuthSync(authSyncURI, token, username, lastsync, mContext); JSONObject result = RestClient.AuthSync(authSyncURI, token, username, lastsync, mContext);
......
...@@ -157,6 +157,9 @@ public class EditPreferences extends PreferenceActivity implements OnSharedPrefe ...@@ -157,6 +157,9 @@ public class EditPreferences extends PreferenceActivity implements OnSharedPrefe
if(VERBOSE) Log.v(TAG, "On destroy received ... "); if(VERBOSE) Log.v(TAG, "On destroy received ... ");
// If the username and token have // If the username and token have
if ( authDetailsChanged ) { if ( authDetailsChanged ) {
if(VERBOSE) Log.v(TAG, "Deleting old account ... ");
Utils.deleteAccount(this);
// force login. // force login.
if(VERBOSE) Log.v(TAG, "Starting auth activity ... "); if(VERBOSE) Log.v(TAG, "Starting auth activity ... ");
startActivity(new Intent(this, AuthenticatorActivity.class)); startActivity(new Intent(this, AuthenticatorActivity.class));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment